def build_history(data_list, supported_tags_phones,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']
#data1 is for every sentence entered by user
for rec in data1:
updates = rec['updates']
sent = rec['sentence']
relatedTags=[]
relations=[]
if "rels" in rec.keys():
relatedEntities = rec['rels']
expected.append(relatedEntities)
for i in relatedEntities:
relations.append(i.keys())
for j in i[i.keys()[0]]:
relatedTags.append(j)
words = []
posTaggedSent = postagger(sent)
#chunkPhrases = chunker(sent)
if len(updates) == len(posTaggedSent):
for i in range(len(updates)):
words.append({"word":updates[i]['word'],"pos":posTaggedSent[i],"tag":updates[i]['tag']})
#------------------------------------------------------------------------------------------------
# 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_phones):
if updates[i]['tag'] == "Model":
updates[i]['tag'] = "Version"
else:
updates[i]['tag'] = "Other"
#------------------------------------------------------------------------------------------------
sents.append(words)
history={}
history['sentence'] = words
history['i'] = count+1
#history['phrases'] = chunkPhrases
history['relatedTags'] = relatedTags
if len(relations) > 0:
history_list.append((history,relations[0][0],))
else:
history_list.append((history,"None",))
count += 1
return (history_list,sents,expected)
rer_build_history.py 文件源码
python
阅读 15
收藏 0
点赞 0
评论 0
评论列表
文章目录