File: issue_56.py

package info (click to toggle)
python-pyahocorasick 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 748 kB
  • sloc: ansic: 4,554; python: 2,823; sh: 312; makefile: 242
file content (41 lines) | stat: -rw-r--r-- 617 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import ahocorasick




def iter_results(s):
    r = []
    for x in A.iter(teststr):
        r.append(x)

    return r


def find_all_results(s):

    r = []
    
    def append(x, s):
        r.append((x, s))

    A.find_all(s, append)

    return r


A = ahocorasick.Automaton()

for word in ("poke", "go", "pokegois", "egoist"):
    A.add_word(word, word)

A.make_automaton()

teststr = 'pokego pokego  pokegoist'
expected = iter_results(teststr)
findall  = find_all_results(teststr)

if findall != expected:
    print("expected: %s" % expected)
    print("findall : %s" % findall)
    assert findall == expected