use of annis.model.Annotation in project ANNIS by korpling.
the class GridExporter 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<>();
boolean showNumbers = true;
if (args.containsKey("numbers")) {
String arg = args.get("numbers");
if (arg.equalsIgnoreCase("false") || arg.equalsIgnoreCase("0") || arg.equalsIgnoreCase("off")) {
showNumbers = false;
}
}
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) {
HashMap<String, TreeMap<Long, Span>> annos = new HashMap<>();
counter++;
out.append((counter + offset) + ".");
long tokenOffset = annisResult.getGraph().getTokens().get(0).getTokenIndex() - 1;
for (AnnisNode resolveNode : annisResult.getGraph().getNodes()) {
for (Annotation resolveAnnotation : resolveNode.getNodeAnnotations()) {
String k = resolveAnnotation.getName();
if (annos.get(k) == null) {
annos.put(k, new TreeMap<Long, Span>());
}
// create a separate span for every annotation
annos.get(k).put(resolveNode.getLeftToken(), new Span(resolveNode.getLeftToken(), resolveNode.getRightToken(), resolveAnnotation.getValue()));
}
}
for (String k : keys) {
if ("tok".equals(k)) {
out.append("\t" + k + "\t ");
for (AnnisNode annisNode : annisResult.getGraph().getTokens()) {
out.append(annisNode.getSpannedText() + " ");
}
out.append("\n");
} else {
if (annos.get(k) != null) {
out.append("\t" + k + "\t ");
for (Span s : annos.get(k).values()) {
out.append(s.getValue());
if (showNumbers) {
long leftIndex = Math.max(1, s.getStart() - tokenOffset);
long rightIndex = s.getEnd() - tokenOffset;
out.append("[" + leftIndex + "-" + rightIndex + "]");
}
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\n");
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class ProielDependecyTree method writeAllNodes.
private void writeAllNodes() {
for (AnnisNode n : input.getResult().getGraph().getNodes()) {
boolean isDepNode = false;
String word = null;
for (Annotation anno : n.getNodeAnnotations()) {
if ("tiger".equals(anno.getNamespace()) && "word".equals(anno.getName())) {
isDepNode = true;
word = anno.getValue();
break;
}
}
if (isDepNode) {
writeNode(n, word);
}
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class ProielDependecyTree method writeEdge.
private void writeEdge(Edge e) {
AnnisNode srcNode = e.getSource();
AnnisNode destNode = e.getDestination();
if (e.getName() == null || srcNode == null || destNode == null) {
return;
}
String srcId = "" + srcNode.getId();
String destId = "" + destNode.getId();
// get the edge annotation
StringBuilder sbAnno = new StringBuilder();
for (Annotation anno : e.getAnnotations()) {
if ("func".equals(anno.getName())) {
if ("--".equals(anno.getValue())) {
return;
}
sbAnno.append(anno.getValue());
}
break;
}
String style = null;
if ("secedge".equals(e.getName())) {
style = "color=blue, fontcolor=black, style=dashed";
} else {
style = "color=orange, fontcolor=black";
}
String edgeString = srcId + " -> " + destId + "[" + style + " label=\"" + sbAnno.toString() + "\"]";
if (!alreadyWrittenEdge.contains(edgeString)) {
w(" " + edgeString);
alreadyWrittenEdge.add(edgeString);
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class ProielRegularDependencyTree method writeAllPseudoToken.
private void writeAllPseudoToken() {
// write out pseudo token nodes
for (AnnisNode n : input.getResult().getGraph().getNodes()) {
if (!n.isToken()) {
boolean isDepNode = false;
for (Annotation anno : n.getNodeAnnotations()) {
if ("tiger".equals(anno.getNamespace()) && "word".equals(anno.getName())) {
isDepNode = true;
break;
}
}
if (isDepNode) {
writeNode(n);
pseudoToken.add(n);
}
}
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class TestListCorpusAnnotationsSqlHelper method mapRow.
@Test
public void mapRow() throws SQLException {
// stub a row in the ResultSet
ResultSet resultSet = mock(ResultSet.class);
final String NAMESPACE = "NAMESPACE";
final String NAME = "NAME";
final String VALUE = "VALUE";
when(resultSet.getString("namespace")).thenReturn(NAMESPACE);
when(resultSet.getString("name")).thenReturn(NAME);
when(resultSet.getString("value")).thenReturn(VALUE);
// expected annotation
Annotation expected = new Annotation(NAMESPACE, NAME, VALUE);
// call and test
assertThat(listCorpusAnnotationsHelper.mapRow(resultSet, 1), is(expected));
}
Aggregations