Search in sources :

Example 1 with SMetaAnnotation

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

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 SAnnotation (org.corpus_tools.salt.core.SAnnotation)1 SFeature (org.corpus_tools.salt.core.SFeature)1 SLayer (org.corpus_tools.salt.core.SLayer)1 SMetaAnnotation (org.corpus_tools.salt.core.SMetaAnnotation)1 SNode (org.corpus_tools.salt.core.SNode)1 SProcessingAnnotation (org.corpus_tools.salt.core.SProcessingAnnotation)1 SRelation (org.corpus_tools.salt.core.SRelation)1