Search in sources :

Example 16 with Annotation

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");
    }
}
Also used : HashMap(java.util.HashMap) AnnisResult(annis.service.ifaces.AnnisResult) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) Annotation(annis.model.Annotation) AnnisNode(annis.model.AnnisNode) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 17 with Annotation

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);
        }
    }
}
Also used : AnnisNode(annis.model.AnnisNode) Annotation(annis.model.Annotation)

Example 18 with Annotation

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);
    }
}
Also used : AnnisNode(annis.model.AnnisNode) Annotation(annis.model.Annotation)

Example 19 with Annotation

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);
            }
        }
    }
}
Also used : AnnisNode(annis.model.AnnisNode) Annotation(annis.model.Annotation)

Example 20 with Annotation

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));
}
Also used : ResultSet(java.sql.ResultSet) Annotation(annis.model.Annotation) Test(org.junit.Test)

Aggregations

Annotation (annis.model.Annotation)43 ArrayList (java.util.ArrayList)13 LinkedList (java.util.LinkedList)12 HashMap (java.util.HashMap)11 AnnisNode (annis.model.AnnisNode)10 AnnotatedSpan (annis.dao.objects.AnnotatedSpan)6 Test (org.junit.Test)6 AnnotatedMatch (annis.dao.objects.AnnotatedMatch)5 List (java.util.List)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 SAnnotation (org.corpus_tools.salt.core.SAnnotation)5 AnnisResult (annis.service.ifaces.AnnisResult)4 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)4 WebResource (com.sun.jersey.api.client.WebResource)4 Array (java.sql.Array)4 SNode (org.corpus_tools.salt.core.SNode)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 SToken (org.corpus_tools.salt.common.SToken)3 AnnotationGraph (annis.model.AnnotationGraph)2