-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_test.py
101 lines (94 loc) · 2.34 KB
/
python_test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import target.debug.libngramconnector as lnc
import pprint
from enum import Enum
import time
class token(Enum):
end = "!END"
timed_test_ngrams = None
try:
import json
with open("./optional/3grams.json", "r") as f:
timed_test_ngrams = json.loads(f.read())
except:
print("Did not load timed_test_ngrams")
example_ngram = {
"this":
{
"is":
{
"a": 1,
"one": 2,
"an": 3
},
"should":
{
"work": 1
}
},
"is":
{
"an":
{
"example": 1
}
},
"an":
{
"example":
{
"of": 1
}
},
"example":
{
"of":
{
"a": 1
}
},
"of":
{
"a":
{
"3gram": 1
}
},
"a":
{
"3gram":
{
"data": 1
},
token.end:
{
token.end: 1
}
},
token.end:
{
token.end:
{
token.end: 1
}
},
"3gram":
{
"data":
{
"structure": 1,
token.end: 1
}
}
}
pprint.pprint(example_ngram)
print(lnc.depth({"a": 1}))
print(lnc.depth({"a": {"b": 1}}))
print(lnc.depth(example_ngram))
print(lnc.bfs(example_ngram, 3, ["this"], ["structure"]))
print(lnc.bfs(example_ngram, 3, ["this"], [token.end]))
print(lnc.bfs(example_ngram, 3, ["non", "existing"], ["ngram"]))
if timed_test_ngrams:
start = time.time()
res = lnc.bfs(timed_test_ngrams, 3, ["i"], ["."])
end = time.time()
print("Search took {} seconds and resulted in \"{}\"".format(end - start, res))