Grammalecte  Check-in [528ccfcead]

Overview
Comment:[core] better suggestion engine for the spellchecker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: 528ccfceadd2d0b764281a3e2f633f3e237516d863f45a4bf0b990096d256d4a
User & Date: olr on 2017-11-21 17:05:31
Other Links: manifest | tags
Context
2017-11-21
17:06
[build] use Firefox Nightly 64 bits check-in: f424d4f1d9 user: olr tags: build, trunk
17:05
[core] better suggestion engine for the spellchecker check-in: 528ccfcead user: olr tags: core, trunk
11:33
[core] char_player: ph/f check-in: a97a2c1409 user: olr tags: core, trunk
Changes

Modified gc_core/js/ibdawg.js from [952ba094d6] to [0055aa4ed5].

   284    284               }
   285    285               for (let sTail of this._getTails(iAddr)) {
   286    286                   oSuggResult.addSugg(sNewWord+sTail);
   287    287               }
   288    288               return;
   289    289           }
   290    290           let cCurrent = sRemain.slice(0, 1);
   291         -        for (let [cChar, jAddr] of this._getSimilarCharArcs(cCurrent, iAddr)) {
   292         -            this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar);
          291  +        for (let [cChar, jAddr] of this._getCharArcs(iAddr)) {
          292  +            if (char_player.d1to1.gl_get(cCurrent, [cCurrent]).includes(cChar)) {
          293  +                this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar);
          294  +            }
          295  +            else if (!bAvoidLoop && nMaxHardRepl) {
          296  +                this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl-1, nDeep+1, jAddr, sNewWord+cChar, true);
          297  +            }
   293    298           }
   294    299           if (!bAvoidLoop) { // avoid infinite loop
   295    300               if (sRemain.length > 1) {
   296    301                   if (cCurrent == sRemain.slice(1, 2)) {
   297    302                       // same char, we remove 1 char without adding 1 to <sNewWord>
   298    303                       this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord);
   299    304                   }
................................................................................
   310    315                   // Phonetic replacements
   311    316                   for (let sRepl of char_player.get1toXReplacement(sNewWord.slice(-1), cCurrent, sRemain.slice(1,2))) {
   312    317                       this._suggest(oSuggResult, sRepl + sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, true);
   313    318                   }
   314    319                   for (let sRepl of char_player.d2toX.gl_get(sRemain.slice(0, 2), [])) {
   315    320                       this._suggest(oSuggResult, sRepl + sRemain.slice(2), nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, true);
   316    321                   }
   317         -                // Hard replacements
   318         -                if (nDeep > 3 && nMaxHardRepl && sRemain.length >= 2) {
   319         -                    for (let [cChar, kAddr] of this._getCharArcs(iAddr)) {
   320         -                        if (!char_player.d1to1.gl_get(cCurrent, "").includes(cChar)) {
   321         -                            this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl-1, nDeep+1, kAddr, sNewWord+cChar, true);
   322         -                        }
   323         -                    }
   324         -                }
   325    322               }
   326    323               // end of word
   327    324               if (sRemain.length == 2) {
   328    325                   for (let sRepl of char_player.dFinal2.gl_get(sRemain, [])) {
   329    326                       this._suggest(oSuggResult, sRepl, nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, true);
   330    327                   }
   331    328               }

Modified gc_core/py/ibdawg.py from [1ba9326518] to [4376dde7d7].

   271    271           if not sRemain:
   272    272               if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
   273    273                   oSuggResult.addSugg(sNewWord, nDeep)
   274    274               for sTail in self._getTails(iAddr):
   275    275                   oSuggResult.addSugg(sNewWord+sTail, nDeep)
   276    276               return
   277    277           cCurrent = sRemain[0:1]
   278         -        for cChar, jAddr in self._getSimilarCharArcs(cCurrent, iAddr):
   279         -            self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar)
          278  +        for cChar, jAddr in self._getCharArcs(iAddr):
          279  +            if cChar in cp.d1to1.get(cCurrent, cCurrent):
          280  +                self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, jAddr, sNewWord+cChar)
          281  +            elif not bAvoidLoop and nMaxHardRepl:
          282  +                self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl-1, nDeep+1, jAddr, sNewWord+cChar, True)
   280    283           if not bAvoidLoop: # avoid infinite loop
   281    284               if len(sRemain) > 1:
   282    285                   if cCurrent == sRemain[1:2]:
   283    286                       # same char, we remove 1 char without adding 1 to <sNewWord>
   284    287                       self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord)
   285    288                   else:
   286    289                       # switching chars
................................................................................
   290    293                       if nMaxDel:
   291    294                           self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel-1, nMaxHardRepl, nDeep+1, iAddr, sNewWord, True)
   292    295                   # Phonetic replacements
   293    296                   for sRepl in cp.get1toXReplacement(sNewWord[-1:], cCurrent, sRemain[1:2]):
   294    297                       self._suggest(oSuggResult, sRepl + sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, True)
   295    298                   for sRepl in cp.d2toX.get(sRemain[0:2], ()):
   296    299                       self._suggest(oSuggResult, sRepl + sRemain[2:], nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, True)
   297         -                # Hard replacements
   298         -                if nDeep > 3 and nMaxHardRepl:
   299         -                    for cChar, kAddr in self._getCharArcs(iAddr):
   300         -                        if cChar not in cp.d1to1.get(cCurrent, ""):
   301         -                            self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl-1, nDeep+1, kAddr, sNewWord+cChar, True)
   302    300               # end of word
   303    301               if len(sRemain) == 2:
   304    302                   for sRepl in cp.dFinal2.get(sRemain, ()):
   305    303                       self._suggest(oSuggResult, sRepl, nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, True)
   306    304               elif len(sRemain) == 1:
   307    305                   self._suggest(oSuggResult, "", nMaxSwitch, nMaxDel, nMaxHardRepl, nDeep+1, iAddr, sNewWord, True) # remove last char and go on
   308    306                   for sRepl in cp.dFinal1.get(sRemain, ()):