Search in sources :

Example 16 with SAnnotation

use of org.corpus_tools.salt.core.SAnnotation 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 SAnnotation

use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.

the class VisJsComponent method includeObject.

private static boolean includeObject(Set<SAnnotation> objectAnnotations, Map<String, Set<String>> displayedAnnotationsMap) {
    for (SAnnotation objectAnnotation : objectAnnotations) {
        String annotation = objectAnnotation.getName();
        String namespace = objectAnnotation.getNamespace();
        if (displayedAnnotationsMap.containsKey(annotation)) {
            // namespace has not to be considered
            if (displayedAnnotationsMap.get(annotation).isEmpty()) {
                return true;
            } else if (displayedAnnotationsMap.get(annotation).contains(namespace)) {
                return true;
            }
        }
    }
    return false;
}
Also used : SAnnotation(org.corpus_tools.salt.core.SAnnotation)

Example 18 with SAnnotation

use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.

the class SaltAnnotateExtractor method createOrFindNewNode.

private SNode createOrFindNewNode(ResultSet resultSet, SDocumentGraph graph, TreeSet<Long> allTextIDs, TreeMap<Long, String> tokenTexts, TreeMap<Long, SToken> tokenByIndex, TreeMap<String, TreeMap<Long, String>> nodeBySegmentationPath, SolutionKey<?> key, FastInverseMap<Long, SNode> nodeByRankID) throws SQLException {
    String name = stringValue(resultSet, NODE_TABLE, "node_name");
    String saltID = stringValue(resultSet, NODE_TABLE, "salt_id");
    if (saltID == null) {
        // fallback to the name
        saltID = name;
    }
    long internalID = longValue(resultSet, "node", "id");
    String relationType = stringValue(resultSet, COMPONENT_TABLE, "type");
    long tokenIndex = longValue(resultSet, NODE_TABLE, "token_index");
    boolean isToken = !resultSet.wasNull();
    org.eclipse.emf.common.util.URI nodeURI = graph.getDocument().getPath();
    nodeURI = nodeURI.appendFragment(saltID);
    SStructuredNode node = (SStructuredNode) graph.getNode(nodeURI.toString());
    if (node == null) {
        // create new node
        if (isToken) {
            node = createSToken(tokenIndex, resultSet, tokenTexts, tokenByIndex);
        } else {
            node = createOtherSNode(resultSet);
        }
        node.setName(name);
        node.setId(nodeURI.toString());
        setFeaturesForNode(node, internalID, resultSet);
        Object nodeId = key.getNodeId(resultSet, outerQueryTableAccessStrategy);
        graph.addNode(node);
        Integer matchedNode = key.getMatchedNodeIndex(nodeId);
        if (matchedNode != null) {
            addLongSFeature(node, FEAT_MATCHEDNODE, matchedNode);
        }
        mapLayer(node, graph, resultSet);
        long textRef = longValue(resultSet, NODE_TABLE, "text_ref");
        allTextIDs.add(textRef);
    } else if ("c".equals(relationType) && isToken == false) {
        node = testAndFixNonSpan(node, nodeByRankID);
    }
    String nodeAnnoValue = stringValue(resultSet, NODE_ANNOTATION_TABLE, "value");
    String nodeAnnoNameSpace = stringValue(resultSet, NODE_ANNOTATION_TABLE, "namespace");
    String nodeAnnoName = stringValue(resultSet, NODE_ANNOTATION_TABLE, "name");
    if (!resultSet.wasNull()) {
        String fullName = (nodeAnnoNameSpace == null || nodeAnnoNameSpace.isEmpty() ? "" : (nodeAnnoNameSpace + "::")) + nodeAnnoName;
        SAnnotation anno = node.getAnnotation(fullName);
        if (anno == null) {
            anno = SaltFactory.createSAnnotation();
            anno.setNamespace(nodeAnnoNameSpace);
            anno.setName(nodeAnnoName);
            anno.setValue(nodeAnnoValue);
            node.addAnnotation(anno);
        }
    }
    // prepare SOrderingRelation if the node is part of a segmentation path
    String segName = stringValue(resultSet, "node", "seg_name");
    if (segName != null) {
        long left = longValue(resultSet, "node", "seg_index");
        // last ones
        if (!nodeBySegmentationPath.containsKey(segName)) {
            nodeBySegmentationPath.put(segName, new TreeMap<Long, String>());
        }
        nodeBySegmentationPath.get(segName).put(left, node.getId());
    }
    return node;
}
Also used : SStructuredNode(org.corpus_tools.salt.common.SStructuredNode) SAnnotation(org.corpus_tools.salt.core.SAnnotation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 19 with SAnnotation

use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.

the class SaltAnnotateExtractor method moveNodeProperties.

private void moveNodeProperties(SStructuredNode oldNode, SStructuredNode newNode, SGraph graph) {
    Validate.notNull(oldNode);
    Validate.notNull(newNode);
    // step 1: collect every information that is need in a separate variable
    String id = oldNode.getId();
    String name = oldNode.getName();
    Set<SAnnotation> annotations = new LinkedHashSet<>(oldNode.getAnnotations());
    Set<SFeature> features = new LinkedHashSet<>(oldNode.getFeatures());
    Set<SProcessingAnnotation> processingAnnotations = new LinkedHashSet<>(oldNode.getProcessingAnnotations());
    Set<SMetaAnnotation> metaAnnotations = new LinkedHashSet<>(oldNode.getMetaAnnotations());
    Set<SLayer> nodeLayers = new LinkedHashSet<>(oldNode.getLayers());
    Multimap<SRelation, SLayer> layerOfRelation = ArrayListMultimap.create();
    List<SRelation<SNode, SNode>> inRelations = new LinkedList<>(graph.getInRelations(oldNode.getId()));
    List<SRelation<SNode, SNode>> outRelations = new LinkedList<>(graph.getOutRelations(oldNode.getId()));
    // step 2: remove the old node from everything it is connected to
    for (SRelation<SNode, SNode> rel : inRelations) {
        if (rel.getLayers() != null) {
            layerOfRelation.putAll(rel, rel.getLayers());
        }
        graph.removeRelation(rel);
    }
    for (SRelation<SNode, SNode> rel : outRelations) {
        if (rel.getLayers() != null) {
            layerOfRelation.putAll(rel, rel.getLayers());
        }
        graph.removeRelation(rel);
    }
    graph.removeNode(oldNode);
    // step 3: add the new node to everything it should be connected to
    newNode.setName(name);
    newNode.setId(id);
    graph.addNode(newNode);
    for (SAnnotation anno : annotations) {
        newNode.addAnnotation(anno);
    }
    for (SFeature feat : features) {
        // filter the features, do not include salt::SNAME
        if (!(SaltUtil.SALT_NAMESPACE.equals(feat.getNamespace()) && SaltUtil.FEAT_NAME.equals(feat.getName()))) {
            newNode.addFeature(feat);
        }
    }
    for (SProcessingAnnotation proc : processingAnnotations) {
        newNode.addProcessingAnnotation(proc);
    }
    for (SMetaAnnotation meta : metaAnnotations) {
        newNode.addMetaAnnotation(meta);
    }
    for (SLayer l : nodeLayers) {
        l.addNode(newNode);
    }
    for (SRelation rel : inRelations) {
        rel.setTarget(newNode);
        graph.addRelation(rel);
        if (layerOfRelation.containsKey(rel)) {
            for (SLayer l : layerOfRelation.get(rel)) {
                l.addRelation(rel);
            }
        }
    }
    for (SRelation rel : outRelations) {
        rel.setSource(newNode);
        graph.addRelation(rel);
        if (layerOfRelation.containsKey(rel)) {
            for (SLayer l : layerOfRelation.get(rel)) {
                l.addRelation(rel);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SLayer(org.corpus_tools.salt.core.SLayer) SNode(org.corpus_tools.salt.core.SNode) SAnnotation(org.corpus_tools.salt.core.SAnnotation) SProcessingAnnotation(org.corpus_tools.salt.core.SProcessingAnnotation) LinkedList(java.util.LinkedList) SRelation(org.corpus_tools.salt.core.SRelation) SMetaAnnotation(org.corpus_tools.salt.core.SMetaAnnotation) SFeature(org.corpus_tools.salt.core.SFeature)

Example 20 with SAnnotation

use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.

the class SaltAnnotateExtractor method addRelationAnnotations.

private void addRelationAnnotations(ResultSet resultSet, SRelation rel) throws SQLException {
    String relationAnnoValue = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "value");
    String relationAnnoNameSpace = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "namespace");
    String relationAnnoName = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "name");
    if (!resultSet.wasNull()) {
        String fullName = relationAnnoNameSpace == null ? "" : relationAnnoNameSpace + "::" + relationAnnoName;
        SAnnotation anno = rel.getAnnotation(fullName);
        if (anno == null) {
            anno = SaltFactory.createSAnnotation();
            anno.setNamespace(relationAnnoNameSpace == null ? "" : relationAnnoNameSpace);
            anno.setName(relationAnnoName);
            anno.setValue(relationAnnoValue);
            rel.addAnnotation(anno);
        }
    }
// end if relationAnnoName exists
}
Also used : SAnnotation(org.corpus_tools.salt.core.SAnnotation)

Aggregations

SAnnotation (org.corpus_tools.salt.core.SAnnotation)22 SToken (org.corpus_tools.salt.common.SToken)9 SNode (org.corpus_tools.salt.core.SNode)8 SRelation (org.corpus_tools.salt.core.SRelation)8 LinkedList (java.util.LinkedList)6 RelannisNodeFeature (annis.model.RelannisNodeFeature)5 HashMap (java.util.HashMap)4 SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)4 SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)4 SFeature (org.corpus_tools.salt.core.SFeature)4 SLayer (org.corpus_tools.salt.core.SLayer)4 Annotation (annis.model.Annotation)3 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)3 SSpan (org.corpus_tools.salt.common.SSpan)3 STextualDS (org.corpus_tools.salt.common.STextualDS)3 DataSourceSequence (org.corpus_tools.salt.util.DataSourceSequence)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2