示例#1
0
def test_automaton():
    schema = fields.Schema(text=fields.TEXT)
    with TempIndex(schema, "automatonspell") as ix:
        with ix.writer() as w:
            w.add_document(text=u" ".join(_wordlist))

        with ix.reader() as r:
            bterms = list(r.lexicon("text"))
            words = [bterm.decode("utf8") for bterm in bterms]
            assert words == _wordlist

            typo = "reoction"
            sugs = list(r.terms_within("text", typo, maxdist=2))
            target = [w for w in _wordlist if levenshtein(typo, w) <= 2]
            assert sugs == target
def test_automaton():
    schema = fields.Schema(text=fields.TEXT)
    with TempIndex(schema, "automatonspell") as ix:
        with ix.writer() as w:
            w.add_document(text=u" ".join(_wordlist))

        with ix.reader() as r:
            bterms = list(r.lexicon("text"))
            words = [bterm.decode("utf8") for bterm in bterms]
            assert words == _wordlist

            typo = "reoction"
            sugs = list(r.terms_within("text", typo, maxdist=2))
            target = [w for w in _wordlist if levenshtein(typo, w) <= 2]
            assert sugs == target
示例#3
0
 def find_brute(target, k):
     for w in words:
         d = levenshtein(w, target, k)
         if d <= k and w[:prefixlen] == target[:prefixlen]:
             yield w
示例#4
0
 def find_brute(target, k):
     for w in words:
         if levenshtein(w, target, k) <= k:
             yield w
示例#5
0
def test_list_corrector():
    corr = spelling.ListCorrector(_wordlist)
    typo = "reoction"
    sugs = list(corr.suggest(typo, maxdist=2))
    target = [w for w in _wordlist if levenshtein(typo, w) <= 2]
    assert sugs == target
def test_list_corrector():
    corr = spelling.ListCorrector(_wordlist)
    typo = "reoction"
    sugs = list(corr.suggest(typo, maxdist=2))
    target = [w for w in _wordlist if levenshtein(typo, w) <= 2]
    assert sugs == target
示例#7
0
 def find_brute(target, k):
     for w in words:
         d = levenshtein(w, target, k)
         if d <= k and w[:prefixlen] == target[:prefixlen]:
             yield w
示例#8
0
 def find_brute(target, k):
     for w in words:
         if levenshtein(w, target, k) <= k:
             yield w