Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -174,10 +174,12 @@ throw ValueError("# Error: unknown code: " + this.nCompressionMethod); } //console.log(this.getInfo()); this.bOptNumSigle = true; this.bOptNumAtLast = false; + + this.aSuggState = new Set(); } getInfo () { return ` Language: ${this.sLangName} Lang code: ${this.sLangCode} Dictionary name: ${this.sDicName}\n` + ` Compression method: ${this.nCompressionMethod} Date: ${this.sDate} Stemming: ${this.cStemming}FX\n` + @@ -316,10 +318,11 @@ } else if (sWord.gl_isLowerCase()) { this._suggest(oSuggResult, sWord.gl_toCapitalize(), nMaxSwitch, nMaxDel, nMaxHardRepl); } let aSugg = oSuggResult.getSuggestions(nSuggLimit); + this.aSuggState.clear(); if (sSfx || sPfx) { // we add what we removed return aSugg.map( (sSugg) => { return sPfx + sSugg + sSfx } ); } return aSugg; @@ -335,10 +338,18 @@ for (let sTail of this._getTails(iAddr)) { oSuggResult.addSugg(sNewWord+sTail); } return; } + else if (sRemain.length < 4) { + let sState = sNewWord + ":" + sRemain; + if (this.aSuggState.has(sState)) { + return; + } + this.aSuggState.add(sState); + } + let cCurrent = sRemain.slice(0, 1); for (let [cChar, jAddr] of this._getCharArcs(iAddr)) { if (char_player.d1to1.gl_get(cCurrent, cCurrent).indexOf(cChar) != -1) { this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar); } Index: graphspell/ibdawg.py ================================================================== --- graphspell/ibdawg.py +++ graphspell/ibdawg.py @@ -136,10 +136,12 @@ raise ValueError(" # Error: unknown code: {}".format(self.nCompressionMethod)) self.bOptNumSigle = False self.bOptNumAtLast = False + self.aSuggState = set() + def _initBinary (self): "initialize with binary structure file" if self.by[0:17] != b"/grammalecte-fsa/": raise TypeError("# Error. Not a grammalecte-fsa binary dictionary. Header: {}".format(self.by[0:9])) if not(self.by[17:18] == b"1" or self.by[17:18] == b"2" or self.by[17:18] == b"3"): @@ -291,10 +293,11 @@ if sWord.istitle(): self._suggest(oSuggResult, sWord.lower(), nMaxSwitch=nMaxSwitch, nMaxDel=nMaxDel, nMaxHardRepl=nMaxHardRepl) elif sWord.islower(): self._suggest(oSuggResult, sWord.title(), nMaxSwitch=nMaxSwitch, nMaxDel=nMaxDel, nMaxHardRepl=nMaxHardRepl) aSugg = oSuggResult.getSuggestions(nSuggLimit) + self.aSuggState.clear() if sSfx or sPfx: # we add what we removed return list(map(lambda sSug: sPfx + sSug + sSfx, aSugg)) return aSugg @@ -305,10 +308,15 @@ if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask: oSuggResult.addSugg(sNewWord, nDeep) for sTail in self._getTails(iAddr): oSuggResult.addSugg(sNewWord+sTail, nDeep) return + elif len(sRemain) < 4: + sState = sNewWord + ":" + sRemain + if sState in self.aSuggState: + return + self.aSuggState.add(sState) cCurrent = sRemain[0:1] for cChar, jAddr in self._getCharArcs(iAddr): if cChar in cp.d1to1.get(cCurrent, cCurrent): self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar) elif not bAvoidLoop and nMaxHardRepl: