Grammalecte  Check-in [8ea89d19b5]

Overview
Comment:[core] ibdawg: suggest2 > char priority
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | spellsugg
Files: files | file ages | folders
SHA3-256: 8ea89d19b58e96a0da175eaaca177071b4fe20063f9d816c032d2b0c6026b2e7
User & Date: olr on 2017-11-07 19:56:28
Other Links: branch diff | manifest | tags
Context
2017-11-07
22:04
[core][bug] ibdawg: suggest2 > fix char priority check-in: 41d308e073 user: olr tags: core, spellsugg
19:56
[core] ibdawg: suggest2 > char priority check-in: 8ea89d19b5 user: olr tags: core, spellsugg
19:28
[core] sort first range of suggestions + code clarification check-in: d22466bd67 user: olr tags: core, spellsugg
Changes

Modified gc_core/py/ibdawg.py from [69a64ae917] to [7b0e081c93].

   327    327           if nDeep >= oSuggResult.nDistLimit:
   328    328               sCleanNewWord = cp.cleanWord(sNewWord)
   329    329               if st.distanceSift4(oSuggResult.sCleanWord[:len(sCleanNewWord)], sCleanNewWord) > oSuggResult.nDistLimit:
   330    330                   return
   331    331           if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
   332    332               #logging.info((nDeep * "  ") + "__" + sNewWord + "__")
   333    333               oSuggResult.addSugg(sNewWord, nDeep)
   334         -        for cChar, jAddr in self._getCharArcs(iAddr):
          334  +        for cChar, jAddr in self._getCharArcsWithPriority(iAddr, oSuggResult.sWord[nDeep:nDeep+1]):
   335    335               self._suggest2(oSuggResult, nDeep+1, jAddr, sNewWord+cChar)
   336    336           return
   337    337   
   338    338       def _getCharArcs (self, iAddr):
   339    339           "generator: yield all chars and addresses from node at address <iAddr>"
   340    340           for nVal, jAddr in self._getArcs(iAddr):
   341    341               if nVal < self.nChar:
................................................................................
   344    344       def _getSimilarCharArcs (self, cChar, iAddr):
   345    345           "generator: yield similar char of <cChar> and address of the following node"
   346    346           for c in cp.d1to1.get(cChar, [cChar]):
   347    347               if c in self.dChar:
   348    348                   jAddr = self._lookupArcNode(self.dChar[c], iAddr)
   349    349                   if jAddr:
   350    350                       yield (c, jAddr)
          351  +
          352  +    def _getCharArcsWithPriority (self, iAddr, cChar):
          353  +        if not cChar:
          354  +            yield from self._getCharArcs(iAddr)
          355  +        lTuple = list(self._getCharArcs(iAddr))
          356  +        lTuple.sort(key=lambda t: 0  if t[0] in cp.d1to1.get(cChar, "")  else  1)
          357  +        yield from lTuple
   351    358   
   352    359       def _getTails (self, iAddr, sTail="", n=2):
   353    360           "return a list of suffixes ending at a distance of <n> from <iAddr>"
   354    361           aTails = set()
   355    362           for nVal, jAddr in self._getArcs(iAddr):
   356    363               if nVal < self.nChar:
   357    364                   if int.from_bytes(self.byDic[jAddr:jAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask: