首页 > 解决方案 > 使用斯坦福依赖解析器进行依赖解析

问题描述

我试图在一个句子中提取主要动词,我跟着这个问题,我期待这种格式的输出

nsubj(swim-4, Parrots-1)
aux(swim-4, do-2)
neg(swim-4, not-3)
root(ROOT-0, swim-4)

但我以这种方式得到输出

[<DependencyGraph with 94 nodes>]

我做了以下

  dependencyParser = stanford.StanfordDependencyParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
  print (list(dependencyParser.raw_parse(noiseLessInput)))

我想我做错了什么,我怎样才能达到想要的输出

标签: machine-learningnlpstanford-nlpdependency-parsing

解决方案


是的,通过这个问题找到了如何做到这一点,但它没有显示根属性,这是现在唯一的问题

  dependencyParser = stanford.StanfordDependencyParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
result = dependencyParser.raw_parse(noiseLessInput)
dep = result.__next__()
for triple in dep.triples():
 print(triple[1], "(", triple[0][0], ", ", triple[2][0], ")")

推荐阅读