Grammalecte  Check-in [06aaa44305]

Overview
Comment:[lo] graphspell wrapper update
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: 06aaa4430538c71a6d7def0e9f1937cc9d9134b60be8ca57ca5e8c3fb820f46b
User & Date: olr on 2018-04-05 21:22:39
Other Links: manifest | tags
Context
2018-04-06
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
21:20
[lo] change menu order check-in: 4706c41cb7 user: olr tags: trunk, lo
Changes

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

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale


lLocale = {
    # List of locales in LibreOffice
    # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx
    ('la', 'VA', ''),  # Latin (for testing purpose)
    ('fr', 'FR', ''),  # France
    ('fr', 'BE', ''),  # Belgique
    ('fr', 'CA', ''),  # Canada
    ('fr', 'CH', ''),  # Suisse
    ('fr', 'LU', ''),  # Luxembourg
    #('fr', 'MC', ''),  # Monaco
    ('fr', 'BF', ''),  # Burkina Faso







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale


lLocale = {
    # List of locales in LibreOffice
    # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx
    #('la', 'VA', ''),  # Latin (for testing purpose)
    ('fr', 'FR', ''),  # France
    ('fr', 'BE', ''),  # Belgique
    ('fr', 'CA', ''),  # Canada
    ('fr', 'CH', ''),  # Suisse
    ('fr', 'LU', ''),  # Luxembourg
    #('fr', 'MC', ''),  # Monaco
    ('fr', 'BF', ''),  # Burkina Faso
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            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.bHunspell
            self.xHunspell = None
            self.xHunspellLocale = Locale('fr', 'MC', '')
            #self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale')
            #self.xHunspellLocale.Language = 'fr'
            #self.xHunspellLocale.Country = 'FR'
            print("init done")
        except:
            print("Graphspell: init")
            traceback.print_exc()
    
    # XServiceName
    def getServiceName (self):
        return self.sImplementationName     #self.sServiceName

    # XServiceInfo







<
|




|

|







49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            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

    # XServiceInfo
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
128
    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







    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"

        lSugg = []
        for l in self.oGraphspell.suggest(aWord):
            lSugg.extend(l)
        return SpellAlternatives(aWord, tuple(lSugg))
        try:
            if not self.xHunspell:
                self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker")
            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)"
















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







>
>
>
>
>
>



>





<
<










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







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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    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