Search in sources :

Example 6 with SSpanningRelation

use of org.corpus_tools.salt.common.SSpanningRelation in project ANNIS by korpling.

the class TimelineReconstructor method moveRelations.

private void moveRelations(SStructuredNode oldSpan, SToken newToken, Set<String> validSpanAnnos, String orderName) {
    final List<SRelation> inRels = new LinkedList<>(oldSpan.getInRelations());
    final List<SRelation> outRels = new LinkedList<>(oldSpan.getOutRelations());
    final List<SToken> coveredByOldSpan = new LinkedList<>();
    for (SRelation rel : outRels) {
        if (rel instanceof SPointingRelation || rel instanceof SDominanceRelation) {
            rel.setSource(newToken);
        } else if (rel instanceof SSpanningRelation) {
            coveredByOldSpan.add(((SSpanningRelation) rel).getTarget());
        }
    }
    for (SRelation rel : inRels) {
        if (rel instanceof SPointingRelation || rel instanceof SDominanceRelation) {
            rel.setTarget(newToken);
        }
    }
    // find the connected spans and connect them with the new token instead
    for (SToken tok : coveredByOldSpan) {
        if (tok.getInRelations() != null) {
            for (SRelation<?, ?> rel : tok.getInRelations()) {
                if (rel instanceof SSpanningRelation) {
                    boolean valid = false;
                    SSpan spanToMap = ((SSpanningRelation) rel).getSource();
                    if (virtualTokenizationFromNamespace) {
                        for (SAnnotation anno : spanToMap.getAnnotations()) {
                            if (anno.getNamespace() != null && anno.getNamespace().equals(orderName)) {
                                valid = true;
                                break;
                            }
                        }
                    } else {
                        for (String validAnno : validSpanAnnos) {
                            if (spanToMap.getAnnotation(validAnno) != null) {
                                valid = true;
                                break;
                            }
                        }
                    }
                    if (valid) {
                        graph.createRelation(spanToMap, newToken, SALT_TYPE.SSPANNING_RELATION, null);
                    }
                }
            }
        }
    }
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SSpan(org.corpus_tools.salt.common.SSpan) SAnnotation(org.corpus_tools.salt.core.SAnnotation) LinkedList(java.util.LinkedList) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation)

Example 7 with SSpanningRelation

use of org.corpus_tools.salt.common.SSpanningRelation in project ANNIS by korpling.

the class TimelineReconstructor method addTimeline.

private void addTimeline() {
    STimeline timeline = graph.createTimeline();
    for (SToken virtualTok : graph.getSortedTokenByText()) {
        timeline.increasePointOfTime();
        // find all spans that are connected to this token and are part of an SOrderRelation
        for (SRelation<?, ?> inRel : virtualTok.getInRelations()) {
            if (inRel instanceof SSpanningRelation) {
                SSpanningRelation spanRel = (SSpanningRelation) inRel;
                SSpan overlappingSpan = spanRel.getSource();
                if (overlappingSpan != null) {
                    spans2TimelinePos.put(overlappingSpan, timeline.getEnd());
                }
            }
        }
        nodesToDelete.add(virtualTok);
    }
}
Also used : SToken(org.corpus_tools.salt.common.SToken) SSpan(org.corpus_tools.salt.common.SSpan) STimeline(org.corpus_tools.salt.common.STimeline) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation)

Example 8 with SSpanningRelation

use of org.corpus_tools.salt.common.SSpanningRelation in project ANNIS by korpling.

the class TimeHelper method getOverlappedTime.

/**
 * Get start and end time from the overlapped {@link SToken}. The minimum
 * start time and maximum end times are choosen.
 * @param node The span to start from.
 * @return A double array, will have length of 0 if no time annotations where found,
 *         one element of only start elements where found, 2 elements if both
 *         start and end time are found.
 */
public static double[] getOverlappedTime(SNode node) {
    SGraph graph = node.getGraph();
    final List<Double> startTimes = new LinkedList<>();
    final List<Double> endTimes = new LinkedList<>();
    List<SToken> token = new LinkedList<>();
    if (node instanceof SToken) {
        token.add((SToken) node);
    } else {
        List<SRelation<SNode, SNode>> outRelations = graph.getOutRelations(node.getId());
        if (outRelations != null) {
            for (SRelation<? extends SNode, ? extends SNode> e : outRelations) {
                if (e instanceof SSpanningRelation) {
                    SToken tok = ((SSpanningRelation) e).getTarget();
                    token.add(tok);
                }
            }
        }
    // end for each out relations
    }
    for (SToken tok : token) {
        SAnnotation anno = tok.getAnnotation(SaltUtil.createQName("annis", "time"));
        if (anno != null && anno.getValue_STEXT() != null && !anno.getValue_STEXT().isEmpty() && !anno.getValue_STEXT().matches("\\-[0-9]*(\\.[0-9]*)?")) {
            try {
                String[] split = anno.getValue_STEXT().split("-");
                if (split.length == 1) {
                    startTimes.add(Double.parseDouble(split[0]));
                }
                if (split.length == 2) {
                    startTimes.add(Double.parseDouble(split[0]));
                    endTimes.add(Double.parseDouble(split[1]));
                }
            } catch (NumberFormatException ex) {
                log.debug("Invalid time annotation", ex);
            }
        }
    }
    if (startTimes.size() > 0 && endTimes.size() > 0) {
        return new double[] { Collections.min(startTimes), Collections.max(endTimes) };
    } else if (startTimes.size() > 0) {
        return new double[] { Collections.min(startTimes) };
    }
    return new double[0];
}
Also used : SAnnotation(org.corpus_tools.salt.core.SAnnotation) LinkedList(java.util.LinkedList) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SGraph(org.corpus_tools.salt.core.SGraph)

Aggregations

SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)8 SToken (org.corpus_tools.salt.common.SToken)7 SRelation (org.corpus_tools.salt.core.SRelation)5 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)4 SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)4 SSpan (org.corpus_tools.salt.common.SSpan)4 SAnnotation (org.corpus_tools.salt.core.SAnnotation)4 RelannisNodeFeature (annis.model.RelannisNodeFeature)2 LinkedList (java.util.LinkedList)2 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)2 STextualRelation (org.corpus_tools.salt.common.STextualRelation)2 SFeature (org.corpus_tools.salt.core.SFeature)2 SNode (org.corpus_tools.salt.core.SNode)2 Test (org.junit.Test)2 GridEvent (annis.gui.widgets.grid.GridEvent)1 Row (annis.gui.widgets.grid.Row)1 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SOrderRelation (org.corpus_tools.salt.common.SOrderRelation)1