de.unistuttgart.quadrama.core.MergeSpeechAnnotations Maven / Gradle / Ivy
package de.unistuttgart.quadrama.core;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.util.JCasUtil;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.tcas.Annotation;
import de.unistuttgart.ims.drama.api.Speech;
import de.unistuttgart.ims.drama.api.StageDirection;
import de.unistuttgart.ims.drama.api.Utterance;
import de.unistuttgart.ims.uimautil.AnnotationComparator;
public class MergeSpeechAnnotations extends JCasAnnotator_ImplBase {
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Set toRemove = new HashSet();
for (Utterance utterance : JCasUtil.select(jcas, Utterance.class)) {
SortedSet annotations = new TreeSet(new AnnotationComparator());
annotations.addAll(JCasUtil.selectCovered(Speech.class, utterance));
annotations.addAll(JCasUtil.selectCovered(StageDirection.class, utterance));
Annotation lastAnnotation = null;
for (Annotation anno : annotations) {
if (lastAnnotation != null) {
if (lastAnnotation instanceof Speech && anno instanceof Speech) {
lastAnnotation.setEnd(anno.getEnd());
toRemove.add(anno);
} else
lastAnnotation = anno;
} else
lastAnnotation = anno;
}
}
for (Annotation a : toRemove)
a.removeFromIndexes();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy