Search in sources :

Example 11 with Edge

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

the class ConstituentLayouter method createLayout.

public T createLayout(LayoutOptions options) {
    TreeLayoutData treeLayout = new TreeLayoutData(options.getOrientation(), computeTokenPositions(options, 5));
    treeLayout.setParentItem(backend.group());
    if (options.getOrientation() == VerticalOrientation.TOP_ROOT) {
        treeLayout.setNtStart(computeTreeHeight());
        treeLayout.setBaseline(treeLayout.getNtStart() + styler.getFont(TOKEN_NODE, input).getLineHeight());
    } else {
        treeLayout.setBaseline(styler.getFont(TOKEN_NODE, input).getLineHeight());
        treeLayout.setNtStart(styler.getFont(TOKEN_NODE, input).getLineHeight());
    }
    calculateNodePosition(root, treeLayout, options);
    Edge e = getOutgoingEdges(root).get(0);
    GraphicsItem edges = backend.makeLines(treeLayout.getLines(), styler.getEdgeColor(e, input), styler.getStroke(e, input));
    edges.setZValue(-4);
    edges.setParentItem(treeLayout.getParentItem());
    addSecEdges(treeLayout, options);
    return treeLayout.getParentItem();
}
Also used : Edge(annis.model.Edge)

Example 12 with Edge

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

the class AomAnnotateSqlGeneratorTest method shouldMapEdgeWithRoot.

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

Example 13 with Edge

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

the class AomAnnotateSqlGeneratorTest method createDefaultEdge.

private Edge createDefaultEdge() {
    Edge expected = new Edge();
    expected.setPre(PRE);
    expected.setEdgeType(EDGETYPE);
    expected.setNamespace(EDGE_NAMESPACE);
    expected.setName(EDGE_NAME);
    expected.setSource(new AnnisNode(PARENT));
    expected.setDestination(new AnnisNode(NODE_REF));
    return expected;
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge)

Example 14 with Edge

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

the class AomAnnotateExtractor method mapEdge.

public Edge mapEdge(ResultSet resultSet, TableAccessStrategy tableAccessStrategy) throws SQLException {
    Edge edge = new Edge();
    edge.setPre(longValue(resultSet, RANK_TABLE, "pre", tableAccessStrategy));
    edge.setComponentID(longValue(resultSet, RANK_TABLE, "component_id", tableAccessStrategy));
    edge.setEdgeType(EdgeType.parseEdgeType(stringValue(resultSet, RANK_TABLE, "edge_type", tableAccessStrategy)));
    edge.setNamespace(stringValue(resultSet, COMPONENT_TABLE, "namespace", tableAccessStrategy));
    edge.setName(stringValue(resultSet, COMPONENT_TABLE, "name", tableAccessStrategy));
    edge.setDestination(new AnnisNode(longValue(resultSet, RANK_TABLE, "node_ref", tableAccessStrategy)));
    edge.setComponentID(longValue(resultSet, COMPONENT_TABLE, "id", tableAccessStrategy));
    edge.setId(longValue(resultSet, RANK_TABLE, "id", tableAccessStrategy));
    // create nodes for src with rank value (parent) as id.
    // this must later be fixed by AnnotationGraphDaoHelper.fixSourceNodeIds().
    // this is simpler than chaining the edgeByPre map in AnnisResultSetBuilder
    // and making the EdgeRowMapper thread-safe.
    // FIXME: use custum mapRow(resultSet, edgeByPre) function, throw Exception here
    // also, no need to implement Spring RowMapper
    long parent = longValue(resultSet, RANK_TABLE, "parent", tableAccessStrategy);
    if (!resultSet.wasNull())
        edge.setSource(new AnnisNode(parent));
    return edge;
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge)

Example 15 with Edge

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

the class AomAnnotateExtractor method createMissingSpanningRelations.

private void createMissingSpanningRelations(AnnotationGraph graph, Map<Long, ComponentEntry> allSpans, Map<Long, AnnisNode> nodeById) {
    for (Map.Entry<Long, ComponentEntry> spanEntry : allSpans.entrySet()) {
        AnnisNode span = nodeById.get(spanEntry.getKey());
        // Check all covered token if there is already a coverage edge between the span
        // and the token. If at least one edge already exists, it must have been
        // a discontinuos span and we don't need to add any missing edges.
        boolean anyTokenConnected = false;
        for (long i = span.getLeftToken(); i <= span.getRightToken() && !anyTokenConnected; i++) {
            AnnisNode token = graph.getToken(i);
            // the span border might be behind the result set, so ignore this entries
            if (token != null) {
                for (Edge e : token.getIncomingEdges()) {
                    if (e.getSource() == span && e.getEdgeType() == EdgeType.COVERAGE) {
                        anyTokenConnected = true;
                        break;
                    }
                }
            }
        }
        if (!anyTokenConnected) {
            long pre = 1;
            for (long i = span.getLeftToken(); i <= span.getRightToken(); i++) {
                AnnisNode tok = graph.getToken(i);
                if (tok != null) {
                    Edge edge = new Edge();
                    ComponentEntry component = spanEntry.getValue();
                    edge.setPre(pre++);
                    edge.setComponentID(component.getId());
                    edge.setEdgeType(EdgeType.COVERAGE);
                    edge.setNamespace(component.getNamespace());
                    edge.setName(null);
                    edge.setDestination(tok);
                    edge.setSource(span);
                    graph.addEdge(edge);
                    span.addOutgoingEdge(edge);
                    tok.addIncomingEdge(edge);
                }
            }
        }
    }
// end for each node
}
Also used : AnnisNode(annis.model.AnnisNode) HashMap(java.util.HashMap) Map(java.util.Map) 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