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);
}
}
}
}
Aggregations