200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
def _suggest (self, sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=False):
# recursive function
aSugg = set()
if not sWord:
if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
#show(nDeep, "___" + sNewWord + "___")
aSugg.add(sNewWord)
return aSugg
#show(nDeep, "<" + sWord + "> ===> " + sNewWord)
cCurrent = sWord[0:1]
for cChar, jAddr in self._getSimilarArcs(cCurrent, iAddr):
#show(nDeep, cChar)
aSugg.update(self._suggest(sWord[1:], nDeep+1, jAddr, sNewWord+cChar))
if not bAvoidLoop: # avoid infinite loop
|
>
>
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
def _suggest (self, sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=False):
# recursive function
aSugg = set()
if not sWord:
if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
#show(nDeep, "___" + sNewWord + "___")
aSugg.add(sNewWord)
for sTail in self._getTails(iAddr):
aSugg.add(sNewWord+sTail)
return aSugg
#show(nDeep, "<" + sWord + "> ===> " + sNewWord)
cCurrent = sWord[0:1]
for cChar, jAddr in self._getSimilarArcs(cCurrent, iAddr):
#show(nDeep, cChar)
aSugg.update(self._suggest(sWord[1:], nDeep+1, jAddr, sNewWord+cChar))
if not bAvoidLoop: # avoid infinite loop
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
def _getSimilarArcs (self, cChar, iAddr):
"generator: yield similar char of <cChar> and address of the following node"
for c in cp.d1to1.get(cChar, [cChar]):
if c in self.dChar:
jAddr = self._lookupArcNode(self.dChar[c], iAddr)
if jAddr:
yield (c, jAddr)
def _suggestWithCrushedUselessChars (self, sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=False):
aSugg = set()
if not sWord:
if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
show(nDeep, "!!! " + sNewWord + " !!!")
aSugg.add(sNewWord)
|
>
>
>
>
>
>
>
>
>
>
>
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
def _getSimilarArcs (self, cChar, iAddr):
"generator: yield similar char of <cChar> and address of the following node"
for c in cp.d1to1.get(cChar, [cChar]):
if c in self.dChar:
jAddr = self._lookupArcNode(self.dChar[c], iAddr)
if jAddr:
yield (c, jAddr)
def _getTails (self, iAddr, sTail="", n=2):
"return a list of suffixes ending at a distance of <n> from <iAddr>"
aTails = set()
for nVal, jAddr in self._getArcs(iAddr):
if nVal < self.nChar:
if int.from_bytes(self.byDic[jAddr:jAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
aTails.add(sTail + self.dCharVal[nVal])
if n:
aTails.update(self._getTails(jAddr, sTail+self.dCharVal[nVal], n-1))
return aTails
def _suggestWithCrushedUselessChars (self, sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=False):
aSugg = set()
if not sWord:
if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
show(nDeep, "!!! " + sNewWord + " !!!")
aSugg.add(sNewWord)
|