Index: gc_lang/fr/modules/tests_modules.py ================================================================== --- gc_lang/fr/modules/tests_modules.py +++ gc_lang/fr/modules/tests_modules.py @@ -65,11 +65,11 @@ ("ditirembique", "dithyrambique"), ("jai", "j’ai"), ("email", "courriel"), ("fatiqué", "fatigué"), ("coeur", "cœur"), - ("trèèèèèèèèès", "très"), + ("triiiiicheuuuur", "tricheur"), ("vraaaaiiiimeeeeennnt", "vraiment"), ("oeil", "œil"), ("Oeil", "Œil"), ("OEIL", "ŒIL"), ("apele", "appel"), @@ -78,10 +78,11 @@ ("testt", "test"), ("apelaion", "appellation"), ("exsepttion", "exception"), ("ebriete", "ébriété"), ("ennormmement", "énormément"), + ("maîtnesse", "maîtresse"), ("sintaxik", "syntaxique") ]: #with timeblock(sWord): for lSugg in self.oSpellChecker.suggest(sWrong): #print(sWord, "->", " ".join(lSugg)) Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -365,11 +365,11 @@ } if (nDist > oSuggResult.nDistLimit) { return; } let cCurrent = sRemain.slice(0, 1); - for (let [cChar, jAddr] of this._getCharArcs(iAddr)) { + for (let [cChar, jAddr] of this._getCharArcs(iAddr, cCurrent)) { if (char_player.d1to1.gl_get(cCurrent, cCurrent).indexOf(cChar) != -1) { this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, jAddr, sNewWord+cChar); } else if (!bAvoidLoop) { if (nMaxHardRepl && this.isNgramsOK(cChar+sRemain.slice(1,2))) { @@ -427,16 +427,25 @@ return true; } return this.a2grams.has(sChars); } - * _getCharArcs (iAddr) { + * _getCharArcs (iAddr, cChar="") { // generator: yield all chars and addresses from node at address + let lStack = []; for (let [nVal, jAddr] of this._getArcs(iAddr)) { if (nVal <= this.nChar) { - yield [this.dCharVal.get(nVal), jAddr]; + if (char_player.d1to1.gl_get(cChar, cChar).indexOf(this.dCharVal.get(nVal)) != -1) { + yield [this.dCharVal.get(nVal), jAddr]; + } + else { + lStack.push([this.dCharVal.get(nVal), jAddr]); + } } + } + while (lStack.length > 0) { + yield lStack.shift(); } } * _getSimilarCharArcs (cChar, iAddr) { // generator: yield similar char of and address of the following node Index: graphspell/ibdawg.py ================================================================== --- graphspell/ibdawg.py +++ graphspell/ibdawg.py @@ -251,11 +251,11 @@ if self.isValid(sWord1) and self.isValid(sWord2): oSuggResult.addSugg(sWord1+" "+sWord2) def _suggest (self, oSuggResult, sRemain, nMaxSwitch=0, nMaxDel=0, nMaxHardRepl=0, nMaxJump=0, nDist=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=False): # recursive function - #logging.info((nDeep * " ") + sNewWord + ":" + sRemain) + #logging.info((nDeep * " ") + f"{sNewWord}:{sRemain} nMaxSwitch:{nMaxSwitch} nMaxDel:{nMaxDel} nMaxHardRepl:{nMaxHardRepl} nMaxJump:{nMaxJump} | nDist:{nDist} / {oSuggResult.nDistLimit}") if self.lByDic[iAddr] & self._finalNodeMask: if not sRemain: oSuggResult.addSugg(sNewWord, nDeep) for sTail in self._getTails(iAddr): oSuggResult.addSugg(sNewWord+sTail, nDeep) @@ -266,11 +266,11 @@ if (len(sNewWord) > 1 and len(sRemain) > 1) or sNewWord in "aày" or sRemain in "aày": oSuggResult.addSugg(sNewWord+" "+sRemain, nDeep) if nDist > oSuggResult.nDistLimit: return cCurrent = sRemain[0:1] - for cChar, jAddr in self._getCharArcs(iAddr): + for cChar, jAddr in self._getCharArcs(iAddr, cCurrent): if cChar in cp.d1to1.get(cCurrent, cCurrent): self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, jAddr, sNewWord+cChar) elif not bAvoidLoop: if nMaxHardRepl and self.isNgramsOK(cChar+sRemain[1:2]): self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl-1, nMaxJump, nDist+1, nDeep+1, jAddr, sNewWord+cChar, True) @@ -308,15 +308,21 @@ return True if not self.a2grams: return True return sChars in self.a2grams - def _getCharArcs (self, iAddr): + def _getCharArcs (self, iAddr, cChar=""): "generator: yield all chars and addresses from node at address " + lStack = [] for nVal, jAddr in self._getArcs(iAddr): if nVal <= self.nChar: - yield (self.dCharVal[nVal], jAddr) + if self.dCharVal[nVal] in cp.d1to1.get(cChar, cChar): + yield (self.dCharVal[nVal], jAddr) + else: + lStack.append((self.dCharVal[nVal], jAddr)) + while lStack: + yield lStack.pop(0) def _getTails (self, iAddr, sTail="", n=2): "return a list of suffixes ending at a distance of from " aTails = set() for nVal, jAddr in self._getArcs(iAddr):