Search in sources :

Example 1 with STimelineRelation

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

the class TimelineReconstructor method convertSpanToToken.

private void convertSpanToToken(SStructuredNode span, String orderName) {
    final Set<String> validSpanAnnos = new HashSet<>(order2spanAnnos.get(orderName));
    if (!nodesToDelete.contains(span)) {
        nodesToDelete.add(span);
        if (textsByName.get(orderName) == null) {
            STextualDS newText = graph.createTextualDS("");
            newText.setName(orderName);
            textsByName.put(orderName, newText);
            textDataByName.put(orderName, new StringBuilder());
        }
        STextualDS textDS = textsByName.get(orderName);
        StringBuilder textData = textDataByName.get(orderName);
        TreeSet<Integer> coveredIdx = new TreeSet<>(spans2TimelinePos.get(span));
        if (!coveredIdx.isEmpty()) {
            SAnnotation textValueAnno = getTextValueAnno(orderName, span);
            if (textValueAnno != null) {
                String textValue = textValueAnno.getValue_STEXT();
                int startTextIdx = textData.length();
                textData.append(textValue);
                int endTextIdx = textData.length();
                SToken newToken = graph.createToken(textDS, startTextIdx, endTextIdx);
                // keep track of changed ids for matches
                if (this.matchIDs.contains(span.getId()))
                    this.oldID2newID.put(span.getId(), newToken.getId());
                // move all features to the new token
                if (span.getFeatures() != null) {
                    for (SFeature feat : span.getFeatures()) {
                        if (!"salt".equals(feat.getNamespace())) {
                            newToken.addFeature(feat);
                        }
                    }
                }
                // move all annotations to the new token
                if (span.getAnnotations() != null) {
                    for (SAnnotation annot : span.getAnnotations()) {
                        if (!"salt".equals(annot.getNamespace()) && !orderName.equals(annot.getName())) {
                            newToken.addAnnotation(annot);
                        }
                    }
                }
                STimelineRelation timeRel = SaltFactory.createSTimelineRelation();
                timeRel.setSource(newToken);
                timeRel.setTarget(graph.getTimeline());
                timeRel.setStart(coveredIdx.first());
                timeRel.setEnd(coveredIdx.last());
                graph.addRelation(timeRel);
                moveRelations(span, newToken, validSpanAnnos, orderName);
            }
        }
    }
}
Also used : SAnnotation(org.corpus_tools.salt.core.SAnnotation) SToken(org.corpus_tools.salt.common.SToken) TreeSet(java.util.TreeSet) STextualDS(org.corpus_tools.salt.common.STextualDS) STimelineRelation(org.corpus_tools.salt.common.STimelineRelation) HashSet(java.util.HashSet) SFeature(org.corpus_tools.salt.core.SFeature)

Aggregations

HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 STextualDS (org.corpus_tools.salt.common.STextualDS)1 STimelineRelation (org.corpus_tools.salt.common.STimelineRelation)1 SToken (org.corpus_tools.salt.common.SToken)1 SAnnotation (org.corpus_tools.salt.core.SAnnotation)1 SFeature (org.corpus_tools.salt.core.SFeature)1