Search in sources :

Example 1 with SaltException

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;
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SNode(org.corpus_tools.salt.core.SNode) SaltException(org.corpus_tools.salt.exceptions.SaltException) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) RelannisEdgeFeature(annis.model.RelannisEdgeFeature) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) SStructure(org.corpus_tools.salt.common.SStructure) SFeature(org.corpus_tools.salt.core.SFeature)

Aggregations

RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)1 SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)1 SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)1 SStructure (org.corpus_tools.salt.common.SStructure)1 SToken (org.corpus_tools.salt.common.SToken)1 SFeature (org.corpus_tools.salt.core.SFeature)1 SNode (org.corpus_tools.salt.core.SNode)1 SRelation (org.corpus_tools.salt.core.SRelation)1 SaltException (org.corpus_tools.salt.exceptions.SaltException)1