/
test.py
84 lines (69 loc) · 2.73 KB
/
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
from questions import *
from trivialpursuitfunctions import *
from scoring import *
from output import *
from determine import *
from importcache import *
#What other options should test take in?
def runQuery( questions, scoringFunction, cache=False):
numberCorrect = 0
currentCount = 0
for question in questions:
currentCount += 1
print "*****"
print "Processing Query %d of %d " % (currentCount, len(questions))
# Read in question, choices, and correct answer
text = question[0]
choices = question[1]
correct = question[2]
outputCount = question[3]
if cache == False:
print "Processing NLTK..."
# Parse urls, questions, answers and generate keywords
raw = NLTK_parse(queryphrase=text, answers=choices)
nltk_data = raw[0] # array of size 6
nltk_time = raw[1] # array of size 6
else:
print "Reading in NLTK cache..."
nltk_data = readCache(outputCount)
nltk_time = [0]*6
print "AI & Scoring..."
# Get answer weight with scoring function(s)
weights = score(choices, nltk_data, scoringFunction)
results = weights[0] # array of size 4
ai_time = weights[1] # array of size 4
results_raw = str(results)
print "Determining Answer..."
# Normalize to determine answer
correctness = determineAnswer(results, choices, correct)
answer = correctness[0]
confidence = correctness[1]
candidate = correctness[2]
de_time = correctness[3]
# Save the results sys.out txt
output(text, choices, correct, nltk_data, results, results_raw, answer, confidence, candidate, nltk_time, ai_time, de_time, outputCount, cache)
print "*****"
# Print results live
bld = text + ": "
if answer[0] == 1:
numberCorrect += 1
bld += "Correct"
else:
bld += "Incorrect"
print bld
print str(numberCorrect) + "/" + str(len(questions))
"""
runQuery(tp_Questions0, useAllScores, cache=True)
runQuery(tp_Questions1, useAllScores, cache=True)
runQuery(tp_Questions2, useAllScores, cache=True)
runQuery(tp_Questions3, useAllScores, cache=True)
"""
runQuery(tp_Questions4, useAllScores, cache=True)
"""runQuery(tp_Questions5, useAllScores, cache=True)
runQuery(tp_Questions6, useAllScores, cache=True)
runQuery(tp_Questions7, useAllScores, cache=True)
runQuery(tp_Questions8, useAllScores, cache=True)
runQuery(tp_Questions9, useAllScores, cache=True)
runQuery(tp_Questions10, useAllScores, cache=True)
runQuery(tp_Questions11, useAllScores, cache=True)
"""