我正在尝试从Malt ConcurrentMaltParserModel中提取树依赖项。我遍布边缘,如:
SortedSet<ConcurrentDependencyEdge> edges = graph.getEdges();
for (ConcurrentDependencyEdge e : edges) {
//here I would need to extract the dependency type
}
我认为我可以像StanfordParser一样提取依赖类型,但不幸的是我无法弄清楚如何做到这一点。
答案 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);
}