Search in sources :

Example 1 with Relation

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;
}
Also used : SRelation(org.corpus_tools.salt.core.SRelation) SLayer(org.corpus_tools.salt.core.SLayer) SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) Relation(org.corpus_tools.salt.graph.Relation) RelannisEdgeFeature(annis.model.RelannisEdgeFeature)

Example 2 with Relation

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;
}
Also used : SRelation(org.corpus_tools.salt.core.SRelation) SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) Relation(org.corpus_tools.salt.graph.Relation)

Example 3 with Relation

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
}
Also used : SToken(org.corpus_tools.salt.common.SToken) RelannisNodeFeature(annis.model.RelannisNodeFeature) SRelation(org.corpus_tools.salt.core.SRelation) SLayer(org.corpus_tools.salt.core.SLayer) SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) Relation(org.corpus_tools.salt.graph.Relation) SSpan(org.corpus_tools.salt.common.SSpan) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation)

Aggregations

SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)3 SOrderRelation (org.corpus_tools.salt.common.SOrderRelation)3 SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)3 SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)3 STextualRelation (org.corpus_tools.salt.common.STextualRelation)3 SRelation (org.corpus_tools.salt.core.SRelation)3 Relation (org.corpus_tools.salt.graph.Relation)3 SLayer (org.corpus_tools.salt.core.SLayer)2 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 SSpan (org.corpus_tools.salt.common.SSpan)1 SToken (org.corpus_tools.salt.common.SToken)1