use of org.corpus_tools.salt.graph.Relation in project ANNIS by korpling.
the class SaltAnnotateExtractor method handleArtificialDominanceRelation.
/**
* In ANNIS there is a special combined dominance component which has an empty
* name, but which should not directly be included in the Salt graph.
*
* This functions checks if a dominance relation with empty name has a
* "mirror" relation which is inside the same layer and between the same nodes
* but has an relation name. If yes the original dominance relation is an
* artificial one. The function will return true in this case and update the
* mirror relation to include information about the artificial dominance
* relation.
*
* @param graph
* @param rel
* @parem layer
* @param componentID
* @param pre
* @return True if the dominance relation was an artificial one
*/
private boolean handleArtificialDominanceRelation(SDocumentGraph graph, SNode source, SNode target, SRelation rel, SLayer layer, long componentID, long pre) {
List<SRelation<SNode, SNode>> mirrorRelations = graph.getRelations(source.getId(), target.getId());
if (mirrorRelations != null && mirrorRelations.size() > 0) {
for (Relation mirror : mirrorRelations) {
if (mirror != rel && mirror instanceof SRelation) {
// check layer
SRelation mirrorRel = (SRelation) mirror;
Set<SLayer> mirrorLayers = mirrorRel.getLayers();
if (mirrorLayers != null) {
for (SLayer mirrorLayer : mirrorLayers) {
if (mirrorLayer == layer) {
// adjust the feature of the mirror relation to include
// information about the artificial dominance relation
RelannisEdgeFeature mirrorFeat = RelannisEdgeFeature.extract(mirrorRel);
mirrorFeat.setArtificialDominanceComponent(componentID);
mirrorFeat.setArtificialDominancePre(pre);
mirrorRel.removeLabel(ANNIS_NS, FEAT_RELANNIS_EDGE);
mirrorRel.createFeature(ANNIS_NS, FEAT_RELANNIS_EDGE, mirrorFeat);
return true;
}
}
}
}
}
}
return false;
}
use of org.corpus_tools.salt.graph.Relation in project ANNIS by korpling.
the class SaltAnnotateExtractor method findExistingRelation.
private SRelation findExistingRelation(SDocumentGraph graph, SNode sourceNode, SNode targetNode, String relationName, SLayer layer) {
SRelation rel = null;
List<SRelation<SNode, SNode>> existingRelations = graph.getRelations(sourceNode.getId(), targetNode.getId());
if (existingRelations != null) {
for (Relation e : existingRelations) {
// the same layer "edge_namespace")
if (e instanceof SRelation) {
SRelation existingRel = (SRelation) e;
boolean noType = existingRel.getType() == null;
if (((noType && relationName == null) || (!noType && existingRel.getType().equals(relationName))) && existingRel.getLayers().contains(layer)) {
rel = existingRel;
break;
}
}
}
}
return rel;
}
use of org.corpus_tools.salt.graph.Relation 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
}
Aggregations