Stanford OpenIE:如何输出依赖路径而不是纯文本模式?

Stanford OpenIE: How to output dependency path instead of plain text patterns?

我正在查看 Java 源代码,想知道是否可以轻松修改系统,使每个三元组的谓词部分成为两个实体之间的依赖路径,而不是表面形式。

由于自然逻辑模块在依赖树上运行,我想应该对这个需求进行简单的调整。

我跟踪 edu.stanford.nlp.naturalli/OpenIE.java 中的代码到:

// Get the extractions
boolean empty = true;
synchronized (OUTPUT) {
  for (CoreMap sentence : ann.get(CoreAnnotations.SentencesAnnotation.class)) {
    for (RelationTriple extraction : sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class)) {
      // Print the extractions
      OUTPUT.println(tripleToString(extraction, docid, sentence));
      empty = false;
    }
  }
}

请指点我执行以下步骤:

sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class)

谢谢!

每个关系三元组实际上确实存储了生成它的依赖结构。看看asDependencyTree() function in RelationTriple

请注意,这棵树不一定是原始句子的子树——例如,它可能是一个主题被四处移动以产生关系三元组。如果您正在寻找原始句子中的依赖路径,您可以通过它们的 IndexAnnotation 查找标记并从中计算依赖路径。