Grammalecte  Check-in [ef040ce115]

Overview
Comment:[lo] spellchecker implementation: use personal dictionary + drop the idea of Hunspell as fallback (it doesn’t work)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: ef040ce115550c53bb75b74875aa72a4d996b000734660fce84d0bbe60cd4756
User & Date: olr on 2018-04-06 10:06:04
Other Links: manifest | tags
Context
2018-04-06
10:21
[fr] faux positifs: confusion <davantage/d’avantages> check-in: 82f4587db7 user: olr tags: trunk, fr
10:06
[lo] spellchecker implementation: use personal dictionary + drop the idea of Hunspell as fallback (it doesn’t work) check-in: ef040ce115 user: olr tags: trunk, lo
2018-04-05
21:22
[lo] graphspell wrapper update check-in: 06aaa44305 user: olr tags: trunk, lo
Changes

Modified gc_lang/fr/oxt/Graphspell.py from [c323cfe028] to [d947f3db6b].

1
2
3
4
5
6
7
8
9

10

11
12
13
14
15
16
17
# Graphspell
#
# Spellchecker based on a DAWG (Direct Acyclic Word Graph)


import uno
import unohelper
import traceback
import re



from grammalecte.graphspell import SpellChecker

from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale











>

>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Graphspell
#
# Spellchecker based on a DAWG (Direct Acyclic Word Graph)


import uno
import unohelper
import traceback
import re
import json

import helpers
from grammalecte.graphspell import SpellChecker

from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale


48
49
50
51
52
53
54











55
56
57
58
59
60
61
62
63
64
65
66
67
68
        try:
            self.ctx = ctx
            self.sServiceName = "com.sun.star.linguistic2.SpellChecker"
            self.sImplementationName = "net.grammalecte.graphspell"
            self.tSupportedServiceNames = (self.sServiceName, )
            self.xSvMgr = ctx.ServiceManager
            self.locales = tuple([ Locale(t[0], t[1], t[2])  for t in lLocale ])











            self.oGraphspell = SpellChecker("fr", "fr.bdic")
            #self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker")
            self.xHunspellLocale = Locale('fr', 'MC', '')
            #self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale')
            #self.xHunspellLocale.Language = 'fr'
            #self.xHunspellLocale.Country = 'FR'
            print("Graphspell: init done")
        except:
            print("Graphspell: init failed")
            traceback.print_exc()
    
    # XServiceName
    def getServiceName (self):
        return self.sImplementationName     #self.sServiceName







>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        try:
            self.ctx = ctx
            self.sServiceName = "com.sun.star.linguistic2.SpellChecker"
            self.sImplementationName = "net.grammalecte.graphspell"
            self.tSupportedServiceNames = (self.sServiceName, )
            self.xSvMgr = ctx.ServiceManager
            self.locales = tuple([ Locale(t[0], t[1], t[2])  for t in lLocale ])
            self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False)
            xChild = self.xSettingNode.getByName("o_fr")
            personal_dic = ""
            if (xChild.getPropertyValue("use_graphspell")):
                sPersonalDicJSON = xChild.getPropertyValue("personal_dic")
                if sPersonalDicJSON:
                    try:
                        personal_dic = json.loads(sPersonalDicJSON)
                    except:
                        print("Graphspell: wrong personal_dic")
                        traceback.print_exc()
            self.oGraphspell = SpellChecker("fr", "fr.bdic", "", "", personal_dic)
            # self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker")
            # self.xHunspellLocale = Locale('fr', 'MC', '')
            # self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale')
            # self.xHunspellLocale.Language = 'fr'
            # self.xHunspellLocale.Country = 'FR'
            # print("Graphspell: init done")
        except:
            print("Graphspell: init failed")
            traceback.print_exc()
    
    # XServiceName
    def getServiceName (self):
        return self.sImplementationName     #self.sServiceName
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    def isValid (self, aWord, rLocale, aProperties):
        try:
            aWord = zElidedWords.sub("", aWord.rstrip("."), count=1)
            return self.oGraphspell.isValidToken(aWord)
        except:
            traceback.print_exc()
        return False
        try:
            if self.xHunspell:
                return self.xHunspell.isValid(aWord, self.xHunspellLocale, aProperties)
        except:
            traceback.print_exc()
        return False

    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"
        self.listSpellChecker()
        lSugg = []
        for l in self.oGraphspell.suggest(aWord):
            lSugg.extend(l)
        return SpellAlternatives(aWord, tuple(lSugg))
        try:
            if self.xHunspell:
                return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties)
        except:
            traceback.print_exc()
        return None

    # XServiceDisplayName
    def getServiceDisplayName(self, aLocale):
        return "Graphspell (fr)"

    # Other
    def listSpellChecker (self):







|
|
|
|
|
|








|
|
|
|
|
|







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    def isValid (self, aWord, rLocale, aProperties):
        try:
            aWord = zElidedWords.sub("", aWord.rstrip("."), count=1)
            return self.oGraphspell.isValidToken(aWord)
        except:
            traceback.print_exc()
        return False
        # try:
        #     if self.xHunspell:
        #         return self.xHunspell.isValid(aWord, self.xHunspellLocale, aProperties)
        # except:
        #     traceback.print_exc()
        # return False

    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"
        self.listSpellChecker()
        lSugg = []
        for l in self.oGraphspell.suggest(aWord):
            lSugg.extend(l)
        return SpellAlternatives(aWord, tuple(lSugg))
        # try:
        #     if self.xHunspell:
        #         return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties)
        # except:
        #     traceback.print_exc()
        # return None

    # XServiceDisplayName
    def getServiceDisplayName(self, aLocale):
        return "Graphspell (fr)"

    # Other
    def listSpellChecker (self):