forked from hannanabdul55/mobilechatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_history_1.py
executable file
·54 lines (53 loc) · 2.39 KB
/
build_history_1.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
def build_history_1(data_list, supported_tags):
history_list = [] # list of all histories
sents = []
count = 0
expected = []
for data in data_list: # data is the inputs entered by a given student
data1 = data['data']
for rec in data1:
updates = rec['updates']
sent = rec['sentence']
words = []
# print rec
rels = rec.get("rels",[{"irrelevant":[]}])
expected.append(rels)
for i in range(len(updates)):
words.append(updates[i]['word'])
#------------------------------------------------------------------------------------------------
# NOTE: below code is a temporary hack to build the MAxEnt for just 2 tags - we will change this later
if (updates[i]['tag'] not in supported_tags):
if updates[i]['tag'] == "Model":
updates[i]['tag'] = "Version"
else:
updates[i]['tag'] = "Other"
#------------------------------------------------------------------------------------------------
sents.append(words)
'''for i in range(len(updates)):
history = {}
history["i"] = i
if i == 0:
history["ta"] = "*" # special tag
history["tb"] = "*" # special tag
elif i == 1:
history["ta"] = "*" # special tag
history["tb"] = updates[i - 1]['tag']
else:
history["ta"] = updates[i - 2]['tag']
history["tb"] = updates[i - 1]['tag']
history["wn"] = count
history_list.append((history, updates[i]['tag'], ))'''
history = {}
history["i"] = i
history["updates"] = updates
history["sentences"] = words
history["wn"] = count
if len(rels)>0:
history["reltags"] = rels[0].values()
else:
history["reltags"] = []
if len(history["reltags"])>0:
history["reltags"] = history["reltags"][0]
history_list.append((history, rels,))
count += 1
return (history_list, sents, expected)