Search in sources :

Example 1 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class PartiturVisualizer method addTimeAttribute.

private String addTimeAttribute(long nodeId) {
    DetectHoles detectHoles = new DetectHoles(token);
    AnnisNode root = null;
    TimeHelper t = new TimeHelper(token);
    for (AnnisNode n : nodes) {
        if (n.getId() == nodeId) {
            root = n;
            break;
        }
    }
    // some calculations for index shifting
    AnnisNode leftNode = detectHoles.getLeftBorder(root);
    AnnisNode rightNode = detectHoles.getRightBorder(root);
    return t.getTimeAnno(leftNode, rightNode);
}
Also used : AnnisNode(annis.model.AnnisNode)

Example 2 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class AomAnnotateExtractor method mapNode.

public AnnisNode mapNode(ResultSet resultSet, TableAccessStrategy tableAccessStrategy, Map<Long, ComponentEntry> spans) throws SQLException {
    AnnisNode annisNode = new AnnisNode(longValue(resultSet, NODE_TABLE, "id", tableAccessStrategy));
    annisNode.setCorpus(longValue(resultSet, NODE_TABLE, "corpus_ref", tableAccessStrategy));
    annisNode.setTextId(longValue(resultSet, NODE_TABLE, "text_ref", tableAccessStrategy));
    annisNode.setLeft(longValue(resultSet, NODE_TABLE, "left", tableAccessStrategy));
    annisNode.setRight(longValue(resultSet, NODE_TABLE, "right", tableAccessStrategy));
    annisNode.setNamespace(stringValue(resultSet, NODE_TABLE, "namespace", tableAccessStrategy));
    annisNode.setName(stringValue(resultSet, NODE_TABLE, "name", tableAccessStrategy));
    annisNode.setTokenIndex(longValue(resultSet, NODE_TABLE, "token_index", tableAccessStrategy));
    if (resultSet.wasNull())
        annisNode.setTokenIndex(null);
    annisNode.setSpannedText(stringValue(resultSet, NODE_TABLE, "span", tableAccessStrategy));
    annisNode.setLeftToken(longValue(resultSet, NODE_TABLE, "left_token", tableAccessStrategy));
    annisNode.setRightToken(longValue(resultSet, NODE_TABLE, "right_token", tableAccessStrategy));
    String typeAsString = stringValue(resultSet, COMPONENT_TABLE, "type", tableAccessStrategy);
    if (spans != null && "c".equals(typeAsString)) {
        ComponentEntry entry = new ComponentEntry(longValue(resultSet, COMPONENT_TABLE, "id", tableAccessStrategy), typeAsString.charAt(0), stringValue(resultSet, COMPONENT_TABLE, "namespace", tableAccessStrategy), stringValue(resultSet, COMPONENT_TABLE, "name", tableAccessStrategy));
        spans.put(annisNode.getId(), entry);
    }
    return annisNode;
}
Also used : AnnisNode(annis.model.AnnisNode)

Example 3 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class GeneralTextExporter method convertText.

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();
            appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
        }
        out.append("\n");
    }
}
Also used : HashMap(java.util.HashMap) AnnisResult(annis.service.ifaces.AnnisResult) LinkedList(java.util.LinkedList) AnnisNode(annis.model.AnnisNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AnnisNode

use of annis.model.AnnisNode 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 5 with AnnisNode

use of annis.model.AnnisNode 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)

Aggregations

AnnisNode (annis.model.AnnisNode)38 Annotation (annis.model.Annotation)10 Edge (annis.model.Edge)9 LinkedList (java.util.LinkedList)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Map (java.util.Map)5 AnnotationGraph (annis.model.AnnotationGraph)4 AnnisResult (annis.service.ifaces.AnnisResult)4 DetectHoles (annis.visualizers.iframe.partitur.DetectHoles)2 DocumentNameMapRow (annis.dao.DocumentNameMapRow)1 MatchedNodeColors (annis.libgui.MatchedNodeColors)1 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 AnnisToken (annis.service.ifaces.AnnisToken)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 ArrayCorpusPathExtractor (annis.sqlgen.ArrayCorpusPathExtractor)1 CorpusPathExtractor (annis.sqlgen.CorpusPathExtractor)1