我试图从句子中提取主要动词,并参考了这个问题,我期望的输出格式如下
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)))
我想我做错了什么,我怎样才能得到期望的输出
回答:
是的,通过这个问题找到了解决方法,但现在唯一的问题是它没有显示根属性
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], ")")