use of annis.model.Edge in project ANNIS by korpling.
the class TigerTreeVisualizer method writeOutput.
@Override
public void writeOutput(VisualizerInput input, OutputStream outstream) {
AnnisResult result = input.getResult();
graphtools = new AnnisGraphTools(input);
List<AbstractImageGraphicsItem> layouts = new LinkedList<AbstractImageGraphicsItem>();
double width = 0;
double maxheight = 0;
for (DirectedGraph<AnnisNode, Edge> g : graphtools.getSyntaxGraphs()) {
if (g.getEdgeCount() > 0 && g.getVertexCount() > 0) {
ConstituentLayouter<AbstractImageGraphicsItem> cl = new ConstituentLayouter<AbstractImageGraphicsItem>(g, getBackend(), labeler, styler, input, graphtools);
AbstractImageGraphicsItem item = cl.createLayout(new LayoutOptions(VerticalOrientation.TOP_ROOT, AnnisGraphTools.detectLayoutDirection(result.getGraph())));
Rectangle2D treeSize = item.getBounds();
maxheight = Math.max(maxheight, treeSize.getHeight());
width += treeSize.getWidth();
layouts.add(item);
}
}
BufferedImage image;
if (width == 0 || maxheight == 0) {
Notification.show("Can't generate tree visualization.", Notification.Type.WARNING_MESSAGE);
image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
} else {
image = new BufferedImage((int) (width + (layouts.size() - 1) * TREE_DISTANCE + 2 * SIDE_MARGIN), (int) (maxheight + 2 * TOP_MARGIN), BufferedImage.TYPE_INT_ARGB);
Graphics2D canvas = createCanvas(image);
double xOffset = SIDE_MARGIN;
for (AbstractImageGraphicsItem item : layouts) {
AffineTransform t = canvas.getTransform();
Rectangle2D bounds = item.getBounds();
canvas.translate(xOffset, TOP_MARGIN + maxheight - bounds.getHeight());
renderTree(item, canvas);
xOffset += bounds.getWidth() + TREE_DISTANCE;
canvas.setTransform(t);
}
}
try {
ImageIO.write(image, "png", outstream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of annis.model.Edge in project ANNIS by korpling.
the class LegacyGraphConverter method addRelation.
private static void addRelation(Class<? extends SRelation> clazz, String type, Collection<SAnnotation> annotations, SNode source, SNode target, Set<SLayer> relLayers, long pre, long componentID, Map<SNode, AnnisNode> allNodes, AnnotationGraph annoGraph) {
Edge aEdge = new Edge();
aEdge.setSource(allNodes.get(source));
aEdge.setDestination(allNodes.get(target));
aEdge.setEdgeType(EdgeType.UNKNOWN);
aEdge.setPre(pre);
aEdge.setComponentID(componentID);
if (!relLayers.isEmpty()) {
aEdge.setNamespace(relLayers.iterator().next().getName());
}
aEdge.setName(type);
if (SDominanceRelation.class.isAssignableFrom(clazz)) {
aEdge.setEdgeType(EdgeType.DOMINANCE);
} else if (SPointingRelation.class.isAssignableFrom(clazz)) {
aEdge.setEdgeType(EdgeType.POINTING_RELATION);
} else if (SSpanningRelation.class.isAssignableFrom(clazz)) {
aEdge.setEdgeType(EdgeType.COVERAGE);
}
for (SAnnotation sAnno : annotations) {
aEdge.addAnnotation(new Annotation(sAnno.getNamespace(), sAnno.getName(), sAnno.getValue_STEXT()));
}
annoGraph.addEdge(aEdge);
aEdge.getDestination().addIncomingEdge(aEdge);
if (aEdge.getSource() != null) {
aEdge.getSource().addOutgoingEdge(aEdge);
}
}
use of annis.model.Edge in project ANNIS by korpling.
the class DotGraphVisualizer method internalCreateDot.
private void internalCreateDot() {
w("digraph G {\n");
w("\tnode [shape=box];\n");
// node definitions
List<AnnisNode> token = new LinkedList<AnnisNode>();
for (AnnisNode n : input.getResult().getGraph().getNodes()) {
if (n.isToken()) {
token.add(n);
} else {
if (testNode(n)) {
writeNode(n);
}
}
}
// Token are in a subgraph
w("\t{\n" + "\trank=max;\n");
for (AnnisNode tok : token) {
w("\t");
writeNode(tok);
}
writeInvisibleTokenEdges(token);
w("\t}\n");
for (Edge e : input.getResult().getGraph().getEdges()) {
if (e != null && testEdge(e)) {
writeEdge(e);
}
}
w("}");
}
use of annis.model.Edge in project ANNIS by korpling.
the class ConstituentLayouter method addSecEdges.
private void addSecEdges(TreeLayoutData treeLayout, LayoutOptions options) {
for (Edge e : graph.getEdges()) {
if (!GRAPH_TOOLS.hasEdgeSubtype(e, GRAPH_TOOLS.getSecEdgeSubType())) {
continue;
}
Rectangle2D sourceRect = treeLayout.getRect(e.getSource());
Rectangle2D targetRect = treeLayout.getRect(e.getDestination());
CubicCurve2D curveData = secedgeCurve(treeLayout.getOrientation(), sourceRect, targetRect);
T secedgeElem = backend.cubicCurve(curveData, styler.getStroke(e, input), styler.getEdgeColor(e, input));
secedgeElem.setZValue(-2);
T arrowElem = backend.arrow(curveData.getP1(), curveData.getCtrlP1(), new Rectangle2D.Double(0, 0, 8, 8), styler.getEdgeColor(e, input));
arrowElem.setZValue(-1);
arrowElem.setParentItem(secedgeElem);
Point2D labelPos = evaluate(curveData, 0.8);
T label = backend.makeLabel(labeler.getLabel(e, input), labelPos, styler.getFont(e), styler.getTextBrush(e), Alignment.CENTERED, styler.getShape(e, input));
label.setParentItem(secedgeElem);
secedgeElem.setParentItem(treeLayout.getParentItem());
}
}
use of annis.model.Edge in project ANNIS by korpling.
the class ConstituentLayouter method getOutgoingEdges.
private List<Edge> getOutgoingEdges(final AnnisNode current) {
List<Edge> outEdges = new ArrayList<Edge>();
for (Edge e : graph.getOutEdges(current)) {
if (GRAPH_TOOLS.hasEdgeSubtype(e, GRAPH_TOOLS.getPrimEdgeSubType())) {
outEdges.add(e);
}
}
Collections.sort(outEdges, new Comparator<Edge>() {
@Override
public int compare(Edge o1, Edge o2) {
int h1 = dataMap.get(graph.getOpposite(current, o1)).getHeight();
int h2 = dataMap.get(graph.getOpposite(current, o2)).getHeight();
return h1 - h2;
}
});
return outEdges;
}
Aggregations