本文整理汇总了Python中tree.Tree.new_from_conll方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.new_from_conll方法的具体用法?Python Tree.new_from_conll怎么用?Python Tree.new_from_conll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.new_from_conll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import new_from_conll [as 别名]
def __init__(self,sent=None,syn=False):
if sent!=None:
self.tree=Tree.new_from_conll(sent,syn)
self.queue=self.tree.tokens[:]
else:
self.tree=None
self.queue=[]
self.stack=[]
self.queue=[Token(-1,u"ROOT",lemma=u"ROOT",pos=u"ROOT",feat=u"ROOT")]
self.queue+=self.tree.tokens[:]
self.score=0.0
self.transitions=[]
self.features=defaultdict(lambda:0.0)
self.prev_state=None #The state from which this one was created, if any
self.wrong_transitions=0 # number of wrong transitions, if 0 then same as gold
示例2: train
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import new_from_conll [as 别名]
def train(self,inp,progress=0.0,quiet=False):
"""If inp is string, it will be interpreted as a file, otherwise as open file reading unicode"""
total=0
failed=0
non=0
for sent in read_conll(inp):
total+=1
gs_tree=Tree.new_from_conll(conll=sent,syn=True)
non_projs=gs_tree.is_nonprojective()
if len(non_projs)>0:
gs_tree.define_projective_order(non_projs)
non+=1
try:
gs_transitions=self.extract_transitions(gs_tree,sent)
self.train_one_sent(gs_transitions,sent,progress) # sent is a conll sentence
except ValueError:
traceback.print_exc()
failed+=1
if not quiet:
print u"Failed to parse:",failed
print u"Total number of trees:",total
print u"Non-projectives:",non
print u"Progress:",progress