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());
}
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;
}
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;
}
}
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;
}
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));
}
Aggregations