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


Python DependencyGraph.get_by_address(0)["deps"]方法代码示例

本文整理汇总了Python中nltk.parse.dependencygraph.DependencyGraph.get_by_address(0)["deps"]方法的典型用法代码示例。如果您正苦于以下问题:Python DependencyGraph.get_by_address(0)["deps"]方法的具体用法?Python DependencyGraph.get_by_address(0)["deps"]怎么用?Python DependencyGraph.get_by_address(0)["deps"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.parse.dependencygraph.DependencyGraph的用法示例。


在下文中一共展示了DependencyGraph.get_by_address(0)["deps"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_dep_tree

# 需要导入模块: from nltk.parse.dependencygraph import DependencyGraph [as 别名]
# 或者: from nltk.parse.dependencygraph.DependencyGraph import get_by_address(0)["deps"] [as 别名]
def make_dep_tree(sent, deps):
    adj = merge_with(cons, [], *[{x:[m]} for x,m,_ in deps])
    heads = dict([(m,h) for h,m,_ in deps])
    rel = dict([(m,rel) for _,m,rel in deps])
    n = len(sent["x"])
    pos = sent["pos"]
    x = sent["x"]
    nodelist = defaultdict(lambda: {"address": -1, "head": -1, "deps": [], "rel": "", "tag": "", "word": None})
    
    for i in range(1, n):
        node = nodelist[i]
        node["address"] = i
        node["head"] = heads[i]
        node["deps"] = adj[i] if adj.has_key(i) else []
        node["tag"] = pos[i]
        node["word"] = x[i]
        node["rel"] = rel[i]
    
    g = DependencyGraph()
    g.get_by_address(0)["deps"] = adj[0] if adj.has_key(0) else []
    [g.add_node(node) for node in nodelist.values()]
    g.root = nodelist[adj[0][0]]
    
    return g
开发者ID:chegejames,项目名称:NLP,代码行数:26,代码来源:util.py


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