use of annis.model.AnnisNode in project ANNIS by korpling.
the class AomAnnotateSqlGeneratorTest method shouldMapNode.
@Test
public void shouldMapNode() throws SQLException {
// given
stubNodeResultSet();
// when
AnnisNode actual = generator.mapNode(resultSet, tableAccessStrategy, null);
// then
AnnisNode expected = new AnnisNode(ID, CORPUS_REF, TEXT_REF, LEFT, RIGHT, NODE_NAMESPACE, NODE_NAME, TOKEN_INDEX, SPAN, LEFT_TOKEN, RIGHT_TOKEN);
assertThat(actual, is(expected));
}
use of annis.model.AnnisNode 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.AnnisNode in project ANNIS by korpling.
the class TokenExporter method convertText.
@Override
public void convertText(AnnisResultSet queryResult, List<String> keys, Map<String, String> args, Writer out, int offset) throws IOException {
Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();
List<String> metaKeys = new LinkedList<>();
if (args.containsKey("metakeys")) {
Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
for (String s : it) {
metaKeys.add(s);
}
}
int counter = 0;
for (AnnisResult annisResult : queryResult) {
Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds();
counter++;
out.append((counter + offset) + ". ");
List<AnnisNode> tok = annisResult.getGraph().getTokens();
for (AnnisNode annisNode : tok) {
Long tokID = annisNode.getId();
if (matchedNodeIds.contains(tokID)) {
out.append("[");
out.append(annisNode.getSpannedText());
out.append("]");
} else {
out.append(annisNode.getSpannedText());
}
for (Annotation annotation : annisNode.getNodeAnnotations()) {
out.append("/" + annotation.getValue());
}
out.append(" ");
}
out.append("\n");
if (!metaKeys.isEmpty()) {
String[] path = annisResult.getPath();
super.appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
}
out.append("\n");
}
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class LegacyGraphConverter method convertToAnnotationGraph.
public static AnnotationGraph convertToAnnotationGraph(SDocumentGraph docGraph, List<Long> matchedNodeIDs) {
Set<Long> matchSet = new HashSet<>(matchedNodeIDs);
AnnotationGraph annoGraph = new AnnotationGraph();
List<String> pathList = CommonHelper.getCorpusPath(docGraph.getDocument().getGraph(), docGraph.getDocument());
annoGraph.setPath(pathList.toArray(new String[pathList.size()]));
annoGraph.setDocumentName(docGraph.getDocument().getName());
Map<SNode, AnnisNode> allNodes = new HashMap<>();
for (SNode sNode : docGraph.getNodes()) {
SFeature featNodeRaw = sNode.getFeature(SaltUtil.createQName(ANNIS_NS, FEAT_RELANNIS_NODE));
if (featNodeRaw != null) {
RelannisNodeFeature featNode = (RelannisNodeFeature) featNodeRaw.getValue();
long internalID = featNode.getInternalID();
AnnisNode aNode = new AnnisNode(internalID);
for (SAnnotation sAnno : sNode.getAnnotations()) {
aNode.addNodeAnnotation(new Annotation(sAnno.getNamespace(), sAnno.getName(), sAnno.getValue_STEXT()));
}
aNode.setName(sNode.getName());
Set<SLayer> layers = sNode.getLayers();
if (!layers.isEmpty()) {
aNode.setNamespace(layers.iterator().next().getName());
}
RelannisNodeFeature feat = (RelannisNodeFeature) sNode.getFeature(SaltUtil.createQName(ANNIS_NS, FEAT_RELANNIS_NODE)).getValue();
if (sNode instanceof SToken) {
List<DataSourceSequence> seqList = docGraph.getOverlappedDataSourceSequence(sNode, SALT_TYPE.STEXT_OVERLAPPING_RELATION);
if (seqList != null) {
DataSourceSequence seq = seqList.get(0);
Preconditions.checkNotNull(seq, "DataSourceSequence is null for token %s", sNode.getId());
SSequentialDS seqDS = seq.getDataSource();
Preconditions.checkNotNull(seqDS, "SSequentalDS is null for token %s", sNode.getId());
Preconditions.checkNotNull(seqDS.getData(), "SSequentalDS data is null for token %s", sNode.getId());
String seqDSData = (String) seqDS.getData();
Preconditions.checkNotNull(seqDSData, "casted SSequentalDS data is null for token %s", sNode.getId());
Preconditions.checkNotNull(seq.getStart(), "SSequentalDS start is null for token %s", sNode.getId());
Preconditions.checkNotNull(seq.getEnd(), "SSequentalDS end is null for supposed token %s", sNode.getId());
int start = seq.getStart().intValue();
int end = seq.getEnd().intValue();
Preconditions.checkState(start >= 0 && start <= end && end <= seqDSData.length(), "Illegal start or end of textual DS for token (start %s, end: %s)", sNode.getId(), start, end);
String spannedText = seqDSData.substring(start, end);
Preconditions.checkNotNull(spannedText, "spanned text is null for supposed token %s (start: %s, end: %s)", sNode.getId(), start, end);
aNode.setSpannedText(spannedText);
aNode.setToken(true);
aNode.setTokenIndex(feat.getTokenIndex());
}
} else {
aNode.setToken(false);
aNode.setTokenIndex(null);
}
aNode.setCorpus(feat.getCorpusRef());
aNode.setTextId(feat.getTextRef());
aNode.setLeft(feat.getLeft());
aNode.setLeftToken(feat.getLeftToken());
aNode.setRight(feat.getRight());
aNode.setRightToken(feat.getRightToken());
if (matchSet.contains(aNode.getId())) {
aNode.setMatchedNodeInQuery((long) matchedNodeIDs.indexOf(aNode.getId()) + 1);
annoGraph.getMatchedNodeIds().add(aNode.getId());
} else {
aNode.setMatchedNodeInQuery(null);
}
annoGraph.addNode(aNode);
allNodes.put(sNode, aNode);
}
}
for (SRelation rel : docGraph.getRelations()) {
RelannisEdgeFeature featRelation = RelannisEdgeFeature.extract(rel);
if (featRelation != null) {
addRelation(rel, featRelation.getPre(), featRelation.getComponentID(), allNodes, annoGraph);
}
}
// add relations with empty relation name for every dominance relation
List<SDominanceRelation> dominanceRelations = new LinkedList<>(docGraph.getDominanceRelations());
for (SDominanceRelation rel : dominanceRelations) {
RelannisEdgeFeature featEdge = RelannisEdgeFeature.extract(rel);
if (featEdge != null && featEdge.getArtificialDominanceComponent() != null && featEdge.getArtificialDominancePre() != null) {
addRelation(SDominanceRelation.class, null, rel.getAnnotations(), rel.getSource(), rel.getTarget(), rel.getLayers(), featEdge.getArtificialDominancePre(), featEdge.getArtificialDominanceComponent(), allNodes, annoGraph);
}
}
return annoGraph;
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class AnnisResultImpl method getTokenList.
public List<AnnisToken> getTokenList() {
List<AnnisToken> result = new ArrayList<AnnisToken>();
for (AnnisNode node : graph.getTokens()) {
AnnisTokenImpl annisToken = new AnnisTokenImpl(node.getId(), node.getSpannedText(), node.getLeft(), node.getRight(), node.getTokenIndex(), node.getCorpus());
for (Annotation annotation : node.getNodeAnnotations()) {
annisToken.put(annotation.getQualifiedName(), annotation.getValue());
}
result.add(annisToken);
}
return result;
}
Aggregations