Search in sources :

Example 6 with Edge

use of annis.model.Edge in project ANNIS by korpling.

the class TigerTreeVisualizer method writeOutput.

@Override
public void writeOutput(VisualizerInput input, OutputStream outstream) {
    AnnisResult result = input.getResult();
    graphtools = new AnnisGraphTools(input);
    List<AbstractImageGraphicsItem> layouts = new LinkedList<AbstractImageGraphicsItem>();
    double width = 0;
    double maxheight = 0;
    for (DirectedGraph<AnnisNode, Edge> g : graphtools.getSyntaxGraphs()) {
        if (g.getEdgeCount() > 0 && g.getVertexCount() > 0) {
            ConstituentLayouter<AbstractImageGraphicsItem> cl = new ConstituentLayouter<AbstractImageGraphicsItem>(g, getBackend(), labeler, styler, input, graphtools);
            AbstractImageGraphicsItem item = cl.createLayout(new LayoutOptions(VerticalOrientation.TOP_ROOT, AnnisGraphTools.detectLayoutDirection(result.getGraph())));
            Rectangle2D treeSize = item.getBounds();
            maxheight = Math.max(maxheight, treeSize.getHeight());
            width += treeSize.getWidth();
            layouts.add(item);
        }
    }
    BufferedImage image;
    if (width == 0 || maxheight == 0) {
        Notification.show("Can't generate tree visualization.", Notification.Type.WARNING_MESSAGE);
        image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    } else {
        image = new BufferedImage((int) (width + (layouts.size() - 1) * TREE_DISTANCE + 2 * SIDE_MARGIN), (int) (maxheight + 2 * TOP_MARGIN), BufferedImage.TYPE_INT_ARGB);
        Graphics2D canvas = createCanvas(image);
        double xOffset = SIDE_MARGIN;
        for (AbstractImageGraphicsItem item : layouts) {
            AffineTransform t = canvas.getTransform();
            Rectangle2D bounds = item.getBounds();
            canvas.translate(xOffset, TOP_MARGIN + maxheight - bounds.getHeight());
            renderTree(item, canvas);
            xOffset += bounds.getWidth() + TREE_DISTANCE;
            canvas.setTransform(t);
        }
    }
    try {
        ImageIO.write(image, "png", outstream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractImageGraphicsItem(annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem) Rectangle2D(java.awt.geom.Rectangle2D) AnnisResult(annis.service.ifaces.AnnisResult) IOException(java.io.IOException) LinkedList(java.util.LinkedList) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) AnnisNode(annis.model.AnnisNode) AffineTransform(java.awt.geom.AffineTransform) Edge(annis.model.Edge)

Example 7 with Edge

use of annis.model.Edge in project ANNIS by korpling.

the class LegacyGraphConverter method addRelation.

private static void addRelation(Class<? extends SRelation> clazz, String type, Collection<SAnnotation> annotations, SNode source, SNode target, Set<SLayer> relLayers, long pre, long componentID, Map<SNode, AnnisNode> allNodes, AnnotationGraph annoGraph) {
    Edge aEdge = new Edge();
    aEdge.setSource(allNodes.get(source));
    aEdge.setDestination(allNodes.get(target));
    aEdge.setEdgeType(EdgeType.UNKNOWN);
    aEdge.setPre(pre);
    aEdge.setComponentID(componentID);
    if (!relLayers.isEmpty()) {
        aEdge.setNamespace(relLayers.iterator().next().getName());
    }
    aEdge.setName(type);
    if (SDominanceRelation.class.isAssignableFrom(clazz)) {
        aEdge.setEdgeType(EdgeType.DOMINANCE);
    } else if (SPointingRelation.class.isAssignableFrom(clazz)) {
        aEdge.setEdgeType(EdgeType.POINTING_RELATION);
    } else if (SSpanningRelation.class.isAssignableFrom(clazz)) {
        aEdge.setEdgeType(EdgeType.COVERAGE);
    }
    for (SAnnotation sAnno : annotations) {
        aEdge.addAnnotation(new Annotation(sAnno.getNamespace(), sAnno.getName(), sAnno.getValue_STEXT()));
    }
    annoGraph.addEdge(aEdge);
    aEdge.getDestination().addIncomingEdge(aEdge);
    if (aEdge.getSource() != null) {
        aEdge.getSource().addOutgoingEdge(aEdge);
    }
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SAnnotation(org.corpus_tools.salt.core.SAnnotation) Edge(annis.model.Edge) Annotation(annis.model.Annotation) SAnnotation(org.corpus_tools.salt.core.SAnnotation)

Example 8 with Edge

use of annis.model.Edge in project ANNIS by korpling.

the class DotGraphVisualizer method internalCreateDot.

private void internalCreateDot() {
    w("digraph G {\n");
    w("\tnode [shape=box];\n");
    // node definitions
    List<AnnisNode> token = new LinkedList<AnnisNode>();
    for (AnnisNode n : input.getResult().getGraph().getNodes()) {
        if (n.isToken()) {
            token.add(n);
        } else {
            if (testNode(n)) {
                writeNode(n);
            }
        }
    }
    // Token are in a subgraph
    w("\t{\n" + "\trank=max;\n");
    for (AnnisNode tok : token) {
        w("\t");
        writeNode(tok);
    }
    writeInvisibleTokenEdges(token);
    w("\t}\n");
    for (Edge e : input.getResult().getGraph().getEdges()) {
        if (e != null && testEdge(e)) {
            writeEdge(e);
        }
    }
    w("}");
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge) LinkedList(java.util.LinkedList)

Example 9 with Edge

use of annis.model.Edge in project ANNIS by korpling.

the class ConstituentLayouter method addSecEdges.

private void addSecEdges(TreeLayoutData treeLayout, LayoutOptions options) {
    for (Edge e : graph.getEdges()) {
        if (!GRAPH_TOOLS.hasEdgeSubtype(e, GRAPH_TOOLS.getSecEdgeSubType())) {
            continue;
        }
        Rectangle2D sourceRect = treeLayout.getRect(e.getSource());
        Rectangle2D targetRect = treeLayout.getRect(e.getDestination());
        CubicCurve2D curveData = secedgeCurve(treeLayout.getOrientation(), sourceRect, targetRect);
        T secedgeElem = backend.cubicCurve(curveData, styler.getStroke(e, input), styler.getEdgeColor(e, input));
        secedgeElem.setZValue(-2);
        T arrowElem = backend.arrow(curveData.getP1(), curveData.getCtrlP1(), new Rectangle2D.Double(0, 0, 8, 8), styler.getEdgeColor(e, input));
        arrowElem.setZValue(-1);
        arrowElem.setParentItem(secedgeElem);
        Point2D labelPos = evaluate(curveData, 0.8);
        T label = backend.makeLabel(labeler.getLabel(e, input), labelPos, styler.getFont(e), styler.getTextBrush(e), Alignment.CENTERED, styler.getShape(e, input));
        label.setParentItem(secedgeElem);
        secedgeElem.setParentItem(treeLayout.getParentItem());
    }
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) CubicCurve2D(java.awt.geom.CubicCurve2D) Edge(annis.model.Edge)

Example 10 with Edge

use of annis.model.Edge in project ANNIS by korpling.

the class ConstituentLayouter method getOutgoingEdges.

private List<Edge> getOutgoingEdges(final AnnisNode current) {
    List<Edge> outEdges = new ArrayList<Edge>();
    for (Edge e : graph.getOutEdges(current)) {
        if (GRAPH_TOOLS.hasEdgeSubtype(e, GRAPH_TOOLS.getPrimEdgeSubType())) {
            outEdges.add(e);
        }
    }
    Collections.sort(outEdges, new Comparator<Edge>() {

        @Override
        public int compare(Edge o1, Edge o2) {
            int h1 = dataMap.get(graph.getOpposite(current, o1)).getHeight();
            int h2 = dataMap.get(graph.getOpposite(current, o2)).getHeight();
            return h1 - h2;
        }
    });
    return outEdges;
}
Also used : ArrayList(java.util.ArrayList) Edge(annis.model.Edge)

Aggregations

Edge (annis.model.Edge)17 AnnisNode (annis.model.AnnisNode)9 LinkedList (java.util.LinkedList)3 Annotation (annis.model.Annotation)2 Point2D (java.awt.geom.Point2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 DocumentNameMapRow (annis.dao.DocumentNameMapRow)1 AnnotationGraph (annis.model.AnnotationGraph)1 AnnisResult (annis.service.ifaces.AnnisResult)1 AbstractImageGraphicsItem (annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem)1 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 CubicCurve2D (java.awt.geom.CubicCurve2D)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1