1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
+
-
+
-
-
+
+
+
-
-
-
+
-
-
+
+
+
+
|
"""
# Graphspell
Graphspell
#
# Spellchecker based on a DAWG (Direct Acyclic Word Graph)
Spellchecker based on a DAWG (Direct Acyclic Word Graph)
"""
# License: MPL 2
import uno
import unohelper
import traceback
import re
import json
import helpers
#import uno
from grammalecte.graphspell import SpellChecker
import unohelper
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
import helpers
from grammalecte.graphspell import SpellChecker
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
|
︙ | | |
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
+
-
+
|
('fr', 'TG', '') # Togo
}
zElidedWords = re.compile("(?i)^(?:[ldnmtsjcçy]|qu|lorsqu|quoiqu|puisqu|jusqu)['’`‘]")
class Graphspell (unohelper.Base, XSpellChecker, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales):
"""Spellchecker class: will be loaded by LibreOffice"""
def __init__ (self, ctx, *args):
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)
self.xOptionNode = self.xSettingNode.getByName("o_fr")
sMainDicName = self.xOptionNode.getPropertyValue("main_dic_name")
personal_dic = ""
if (self.xOptionNode.getPropertyValue("use_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()
|
︙ | | |
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
-
+
|
return self.sImplementationName #self.sServiceName
# XServiceInfo
def getImplementationName (self):
return self.sImplementationName
def supportsService (self, sServiceName):
return (sServiceName in self.tSupportedServiceNames)
return sServiceName in self.tSupportedServiceNames
def getSupportedServiceNames (self):
return self.tSupportedServiceNames
# XSupportedLocales
def hasLocale (self, aLocale):
if aLocale in self.locales:
|
︙ | | |
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
+
-
-
-
+
+
|
traceback.print_exc()
return False
def spell (self, aWord, aLocale, aProperties):
"returns an object SpellAlternatives"
try:
if not self.bHunspell:
# Graphspell
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)
# 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)"
|
︙ | | |
|