def combineparse2sent(sent, parse):
""" Combine constitent parse into sent
"""
parse = parse.split()
tokenlist = [token.word for token in sent.tokenlist]
parselist, tidx = [""] * len(tokenlist), 0
while parse:
item = parse.pop(0)
parselist[tidx] += (" " + item)
partialparse = parselist[tidx].replace(' ', '')
word = tokenlist[tidx].replace(' ', '')
# print word, partialparse
if (word + ')') in partialparse:
tidx += 1
# Attach to sent
for (tidx, token) in enumerate(sent.tokenlist):
item = parselist[tidx]
sent.tokenlist[tidx].partialparse = item
return sent
评论列表
文章目录