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);
}
}
}
}
Aggregations