【问题标题】:How to draw the dependency tree from the CoreNLPClient parsing result?如何从 CoreNLPClient 解析结果中绘制依赖树?
【发布时间】:2020-07-12 07:40:22
【问题描述】:

我想要一个解析结果的依赖树。我使用 stanford core nlp 的 github repo 上给出的代码进行了解析

我得到的结果如下。[jupyter notebook 结果截图][1]

我已经看到其他提到 graphviz 和 todoformat() 的答案,但是这些方法需要语义图格式输入(据我所知,todoformat 确实如此)。我已经能够将解析结果转换为以下格式,但它是一个字符串列表。 [结果的新格式][2] 正如我看到的其他结果格式一样。我该怎么做才能获得依赖树图? 我得到的结果是否以适用于 todoformat 的形式进行更改? 我是新来的。我将衷心感谢您的帮助。 [1]:https://i.stack.imgur.com/qma9n.png [2]:https://i.stack.imgur.com/Xjhwh.png

代码:

with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner','parse','depparse','coref'], timeout=60000, memory='16G') as client:
    # submit the request to the server
    ann = client.annotate(text)
    sentence = ann.sentence[0]
    print('dependency parse of first sentence')
    dependency_parse = sentence.basicDependencies
    print(dependency_parse)````


【问题讨论】:

    标签: nlp stanford-nlp stanza


    【解决方案1】:
    from stanza.server import CoreNLPClient
    client = CoreNLPClient(
            annotators=['tokenize','ssplit','pos','lemma','ner', 'parse', 'openie','depparse','coref'],
            timeout=30000,
            memory='16G')
    
    test ="A man and a woman came into the store."
    matches = client.tregex(text, 'S')
    print(matches['sentences'][0]['0']['match'])
    

    【讨论】:

      猜你喜欢
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 2021-08-04
      • 2021-02-19
      相关资源
      最近更新 更多