-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomp_trie_automation.py
48 lines (32 loc) · 1.18 KB
/
comp_trie_automation.py
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
42
43
44
45
46
47
from lev_trie_gen import *
from lev_dfa_gen import *
from lib.util.timer import Timer
corpus_trie = load_data(corpus_trie_path)
corpus_dfa = load_data(corpus_dfa_path)
print(corpus_trie.stats())
# max edit edistance
k = 3
timer = Timer()
# tests = ["food"]
tests = ["beautiful", "bad", "heart", "universty"]
ks = list(range(1, k + 1))
lev_dfa = LevTrieDFAGenerator(corpus_dfa)
lev_trie = LevTrieGenerator(corpus_trie)
for w in tests:
for k in ks:
print("\nvalidating [{:10}] on k = {}".format(w, k))
timer.start("Lev-Automation")
dfa_result = lev_dfa.gen_candidates(w, k)
timer.stop_and_report("Lev-Automation")
timer.start("Lev-Trie")
trie_result = lev_trie.gen_candidates(w, k)
timer.stop_and_report("Lev-Trie")
dfa_result = set(dfa_result)
trie_result = set(trie_result)
assert(dfa_result == trie_result)
# print("Naive: {}".format(naive_result))
# print("Lev: {}".format(lev_result))
# for w in naive_result:
# if w not in lev_result:
# raise Exception("{} in Naive but not in Lev!".format(w))
print("--------- Passed ---------")