Index: graphspell/spellchecker.py ================================================================== --- graphspell/spellchecker.py +++ graphspell/spellchecker.py @@ -6,11 +6,11 @@ # - the main dictionary, bundled with the package # - the extended dictionary # - the community dictionary, added by an organization # - the personal dictionary, created by the user for its own convenience - +import importlib import traceback from . import ibdawg from . import tokenizer @@ -34,10 +34,13 @@ self.oPersonalDic = self._loadDictionary(sfPersonalDic) self.bExtendedDic = bool(self.oExtendedDic) self.bCommunityDic = bool(self.oCommunityDic) self.bPersonalDic = bool(self.oPersonalDic) self.oTokenizer = None + # Default suggestions + self.dDefaultSugg = None + self.loadSuggestions(sLangCode) # storage self.bStorage = False self._dMorphologies = {} # key: flexion, value: list of morphologies self._dLemmas = {} # key: flexion, value: list of lemmas @@ -101,10 +104,21 @@ self.bCommunityDic = False def deactivatePersonalDictionary (self): self.bPersonalDic = False + + # Default suggestions + + def loadSuggestions (self, sLangCode): + try: + suggest_module = importlib.import_module("."+sLangCode, "graphspell") + except: + print("No suggestion module for language <"+sLangCode+">") + return + self.dDefaultSugg = suggest_module.dSugg + # Storage def activateStorage (self): self.bStorage = True @@ -210,11 +224,14 @@ return self._dLemmas[sWord] return set([ s[1:s.find(" ")] for s in self.getMorph(sWord) ]) def suggest (self, sWord, nSuggLimit=10): "generator: returns 1, 2 or 3 lists of suggestions" - yield self.oMainDic.suggest(sWord, nSuggLimit) + if self.dDefaultSugg and sWord in self.dDefaultSugg: + yield self.dDefaultSugg[sWord].split("|") + else: + yield self.oMainDic.suggest(sWord, nSuggLimit) if self.bExtendedDic: yield self.oExtendedDic.suggest(sWord, nSuggLimit) if self.bCommunityDic: yield self.oCommunityDic.suggest(sWord, nSuggLimit) if self.bPersonalDic: