Search in sources :

Example 16 with RelannisNodeFeature

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

the class SpanHTMLOutputter method outputAnnotation.

private void outputAnnotation(SNode span, String matchedQName, SortedMap<Long, List<OutputItem>> outputStartTags, SortedMap<Long, List<OutputItem>> outputEndTags, int priority) {
    long left;
    long right;
    RelannisNodeFeature feat = (RelannisNodeFeature) span.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
    left = feat.getLeftToken();
    right = feat.getRightToken();
    SAnnotation matchedAnnotation;
    if (type == Type.META_NAME) {
        // constant property is used to store metadata names, see VisParser.java
        matchedAnnotation = span.getAnnotation("meta::" + constant);
    } else {
        matchedAnnotation = span.getAnnotation(matchedQName);
    }
    String value;
    // output to an inner text node
    switch(type) {
        case CONSTANT:
            value = constant;
            break;
        case HTML_TEMPLATE:
            String original = constant;
            String innerValue = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
            String innerAnno = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
            value = original.replaceAll("%%value%%", innerValue);
            value = value.replaceAll("%%anno%%", innerAnno);
            break;
        case VALUE:
            value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
            break;
        case ESCAPED_VALUE:
            value = htmlEscaper.escape(matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT());
            break;
        case ANNO_NAME:
            value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
            break;
        case META_NAME:
            value = matchedAnnotation.getValue() == null ? "NULL" : matchedAnnotation.getValue().toString();
            matchedQName = "meta::" + metaname;
            break;
        default:
            value = "";
            break;
    }
    outputAny(left, right, matchedQName, value, outputStartTags, outputEndTags, priority);
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) SAnnotation(org.corpus_tools.salt.core.SAnnotation)

Example 17 with RelannisNodeFeature

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

the class SaltAnnotateExtractor method createMissingSpanningRelations.

/**
 * Use the left/right token index of the spans to create spanning relations
 * when this did not happen yet.
 *
 * @param graph
 * @param nodeByRankID
 * @param numberOfRelations
 */
private void createMissingSpanningRelations(SDocumentGraph graph, FastInverseMap<Long, SNode> nodeByRankID, TreeMap<Long, SToken> tokenByIndex, Map<String, ComponentEntry> componentForSpan, AtomicInteger numberOfRelations) {
    // add the missing spanning relations for each continuous span of the graph
    for (SSpan span : graph.getSpans()) {
        long pre = 1;
        RelannisNodeFeature featSpan = RelannisNodeFeature.extract(span);
        ComponentEntry spanComponent = componentForSpan.get(span.getId());
        if (spanComponent != null && featSpan != null && featSpan.getLeftToken() >= 0 && featSpan.getRightToken() >= 0) {
            for (long i = featSpan.getLeftToken(); i <= featSpan.getRightToken(); i++) {
                SToken tok = tokenByIndex.get(i);
                if (tok != null) {
                    boolean missing = true;
                    List<SRelation<SNode, SNode>> existingRelations = graph.getRelations(span.getId(), tok.getId());
                    if (existingRelations != null) {
                        for (Relation e : existingRelations) {
                            if (e instanceof SSpanningRelation) {
                                missing = false;
                                break;
                            }
                        }
                    }
                    if (missing) {
                        String type = "c";
                        SLayer layer = findOrAddSLayer(spanComponent.getNamespace(), graph);
                        createNewRelation(graph, span, tok, null, type, spanComponent.getId(), layer, pre++, nodeByRankID, numberOfRelations);
                    }
                }
            // end if token exists
            }
        // end for each covered token index
        }
    }
// end for each span
}
Also used : SToken(org.corpus_tools.salt.common.SToken) RelannisNodeFeature(annis.model.RelannisNodeFeature) SRelation(org.corpus_tools.salt.core.SRelation) SLayer(org.corpus_tools.salt.core.SLayer) SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) Relation(org.corpus_tools.salt.graph.Relation) SSpan(org.corpus_tools.salt.common.SSpan) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation)

Example 18 with RelannisNodeFeature

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

the class SingleResultPanel method getIds.

private MinMax getIds(SDocumentGraph graph) {
    List<SToken> sTokens = graph.getTokens();
    MinMax minMax = new MinMax();
    minMax.min = Long.MAX_VALUE;
    minMax.max = Long.MIN_VALUE;
    if (segmentationName == null) {
        minMax.segName = "tokens";
        if (sTokens != null) {
            for (SToken t : sTokens) {
                SFeature feature = t.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE);
                if (feature != null && feature.getValue() instanceof RelannisNodeFeature) {
                    RelannisNodeFeature f = (RelannisNodeFeature) feature.getValue();
                    if (minMax.min > f.getTokenIndex()) {
                        minMax.min = f.getTokenIndex();
                    }
                    if (minMax.max < f.getTokenIndex()) {
                        minMax.max = f.getTokenIndex();
                    }
                }
            }
        }
    } else {
        minMax.segName = segmentationName;
        List<SNode> nodes = CommonHelper.getSortedSegmentationNodes(segmentationName, graph);
        for (SNode n : nodes) {
            RelannisNodeFeature f = RelannisNodeFeature.extract(n);
            if (minMax.min > f.getSegIndex()) {
                minMax.min = f.getSegIndex();
            }
            if (minMax.max < f.getSegIndex()) {
                minMax.max = f.getSegIndex();
            }
        }
    }
    minMax.min++;
    minMax.max++;
    return minMax;
}
Also used : SToken(org.corpus_tools.salt.common.SToken) RelannisNodeFeature(annis.model.RelannisNodeFeature) SNode(org.corpus_tools.salt.core.SNode) SFeature(org.corpus_tools.salt.core.SFeature)

Aggregations

RelannisNodeFeature (annis.model.RelannisNodeFeature)18 SNode (org.corpus_tools.salt.core.SNode)11 SFeature (org.corpus_tools.salt.core.SFeature)8 SToken (org.corpus_tools.salt.common.SToken)7 HashMap (java.util.HashMap)6 GridEvent (annis.gui.widgets.grid.GridEvent)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SAnnotation (org.corpus_tools.salt.core.SAnnotation)5 LinkedList (java.util.LinkedList)4 TreeMap (java.util.TreeMap)4 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)4 Row (annis.gui.widgets.grid.Row)3 HashSet (java.util.HashSet)3 SLayer (org.corpus_tools.salt.core.SLayer)3 SRelation (org.corpus_tools.salt.core.SRelation)3 Annotation (annis.model.Annotation)2 AnnotationGraph (annis.model.AnnotationGraph)2 CorpusConfigMap (annis.service.objects.CorpusConfigMap)2 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)2