Reputation: 855
I am trying to extract the tree dependencies from a Malt ConcurrentMaltParserModel. I iterate over the edges like:
SortedSet<ConcurrentDependencyEdge> edges = graph.getEdges();
for (ConcurrentDependencyEdge e : edges) {
//here I would need to extract the dependency type
}
I thought I could extract the dependency type in a similar way as StanfordParser, but unfortunately I cant figure out how to do that.
Upvotes: 0
Views: 156
Reputation: 25592
First obtain a SemanticGraph
object (e.g. by retrieving the value of a BasicDependenciesAnnotation
in the CoreNLP pipeline, or by parsing directly with Stanford Parser). I can elaborate on this more if necessary.
The SemanticGraph
provides a simple edge iterable for processing independent graph edges. (See the SemanticGraphEdge
class. Also, note that SemanticGraphEdge.getRelation
returns a GrammaticalRelation
instance.)
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);
}
Upvotes: 1