Search in sources :

Example 11 with AnnisNode

use of annis.model.AnnisNode 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 12 with AnnisNode

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

the class ConstituentLayouter method getTokens.

private List<AnnisNode> getTokens(LayoutOptions options) {
    List<AnnisNode> tokens = new ArrayList<AnnisNode>();
    for (AnnisNode n : graph.getVertices()) {
        if (AnnisGraphTools.isTerminal(n, input)) {
            tokens.add(n);
        }
    }
    Collections.sort(tokens, options.getHorizontalOrientation().getComparator());
    return tokens;
}
Also used : AnnisNode(annis.model.AnnisNode) ArrayList(java.util.ArrayList)

Example 13 with AnnisNode

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

the class ConstituentLayouter method fillHeightMap.

private NodeStructureData fillHeightMap(AnnisNode node, int height, NodeStructureData parent) {
    if (AnnisGraphTools.isTerminal(node, input)) {
        NodeStructureData structureData = new NodeStructureData(parent);
        structureData.setChildHeight(0);
        structureData.setTokenArity(1);
        structureData.setLeftCorner(node.getLeftToken());
        structureData.setRightCorner(node.getLeftToken());
        dataMap.put(node, structureData);
        return structureData;
    } else {
        int maxH = 0;
        long leftCorner = Integer.MAX_VALUE;
        long rightCorner = 0;
        boolean hasTokenChildren = false;
        long leftmostImmediate = Integer.MAX_VALUE;
        long rightmostImmediate = 0;
        int tokenArity = 0;
        int arity = 0;
        NodeStructureData structureData = new NodeStructureData(parent);
        for (AnnisNode n : graph.getSuccessors(node)) {
            NodeStructureData childData = fillHeightMap(n, height + 1, structureData);
            maxH = Math.max(childData.getHeight(), maxH);
            leftCorner = Math.min(childData.getLeftCorner(), leftCorner);
            rightCorner = Math.max(childData.getRightCorner(), rightCorner);
            tokenArity += childData.getTokenArity();
            arity += 1;
            if (AnnisGraphTools.isTerminal(n, input)) {
                hasTokenChildren = true;
                leftmostImmediate = Math.min(leftmostImmediate, childData.getLeftCorner());
                rightmostImmediate = Math.max(rightmostImmediate, childData.getLeftCorner());
            }
        }
        structureData.setStep(1);
        structureData.setArity(arity);
        structureData.setTokenArity(tokenArity);
        structureData.setChildHeight(maxH);
        structureData.setLeftCorner(leftCorner);
        structureData.setRightCorner(rightCorner);
        structureData.setContinuous(tokenArity == rightCorner - leftCorner + 1);
        if (hasTokenChildren) {
            structureData.setLeftmostImmediate(leftmostImmediate);
            structureData.setRightmostImmediate(rightmostImmediate);
        }
        dataMap.put(node, structureData);
        return structureData;
    }
}
Also used : AnnisNode(annis.model.AnnisNode)

Example 14 with AnnisNode

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

the class TestAnnisResultImpl method newToken.

// /// private helper
private AnnisNode newToken(long id, String text, long tokenIndex) {
    AnnisNode n = new AnnisNode(id);
    n.setSpannedText(text);
    n.setTokenIndex(tokenIndex);
    n.setLeft(LEFT);
    n.setRight(RIGHT);
    return n;
}
Also used : AnnisNode(annis.model.AnnisNode)

Example 15 with AnnisNode

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

the class AomAnnotateSqlGeneratorTest method shouldMapNodeWithoutToken.

@Test
public void shouldMapNodeWithoutToken() throws SQLException {
    // given
    stubNodeResultSet();
    given(resultSet.wasNull()).willReturn(false);
    // when
    AnnisNode node = generator.mapNode(resultSet, tableAccessStrategy, null);
    // then
    assertThat(node.isToken(), is(true));
}
Also used : AnnisNode(annis.model.AnnisNode) Test(org.junit.Test)

Aggregations

AnnisNode (annis.model.AnnisNode)38 Annotation (annis.model.Annotation)10 Edge (annis.model.Edge)9 LinkedList (java.util.LinkedList)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Map (java.util.Map)5 AnnotationGraph (annis.model.AnnotationGraph)4 AnnisResult (annis.service.ifaces.AnnisResult)4 DetectHoles (annis.visualizers.iframe.partitur.DetectHoles)2 DocumentNameMapRow (annis.dao.DocumentNameMapRow)1 MatchedNodeColors (annis.libgui.MatchedNodeColors)1 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 AnnisToken (annis.service.ifaces.AnnisToken)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 ArrayCorpusPathExtractor (annis.sqlgen.ArrayCorpusPathExtractor)1 CorpusPathExtractor (annis.sqlgen.CorpusPathExtractor)1