我想要一个解析结果的依赖树。我使用 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)````