Grammalecte  Check-in [3f0d501d26]

Overview
Comment:[lo] Hunspell as a fallback spellchecker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: 3f0d501d268523807ad214074d8dfed476385bca471f698ae9e54716de8830cd
User & Date: olr on 2018-04-11 09:52:04
Other Links: manifest | tags
Context
2018-04-11
10:28
[lo] ui for choosing spellchecker suggestion engine check-in: b093fd512b user: olr tags: trunk, lo
09:52
[lo] Hunspell as a fallback spellchecker check-in: 3f0d501d26 user: olr tags: trunk, lo
06:43
[fr] faux positif: confusion <quel/qu’elle> check-in: f148dd52e5 user: olr tags: trunk, fr
Changes

Modified gc_core/py/oxt/OptionsDialog.xcs from [3732fcdcec] to [6ddcee836f].

20
21
22
23
24
25
26

27
28

29
30
31
32
33
34
35
        <group oor:name="o_${lang}">
            <info>
                <desc>The data for one leaf.</desc>
            </info>
            <prop oor:name="use_graphspell" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="use_graphspell_sugg" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="use_extended_dic" oor:type="xs:int"><value>0</value></prop>

            <prop oor:name="use_personal_dic" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="extended_dic" oor:type="xs:string"><value></value></prop>

            <prop oor:name="personal_dic" oor:type="xs:string"><value></value></prop>
        </group>
    </templates>

    <component>
        <group oor:name="Leaves">
            <node-ref oor:name="${lang}" oor:node-type="${lang}" />







>


>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        <group oor:name="o_${lang}">
            <info>
                <desc>The data for one leaf.</desc>
            </info>
            <prop oor:name="use_graphspell" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="use_graphspell_sugg" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="use_extended_dic" oor:type="xs:int"><value>0</value></prop>
            <prop oor:name="use_community_dic" oor:type="xs:int"><value>0</value></prop>
            <prop oor:name="use_personal_dic" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="extended_dic" oor:type="xs:string"><value></value></prop>
            <prop oor:name="community_dic" oor:type="xs:string"><value></value></prop>
            <prop oor:name="personal_dic" oor:type="xs:string"><value></value></prop>
        </group>
    </templates>

    <component>
        <group oor:name="Leaves">
            <node-ref oor:name="${lang}" oor:node-type="${lang}" />

Modified gc_lang/fr/oxt/Graphspell.py from [37463449be] to [46a0993dea].

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
82
83
84
85
            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_personal_dic")):
                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

    # XServiceInfo
    def getImplementationName (self):
        return self.sImplementationName







|

|
|







<
<
<
|
<





>
>
>
>
>
>
>
>
>
>
>
>
>







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
82
83
84
85
86
87
88
89
90
91
92
93
94
            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)
            self.xOptionNode = self.xSettingNode.getByName("o_fr")
            personal_dic = ""
            if (self.xOptionNode.getPropertyValue("use_personal_dic")):
                sPersonalDicJSON = self.xOptionNode.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.loadHunspell()

            # print("Graphspell: init done")
        except:
            print("Graphspell: init failed")
            traceback.print_exc()
    
    def loadHunspell (self):
        # Hunspell is a fallback spellchecker
        try:
            self.xHunspell = self.xSvMgr.createInstance("org.openoffice.lingu.MySpellSpellChecker")
        except:
            print("Hunspell: init failed")
            traceback.print_exc()
            self.xHunspell = False
            self.bHunspell = False
        else:
            self.xHunspellLocale = Locale('fr', 'MC', '')
            self.bHunspell = not bool(self.xOptionNode.getPropertyValue("use_graphspell_sugg"))

    # XServiceName
    def getServiceName (self):
        return self.sImplementationName     #self.sServiceName

    # XServiceInfo
    def getImplementationName (self):
        return self.sImplementationName
104
105
106
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
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
    
    # XSpellChecker
    # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html
    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):
        xLinguServiceManager = self.xSvMgr.createInstance("com.sun.star.linguistic2.LinguServiceManager")
        #print ("STTTSpeller: lingu service manager = %s" % repr(xLinguServiceManager))
        lService = xLinguServiceManager.getAvailableServices('com.sun.star.linguistic2.SpellChecker', Locale("fr", "MC", ""))
        #print ("STTTSpeller: spell services: %s" % repr(lService))
        for speller in lService:
            print(repr(speller))
            #if speller == self.ImplementationName:
            #    continue
            #self.fallback_sc = self.xSvMgr.createInstance (speller)
            #if self.fallback_sc:
            #    #print ("STTTSpeller: found other spell checker: %s" % speller)
            #    break


class SpellAlternatives (unohelper.Base, XSpellAlternatives):
    
    def __init__ (self, sWord, lSugg):
        try:
            self.sWord = sWord
            self.lSugg = lSugg







>



<
<
<
<
<
<



>
|
|
|
|
|
<
>
|
|
|
|
|








<

<
|
|
|

|
|
|

>







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
141
142
143
144
145
146

147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    
    # XSpellChecker
    # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html
    def isValid (self, aWord, rLocale, aProperties):
        try:
            aWord = zElidedWords.sub("", aWord.rstrip("."), count=1)
            return self.oGraphspell.isValidToken(aWord)
            # return self.xHunspell.isValid(aWord, self.xHunspellLocale, aProperties)
        except:
            traceback.print_exc()
        return False







    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"
        try:
            if not self.bHunspell:
                lSugg = []
                for l in self.oGraphspell.suggest(aWord):
                    lSugg.extend(l)
                return SpellAlternatives(aWord, tuple(lSugg))

            else:
                # fallback dictionary suggestions (Hunspell)
                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):
        xLinguServiceManager = self.xSvMgr.createInstance("com.sun.star.linguistic2.LinguServiceManager")

        lService = xLinguServiceManager.getAvailableServices('com.sun.star.linguistic2.SpellChecker', Locale("fr", "MC", ""))

        for sSpellchecker in lService:
            print(repr(sSpellchecker))
            #if sSpellchecker == self.ImplementationName:
            #    continue
            #self.xFallbackSpellChecker = self.xSvMgr.createInstance(sSpellchecker)
            #if self.xFallbackSpellChecker:
            #    print("Spell checker: %s" % xSpellChecker)
            #    break


class SpellAlternatives (unohelper.Base, XSpellAlternatives):
    
    def __init__ (self, sWord, lSugg):
        try:
            self.sWord = sWord
            self.lSugg = lSugg