Search in sources :

Example 26 with AnnisNode

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

the class ConstituentLayouter method adaptNodeHeights.

public void adaptNodeHeights() {
    /*
		Adapts node heights to prevent overlapping horizontal edges with discontinuous nodes.

		To avoid clashes, the `step` attribute of nodes is increased. Moved-up nodes will be
		rechecked at the next level.

		Algorithm outline
		=================
		1. Retrieve all nonterminals from `tree`
		2. If all nonterminals are continuous, stop here
		3. Set `level` to 1
		4. Get all nonterminals `level_nodes` whose height equals `level`
		5. Compare each node `a` from `level_nodes` to each other node `b`

		 * if the terminals of one node are completely inside another node, move up
   		   the enclosing node
		 * if the left/rightmost direct terminal children (not corners!) of `a` and `b` overlap,
   		   move up the node with less direct children

		6. Increase `level`
		7. Continue with 4 until there is a level for which no nodes are found.
		 */
    List<NodeStructureData> allNonterminals = new ArrayList<NodeStructureData>();
    boolean allContinuous = true;
    for (AnnisNode n : this.graph.getVertices()) {
        if (!AnnisGraphTools.isTerminal(n, input)) {
            allNonterminals.add(dataMap.get(n));
            allContinuous &= dataMap.get(n).isContinuous();
        }
    }
    if (allContinuous) {
        return;
    }
    for (int level = 1; ; level++) {
        List<NodeStructureData> levelNodes = new ArrayList<NodeStructureData>();
        for (NodeStructureData n : allNonterminals) {
            if (n.getHeight() == level) {
                levelNodes.add(n);
            }
        }
        if (levelNodes.isEmpty()) {
            return;
        }
        Collections.sort(levelNodes, new Comparator<NodeStructureData>() {

            @Override
            public int compare(NodeStructureData o1, NodeStructureData o2) {
                int o1k = o1.isContinuous() ? 1 : 0;
                int o2k = o2.isContinuous() ? 1 : 0;
                return o1k - o2k;
            }
        });
        int d = findFirstContinuous(levelNodes);
        /* d is either the index of the first continuous node,
		     * or levelNodes.size(), if there are only discontinuous
		     * nodes.
		     * In any case, each combination of 2 nodes with at least
		     * one discontinuous node is checked exactly once. 
		     */
        for (int i = 0; i < d; i++) {
            NodeStructureData iNode = levelNodes.get(i);
            for (int j = i + 1; j < levelNodes.size(); j++) {
                NodeStructureData jNode = levelNodes.get(j);
                if (iNode.getHeight() != jNode.getHeight()) {
                    continue;
                }
                if (jNode.isContinuous()) {
                    if (iNode.encloses(jNode)) {
                        iNode.increaseStep();
                        break;
                    }
                } else {
                    bubbleNode(iNode, jNode);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AnnisNode(annis.model.AnnisNode)

Example 27 with AnnisNode

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

the class ConstituentLayouter method computeTokenPositions.

private Map<AnnisNode, Double> computeTokenPositions(LayoutOptions options, int padding) {
    Map<AnnisNode, Double> positions = new HashMap<AnnisNode, Double>();
    double x = 0;
    boolean first = true;
    List<AnnisNode> leaves = getTokens(options);
    Preconditions.checkState(leaves.isEmpty() == false, "No terminal nodes found");
    GraphicsBackend.Font tokenFont = styler.getFont(leaves.get(0), input);
    for (AnnisNode token : leaves) {
        if (first) {
            first = false;
        } else {
            x += styler.getTokenSpacing();
        }
        positions.put(token, x);
        x += 2 * padding + tokenFont.extents(labeler.getLabel(token, input)).getWidth();
    }
    return positions;
}
Also used : HashMap(java.util.HashMap) AnnisNode(annis.model.AnnisNode)

Example 28 with AnnisNode

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

the class DetectHolesTest method initializeTokens.

private void initializeTokens() {
    token = new ArrayList<AnnisNode>();
    token.add(new AnnisNode(5, 0, 0, 0, 0, "annis", "test", 20, "test1", 20, 20));
    token.add(new AnnisNode(6, 0, 0, 0, 0, "annis", "test", 21, "test2", 21, 21));
    token.add(new AnnisNode(7, 0, 0, 0, 0, "annis", "test", 22, "test3", 22, 22));
    token.add(new AnnisNode(8, 0, 0, 0, 0, "annis", "test", 40, "test4", 40, 40));
    token.add(new AnnisNode(9, 0, 0, 0, 0, "annis", "test", 41, "test5", 41, 41));
    token.add(new AnnisNode(10, 0, 0, 0, 0, "annis", "test", 42, "test6", 42, 42));
    token.add(new AnnisNode(11, 0, 0, 0, 0, "annis", "test", 50, "test7", 50, 50));
}
Also used : AnnisNode(annis.model.AnnisNode)

Example 29 with AnnisNode

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

the class DetectHolesTest method testGetLeftBorder.

/**
 * Test of getLeftBorder method, of class DetectHoles.
 */
@Test
public void testGetLeftBorder() {
    System.out.println("getLeftBorder");
    DetectHoles instance = new DetectHoles(token);
    AnnisNode result = instance.getLeftBorder(node1);
    assertEquals(token.get(0), result);
    result = instance.getLeftBorder(node2);
    assertEquals(token.get(3), result);
    result = instance.getLeftBorder(node3);
    assertEquals(token.get(0), result);
    result = instance.getRightBorder(node4);
    assertEquals(token.get(5), result);
}
Also used : DetectHoles(annis.visualizers.iframe.partitur.DetectHoles) AnnisNode(annis.model.AnnisNode) Test(org.junit.Test)

Example 30 with AnnisNode

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

the class DetectHolesTest method testGetRightBorder.

/**
 * Test of getRightBorder method, of class DetectHoles.
 */
@Test
public void testGetRightBorder() {
    System.out.println("getRightBorder");
    AnnisNode result = null;
    DetectHoles instance = new DetectHoles(token);
    result = instance.getRightBorder(node1);
    assertEquals(token.get(2), result);
    result = instance.getRightBorder(node2);
    assertEquals(token.get(5), result);
    result = instance.getRightBorder(node3);
    assertEquals(token.get(6), result);
    result = instance.getRightBorder(node4);
    assertEquals(token.get(5), result);
}
Also used : DetectHoles(annis.visualizers.iframe.partitur.DetectHoles) 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