Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -37,10 +37,11 @@ // data let _sAppContext = ""; // what software is running let _dOptions = null; let _aIgnoredRules = new Set(); let _oDict = null; +let _oSpellChecker = null; let _dAnalyses = new Map(); // cache for data from dictionary var gc_engine = { @@ -320,14 +321,19 @@ //// Initialization load: function (sContext="JavaScript", sPath="") { try { if (typeof(require) !== 'undefined') { - var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js"); - _oDict = new ibdawg.IBDAWG("${dic_filename}.json"); + //var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js"); + //_oDict = new ibdawg.IBDAWG("${dic_filename}.json"); + console.log(""); + var spellchecker = require("resource://grammalecte/graphspell/spellchecker.js"); + _oSpellChecker = new spellchecker.Spellchecker("${lang}", "${dic_filename}.json"); } else { - _oDict = new IBDAWG("${dic_filename}.json", sPath); + //_oDict = new IBDAWG("${dic_filename}.json", sPath); + console.log("no "); + _oSpellChecker = new Spellchecker("${lang}", "${dic_filename}.json", sPath); } _sAppContext = sContext; _dOptions = gc_options.getOptions(sContext).gl_shallowCopy(); // duplication necessary, to be able to reset to default } catch (e) { @@ -334,11 +340,11 @@ helpers.logerror(e); } }, getDictionary: function () { - return _oDict; + return _oSpellChecker; }, //// Options setOption: function (sOpt, bVal) { @@ -388,13 +394,13 @@ helpers.echo("FSA: " + _dAnalyses.get(aWord[1])); return true; } function _storeMorphFromFSA (sWord) { - // retrieves morphologies list from _oDict -> _dAnalyses - //helpers.echo("register: "+sWord + " " + _oDict.getMorph(sWord).toString()) - _dAnalyses.set(sWord, _oDict.getMorph(sWord)); + // retrieves morphologies list from _oSpellChecker -> _dAnalyses + //helpers.echo("register: "+sWord + " " + _oSpellChecker.getMorph(sWord).toString()) + _dAnalyses.set(sWord, _oSpellChecker.getMorph(sWord)); return !!_dAnalyses.get(sWord); } function morph (dDA, aWord, sPattern, bStrict=true, bNoWord=false) { // analyse a tuple (position, word), return true if sPattern in morphologies (disambiguation on) Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -34,10 +34,11 @@ importScripts("grammalecte/graphspell/helpers.js"); importScripts("grammalecte/graphspell/str_transform.js"); importScripts("grammalecte/graphspell/char_player.js"); importScripts("grammalecte/graphspell/ibdawg.js"); +importScripts("grammalecte/graphspell/spellchecker.js"); importScripts("grammalecte/text.js"); importScripts("grammalecte/graphspell/tokenizer.js"); importScripts("grammalecte/fr/conj.js"); importScripts("grammalecte/fr/mfsp.js"); importScripts("grammalecte/fr/phonet.js"); Index: graphspell/spellchecker.py ================================================================== --- graphspell/spellchecker.py +++ graphspell/spellchecker.py @@ -17,21 +17,20 @@ "fr": "fr.bdic", "en": "en.bdic" } -class Spellchecker (): +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) - return bool(self.oMainDic) def _loadDictionary (self, sfDictionary): "returns an IBDAWG object" if not sfDictionary: return None @@ -70,35 +69,35 @@ return True return False def isValid (self, sWord): "checks if sWord is valid (different casing tested if the first letter is a capital)" - if self.oMainDic.isValid(sToken): + if self.oMainDic.isValid(sWord): return True - if self.oExtendedDic and self.oExtendedDic.isValid(sToken): + if self.oExtendedDic and self.oExtendedDic.isValid(sWord): return True - if self.oPersonalDic and self.oPersonalDic.isValid(sToken): + if self.oPersonalDic and self.oPersonalDic.isValid(sWord): return True return False def lookup (self, sWord): "checks if sWord is in dictionary as is (strict verification)" - if self.oMainDic.lookup(sToken): + if self.oMainDic.lookup(sWord): return True - if self.oExtendedDic and self.oExtendedDic.lookup(sToken): + if self.oExtendedDic and self.oExtendedDic.lookup(sWord): return True - if self.oPersonalDic and self.oPersonalDic.lookup(sToken): + if self.oPersonalDic and self.oPersonalDic.lookup(sWord): return True return False def getMorph (self, sWord): "retrieves morphologies list, different casing allowed" - lResult = self.oMainDic.getMorph(sToken) + lResult = self.oMainDic.getMorph(sWord) if self.oExtendedDic: - lResult.extends(self.oExtendedDic.getMorph(sToken)) + lResult.extends(self.oExtendedDic.getMorph(sWord)) if self.oPersonalDic: - lResult.extends(self.oPersonalDic.getMorph(sToken)) + 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)