forked from vishakha-lall/MapBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utilities.py
57 lines (49 loc) · 1.58 KB
/
test_utilities.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
import utilities
class TestClass:
test_input = "The quick brown fox jumps over the lazy dog."
clf = utilities.classify_model()
def test_setup_nltk(self):
result = utilities.setup_nltk()
assert result
def test_parse_sentence(self):
triples, root = utilities.parse_sentence(self.test_input)
triples = list(triples)
assert (("jumps", "VBZ"), "nsubj", ("fox", "NN")) in triples
assert (("jumps", "VBZ"), "nmod", ("dog", "NN")) in triples
assert root == "jumps"
def test_classify_model(self):
from features import features_dict
import hashlib
import numpy as np
keys = [
"id",
"wordCount",
"stemmedCount",
"stemmedEndNN",
"CD",
"NN",
"NNP",
"NNPS",
"NNS",
"PRP",
"VBG",
"VBZ",
"startTuple0",
"endTuple0",
"endTuple1",
"endTuple2",
"verbBeforeNoun",
"qMark",
"qVerbCombo",
"qTripleScore",
"sTripleScore",
"class",
]
id = hashlib.md5(str(self.test_input).encode("utf-8")).hexdigest()[:16]
f = features_dict(id, self.test_input)
features = [f[k] for k in keys][1:-1]
features = np.array(features).reshape(1, -1)
assert self.clf.predict(features)[0] == "S"
def test_classify_sentence(self):
result = utilities.classify_sentence(self.clf, self.test_input)
assert result == "S"