22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
class SpellChecker ():
def __init__ (self, sLangCode, sfMainDic="", sfExtendedDic="", sfPersonalDic=""):
"returns True if the main dictionary is loaded"
self.sLangCode = sLangCode
if not sfMainDic:
sfMainDic = dDefaultDictionaries.get(sLangCode, "")
self.oMainDic = self._loadDictionary(sfMainDic)
self.oExtendedDic = self._loadDictionary(sfExtendedDic)
self.oPersonalDic = self._loadDictionary(sfPersonalDic)
def _loadDictionary (self, sfDictionary):
"returns an IBDAWG object"
if not sfDictionary:
return None
try:
return ibdawg.IBDAWG(sfDictionary)
except:
print("Error: <" + sDicName + "> not loaded.")
traceback.print_exc()
return None
def setMainDictionary (self, sfDictionary):
"returns True if the dictionary is loaded"
self.oMainDic = self._loadDictionary(sfDictionary)
return bool(self.oMainDic)
|
|
|
|
>
>
|
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
class SpellChecker ():
def __init__ (self, sLangCode, sfMainDic="", sfExtendedDic="", sfPersonalDic=""):
"returns True if the main dictionary is loaded"
self.sLangCode = sLangCode
if not sfMainDic:
sfMainDic = dDefaultDictionaries.get(sLangCode, "")
self.oMainDic = self._loadDictionary(sfMainDic, True)
self.oExtendedDic = self._loadDictionary(sfExtendedDic)
self.oPersonalDic = self._loadDictionary(sfPersonalDic)
def _loadDictionary (self, sfDictionary, bNecessary=False):
"returns an IBDAWG object"
if not sfDictionary:
return None
try:
return ibdawg.IBDAWG(sfDictionary)
except Exception as e:
if bNecessary:
raise Exception(str(e), "Error: <" + sfDictionary + "> not loaded.")
print("Error: <" + sfDictionary + "> not loaded.")
traceback.print_exc()
return None
def setMainDictionary (self, sfDictionary):
"returns True if the dictionary is loaded"
self.oMainDic = self._loadDictionary(sfDictionary)
return bool(self.oMainDic)
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
return True
return False
def getMorph (self, sWord):
"retrieves morphologies list, different casing allowed"
lResult = self.oMainDic.getMorph(sWord)
if self.oExtendedDic:
lResult.extends(self.oExtendedDic.getMorph(sWord))
if self.oPersonalDic:
lResult.extends(self.oPersonalDic.getMorph(sWord))
return lResult
def suggest (self, sWord, nSuggLimit=10):
"generator: returns 1, 2 or 3 lists of suggestions"
yield self.oMainDic.suggest(sWord, nSuggLimit)
if self.oExtendedDic:
yield self.oExtendedDic.suggest(sWord, nSuggLimit)
|
|
|
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
return True
return False
def getMorph (self, sWord):
"retrieves morphologies list, different casing allowed"
lResult = self.oMainDic.getMorph(sWord)
if self.oExtendedDic:
lResult.extend(self.oExtendedDic.getMorph(sWord))
if self.oPersonalDic:
lResult.extend(self.oPersonalDic.getMorph(sWord))
return lResult
def suggest (self, sWord, nSuggLimit=10):
"generator: returns 1, 2 or 3 lists of suggestions"
yield self.oMainDic.suggest(sWord, nSuggLimit)
if self.oExtendedDic:
yield self.oExtendedDic.suggest(sWord, nSuggLimit)
|