use of org.corpus_tools.salt.exceptions.SaltException in project ANNIS by korpling.
the class SaltAnnotateExtractor method createNewRelation.
private SRelation createNewRelation(SDocumentGraph graph, SStructuredNode sourceNode, SNode targetNode, String relationName, String type, long componentID, SLayer layer, long pre, FastInverseMap<Long, SNode> nodeByRankID, AtomicInteger numberOfRelations) {
SRelation rel = null;
if (null != type) // create new relation
{
switch(type) {
case "d":
SDominanceRelation domrel = SaltFactory.createSDominanceRelation();
// always set a name by ourself since the SDocumentGraph#basicAddRelation()
// functions otherwise real slow
domrel.setName("sDomRel" + numberOfRelations.incrementAndGet());
rel = domrel;
if (sourceNode != null && !(sourceNode instanceof SStructure)) {
log.debug("Mismatched source type: should be SStructure");
SNode oldNode = sourceNode;
sourceNode = recreateNode(SStructure.class, sourceNode);
updateMapAfterRecreatingNode(oldNode, sourceNode, nodeByRankID);
}
if (relationName == null || relationName.isEmpty()) {
// layer but has a non-empty relation name
if (handleArtificialDominanceRelation(graph, sourceNode, targetNode, rel, layer, componentID, pre)) {
// don't include this relation
rel = null;
}
}
break;
case "c":
SSpanningRelation spanrel = SaltFactory.createSSpanningRelation();
// always set a name by ourself since the SDocumentGraph#basicAddRelation()
// functions is real slow otherwise
spanrel.setName("sSpanRel" + numberOfRelations.incrementAndGet());
rel = spanrel;
sourceNode = testAndFixNonSpan(sourceNode, nodeByRankID);
break;
case "p":
SPointingRelation pointingrel = SaltFactory.createSPointingRelation();
pointingrel.setName("sPointingRel" + numberOfRelations.incrementAndGet());
rel = pointingrel;
break;
default:
throw new IllegalArgumentException("Invalid type " + type + " for new Relation");
}
try {
if (rel != null) {
rel.setType(relationName);
RelannisEdgeFeature featRelation = new RelannisEdgeFeature();
featRelation.setPre(pre);
featRelation.setComponentID(componentID);
SFeature sfeatRelation = SaltFactory.createSFeature();
sfeatRelation.setNamespace(ANNIS_NS);
sfeatRelation.setName(FEAT_RELANNIS_EDGE);
sfeatRelation.setValue(featRelation);
rel.addFeature(sfeatRelation);
rel.setSource(sourceNode);
if ("c".equals(type) && !(targetNode instanceof SToken)) {
log.warn("invalid relation detected: target node ({}) " + "of a coverage relation (from: {}, internal id {}) was not a token", new Object[] { targetNode.getName(), sourceNode == null ? "null" : sourceNode.getName(), "" + pre });
} else {
rel.setTarget(targetNode);
graph.addRelation(rel);
layer.addRelation(rel);
}
}
} catch (SaltException ex) {
log.warn("invalid relation detected", ex);
}
}
return rel;
}
Aggregations