当前位置: 首页>>代码示例>>Python>>正文


Python Tree.new_from_conll方法代码示例

本文整理汇总了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
开发者ID:jmnybl,项目名称:Turku-Dependency-Parser,代码行数:17,代码来源:tparser.py

示例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
开发者ID:jmnybl,项目名称:Turku-Dependency-Parser,代码行数:25,代码来源:tparser.py


注:本文中的tree.Tree.new_from_conll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。