Search in sources :

Example 1 with Edge

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

the class AnnisGraphTools method extractGraph.

private DirectedGraph<AnnisNode, Edge> extractGraph(AnnotationGraph ag, AnnisNode n, String terminalNamespace, String terminalName) {
    DirectedGraph<AnnisNode, Edge> graph = new DirectedSparseGraph<AnnisNode, Edge>();
    copyNode(graph, n, terminalNamespace, terminalName);
    for (Edge e : ag.getEdges()) {
        if (hasEdgeSubtype(e, getSecEdgeSubType()) && graph.containsVertex(e.getDestination()) && graph.containsVertex(e.getSource())) {
            graph.addEdge(e, e.getSource(), e.getDestination());
        }
    }
    return graph;
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph)

Example 2 with Edge

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

the class AnnisGraphTools method copyNode.

private boolean copyNode(DirectedGraph<AnnisNode, Edge> graph, AnnisNode n, String terminalNamespace, String terminalName) {
    boolean addToGraph = AnnisGraphTools.isTerminal(n, input);
    if (!addToGraph) {
        for (Edge e : n.getOutgoingEdges()) {
            if (includeEdge(e) && copyNode(graph, e.getDestination(), terminalNamespace, terminalName)) {
                addToGraph |= true;
                graph.addEdge(e, n, e.getDestination());
            }
        }
    }
    if (addToGraph) {
        graph.addVertex(n);
    }
    return addToGraph;
}
Also used : Edge(annis.model.Edge)

Example 3 with Edge

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

the class ConstituentLayouter method calculateNodePosition.

private Point2D calculateNodePosition(final AnnisNode current, TreeLayoutData treeLayout, LayoutOptions options) {
    double y = treeLayout.getYPosition(current);
    List<Double> childPositions = new ArrayList<Double>();
    for (Edge e : getOutgoingEdges(current)) {
        AnnisNode child = graph.getOpposite(current, e);
        Point2D childPos;
        if (AnnisGraphTools.isTerminal(child, input)) {
            childPos = addTerminalNode(child, treeLayout);
        } else {
            childPos = calculateNodePosition(child, treeLayout, options);
        }
        childPositions.add(childPos.getX());
        NodeStructureData childData = dataMap.get(child);
        if (childData.canHaveVerticalOverlap()) {
            treeLayout.getNodeList().addVerticalEdgePosition(childData, childPos);
        }
        treeLayout.addEdge(new Point2D.Double(childPos.getX(), y), childPos);
        GraphicsItem label = backend.makeLabel(labeler.getLabel(e, input), new Point2D.Double(childPos.getX(), y + treeLayout.orientation.value * styler.getHeightStep() * 0.5), styler.getFont(e), styler.getTextBrush(e), Alignment.CENTERED, styler.getShape(e, input));
        label.setZValue(10);
        label.setParentItem(treeLayout.parentItem);
    }
    double xCenter = treeLayout.getNodeList().findBestPosition(dataMap.get(current), Collections.min(childPositions), Collections.max(childPositions));
    GraphicsItem label = backend.makeLabel(labeler.getLabel(current, input), new Point2D.Double(xCenter, y), styler.getFont(current, input), styler.getTextBrush(current, input), Alignment.CENTERED, styler.getShape(current, input));
    treeLayout.addNodeRect(current, label.getBounds());
    label.setZValue(11);
    label.setParentItem(treeLayout.getParentItem());
    treeLayout.addEdge(new Point2D.Double(Collections.min(childPositions), y), new Point2D.Double(Collections.max(childPositions), y));
    return treeLayout.getDominanceConnector(current, label.getBounds());
}
Also used : Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge)

Example 4 with Edge

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

the class LegacyGraphConverterTest method checkAnnisNodeEqual.

private void checkAnnisNodeEqual(AnnisNode n1, AnnisNode n2) {
    checkAnnotationSetEqual(n1.getNodeAnnotations(), n2.getNodeAnnotations());
    checkAnnotationSetEqual(n1.getEdgeAnnotations(), n2.getEdgeAnnotations());
    assertEquals("corpus number must be equal", n1.getCorpus(), n2.getCorpus());
    assertEquals("node ID must be equal", n1.getId(), n2.getId());
    assertEquals("left must be equal", n1.getLeft(), n2.getLeft());
    assertEquals("left token must be equal", n1.getLeftToken(), n2.getLeftToken());
    assertEquals("matched node in query must be equal", n1.getMatchedNodeInQuery(), n2.getMatchedNodeInQuery());
    assertEquals("node name must be equal", n1.getName(), n2.getName());
    assertEquals("node namespace must be equal", n1.getNamespace(), n2.getNamespace());
    assertEquals("right must be equal", n1.getRight(), n2.getRight());
    assertEquals("right token must be equal", n1.getRightToken(), n2.getRightToken());
    assertEquals("spanned text of node must be equal", n1.getSpannedText(), n2.getSpannedText());
    assertEquals("text ID of node must be equal", n1.getTextId(), n2.getTextId());
    assertEquals("token index must be equal", n1.getTokenIndex(), n2.getTokenIndex());
    Set<Edge> out1 = n1.getOutgoingEdges();
    Set<Edge> out2 = n2.getOutgoingEdges();
    assertEquals("number of outgoing edges must be equal for [" + n1.toString() + "]", out1.size(), out2.size());
    for (Edge e1 : out1) {
        assertTrue("edge [" + e1 + "] must be contained in outgoing edges " + out2.toString(), out2.contains(e1));
        for (Edge e2 : out2) {
            if (e1.getPre() == e2.getPre()) {
                checkAnnisEdgeEqual(e1, e2);
                break;
            }
        }
    }
    Set<Edge> in1 = n1.getIncomingEdges();
    Set<Edge> in2 = n2.getIncomingEdges();
    assertEquals("number of incoming edges must be the same for node " + n1.getName(), in1.size(), in2.size());
    for (Edge e1 : in1) {
        assertTrue("edge " + e1.getPre() + " must be included", in2.contains(e1));
        for (Edge e2 : in2) {
            if (e1.getPre() == e2.getPre() && e1.getComponentID() == e2.getComponentID()) {
                checkAnnisEdgeEqual(e1, e2);
                break;
            }
        }
    }
}
Also used : Edge(annis.model.Edge)

Example 5 with Edge

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

the class AomAnnotateSqlGeneratorTest method shouldMapEdge.

@Test
public void shouldMapEdge() throws SQLException {
    // given
    stubEdgeResultSet();
    // when
    Edge actual = generator.mapEdge(resultSet, tableAccessStrategy);
    // then
    Edge expected = createDefaultEdge();
    assertThat(actual, is(expected));
}
Also used : Edge(annis.model.Edge) Test(org.junit.Test)

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