Grammalecte  Check-in [f4c85fbe0b]

Overview
Comment:[core] ibdawg: code cleaning
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: f4c85fbe0b8986f412b9702c32ea6d2f8277ad4d1f2ed431559893e5cff1456d
User & Date: olr on 2017-07-03 02:35:21
Other Links: manifest | tags
Context
2017-07-03
09:30
[core] ibdawg: suggest() seeks for tails check-in: e07a5e6edb user: olr tags: trunk, core
02:35
[core] ibdawg: code cleaning check-in: f4c85fbe0b user: olr tags: trunk, core
2017-07-02
19:53
[core] ibdawg: suggest() use sets instead of lists check-in: f11e2ad39c user: olr tags: trunk, core
Changes

Modified gc_core/py/ibdawg.py from [48f4ad6627] to [e66ef9b298].

1
2
3
4
5
6
7
8
9
#!python3
# -*- coding: UTF-8 -*-

import os
import traceback
import pkgutil
import re
from itertools import chain


<







1

2
3
4
5
6
7
8
#!python3


import os
import traceback
import pkgutil
import re
from itertools import chain

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
            if sWord.isupper() and len(sWord) > 1:
                l.extend(self.morph(sWord.capitalize()))
        return l

    def suggest (self, sWord):
        "returns a set of similar words"
        # first, we check for similar words
        #return set(self._suggestWithCrushedUselessChars(cp.clearWord(sWord)))
        aSugg = self._suggest(sWord)
        if not aSugg:
            aSugg.update(self._suggest(sWord[1:]))
            aSugg.update(self._suggest(sWord[:-1]))
            aSugg.update(self._suggest(sWord[1:-1]))
            if not aSugg:
                aSugg.update(self._suggestWithCrushedUselessChars(cp.clearWord(sWord)))
        return aSugg

    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)







|










|







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
            if sWord.isupper() and len(sWord) > 1:
                l.extend(self.morph(sWord.capitalize()))
        return l

    def suggest (self, sWord):
        "returns a set of similar words"
        # first, we check for similar words
        #return self._suggestWithCrushedUselessChars(cp.clearWord(sWord))
        aSugg = self._suggest(sWord)
        if not aSugg:
            aSugg.update(self._suggest(sWord[1:]))
            aSugg.update(self._suggest(sWord[:-1]))
            aSugg.update(self._suggest(sWord[1:-1]))
            if not aSugg:
                aSugg.update(self._suggestWithCrushedUselessChars(cp.clearWord(sWord)))
        return aSugg

    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)