use of edu.uci.ics.jung.graph.DirectedGraph in project ANNIS by korpling.
the class AnnisGraphTools method getSyntaxGraphs.
public List<DirectedGraph<AnnisNode, Edge>> getSyntaxGraphs() {
AnnotationGraph ag = input.getResult().getGraph();
String namespace = input.getMappings().getProperty("node_ns", input.getNamespace());
String terminalName = input.getMappings().getProperty(TigerTreeVisualizer.TERMINAL_NAME_KEY);
String terminalNamespace = input.getMappings().getProperty(TigerTreeVisualizer.TERMINAL_NS_KEY);
List<DirectedGraph<AnnisNode, Edge>> resultGraphs = new ArrayList<>();
List<AnnisNode> rootNodes = new LinkedList<>();
for (AnnisNode n : ag.getNodes()) {
if (isRootNode(n, namespace)) {
rootNodes.add(n);
}
}
// sort root nodes according to their left-most covered token
HorizontalOrientation orientation = detectLayoutDirection(ag);
if (orientation == HorizontalOrientation.LEFT_TO_RIGHT) {
Collections.sort(rootNodes, new Comparator<AnnisNode>() {
@Override
public int compare(AnnisNode o1, AnnisNode o2) {
return Long.compare(o1.getLeftToken(), o2.getLeftToken());
}
});
} else if (orientation == HorizontalOrientation.RIGHT_TO_LEFT) {
Collections.sort(rootNodes, new Comparator<AnnisNode>() {
@Override
public int compare(AnnisNode o1, AnnisNode o2) {
return Long.compare(o2.getLeftToken(), o1.getLeftToken());
}
});
}
for (AnnisNode r : rootNodes) {
resultGraphs.add(extractGraph(ag, r, terminalNamespace, terminalName));
}
return resultGraphs;
}
Aggregations