本文整理汇总了Python中nltk.Tree.depindex方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.depindex方法的具体用法?Python Tree.depindex怎么用?Python Tree.depindex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.Tree
的用法示例。
在下文中一共展示了Tree.depindex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeConstNode
# 需要导入模块: from nltk import Tree [as 别名]
# 或者: from nltk.Tree import depindex [as 别名]
def makeConstNode(i,node,constDic, rootindeces,tree):
if node["cat"] in constDic:
if node["cat"]=="V":
if node.get("mode","")=="infinitive":
ntree=Tree("(VP (V "+node["t"]+"))")
elif "V" in node["govcats"]:
j,func=node["govcats"]["V"][0]
if func.startswith("para"): # copy governor's const
gov=tree[j]
if "const" not in gov:
makeConstNode(j,gov,constDic, rootindeces,tree)
if unicode(gov["const"])[1]=="V": # governor's const is VP
ntree=Tree("(VP (V "+node["t"]+"))")
else: # governor's const is S
ntree=Tree("(S (V "+node["t"]+"))")
else: # verb depends on verb
ntree=Tree("(VP (V "+node["t"]+"))")
else:
ntree=Tree("(S (V "+node["t"]+"))")
else:
ntree=constDic[node["cat"]].copy(True)
ntree.insert(0,Tree("("+node["cat"]+" "+node["t"]+")"))
else:
if node["children"] or i in rootindeces or node["cat"] in node["govcats"]:
ntree=Tree("("+node["cat"]+"P ("+node["cat"]+" "+node["t"]+"))")
else:
ntree=Tree("("+node["cat"]+" "+node["t"]+")")
ntree.depindex=i
ntree.function=unicode(node["gov"].items()[0][1])
#ntree.t=node["t"]
node["const"]=ntree
for t in list(ntree.subtrees(lambda t: t.height() == 2)):
t.depindex=i
#t.lexid=node["lexid"]
t.lexid=node["id"]
t.t=node["t"]