麦芽解析器,迭代java中的解析树

时间:2015-03-23 15:17:52

标签: parsing nlp stanford-nlp

我正在尝试从Malt ConcurrentMaltParserModel中提取树依赖项。我遍布边缘,如:

SortedSet<ConcurrentDependencyEdge> edges = graph.getEdges();
for (ConcurrentDependencyEdge e : edges) {
      //here I would need to extract the dependency type
}

我认为我可以像StanfordParser一样提取依赖类型,但不幸的是我无法弄清楚如何做到这一点。

1 个答案:

答案 0 :(得分:1)

首先获取SemanticGraph个对象(例如,通过检索CoreNLP管道中的BasicDependenciesAnnotation的值,或直接使用Stanford Parser进行解析)。如有必要,我可以更详细地说明这一点。

SemanticGraph提供了一个简单的边迭代,用于处理独立的图边。 (请参阅SemanticGraphEdge课程。另请注意,SemanticGraphEdge.getRelation会返回GrammaticalRelation个实例。)

SemanticGraph sg = ....
for (SemanticGraphEdge edge : sg.getEdgesIterable()) {
  int headIndex = edge.getGovernor().index();
  int depIndex = edge.getDependent().index();
  String label = edge.getRelation().getShortName();

  System.out.printf("%d %d %s%n", headIndex, depIndex, label);
}
相关问题