如何在 Stanford NLP 解析器中获取包含 "root" 修饰符依赖项的边?

How can I get the edges containing the "root" modifier dependency in the Stanford NLP parser?

我已经为需要文本输入的场景创建了依赖关系图。

SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);

我使用以下代码成功获取了 "num" 修饰符依赖项:

List<SemanticGraphEdge> edgesContainingNumModifierDependency = dependencies.findAllRelns(GrammaticalRelation.valueOf("num"));

但是,我想找到属于 "root" 的边,因此,下面的

List<SemanticGraphEdge> edgesContainingRootModifierDependency = dependencies.findAllRelns(GrammaticalRelation.valueOf("root"));

好像不行。

谁能解释一下为什么?我怎样才能获得 root 的优势?

我们实际上并没有在词根和虚拟 ROOT 节点之间存储 SemanticGraphEdge。 (您可以看到在 public 面向方法 like toList 中手动添加了依赖项)。

来自SemanticGraph documentation

The root is not at present represented as a vertex in the graph. At present you need to get a root/roots from the separate roots variable and to know about it. This should maybe be changed, because otherwise, doing things like simply getting the set of nodes or edges from the graph doesn't give you root nodes or edges.

不过,SemanticGraph#getFirstRoot

你或许可以得到你想要的东西