Search in sources :

Example 1 with DirectedGraph

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;
}
Also used : AnnotationGraph(annis.model.AnnotationGraph) DirectedGraph(edu.uci.ics.jung.graph.DirectedGraph) ArrayList(java.util.ArrayList) AnnisNode(annis.model.AnnisNode) LinkedList(java.util.LinkedList) Comparator(java.util.Comparator)

Aggregations

AnnisNode (annis.model.AnnisNode)1 AnnotationGraph (annis.model.AnnotationGraph)1 DirectedGraph (edu.uci.ics.jung.graph.DirectedGraph)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1