}
protected void updateHeuristicAnnotation(RuleMatch match, RuleElement element,
RutaStream stream, AnnotationFS matchedAnnotation, double deltaScore) {
Type heuristicType = stream.getJCas().getCasType(RutaAnnotation.type);
RutaAnnotation heuristicAnnotation = (RutaAnnotation) stream.getCas()
.createAnnotation(heuristicType, matchedAnnotation.getBegin(),
matchedAnnotation.getEnd());
Annotation newAnnotation = (Annotation) stream.getCas().createAnnotation(
type.getType(element.getParent()), heuristicAnnotation.getBegin(),
heuristicAnnotation.getEnd());
heuristicAnnotation.setScore(deltaScore);
heuristicAnnotation.setAnnotation(newAnnotation);
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(heuristicAnnotation,
heuristicType);
if (annotationsInWindow.isEmpty()) {
heuristicAnnotation.addToIndexes();
newAnnotation.addToIndexes();
stream.addAnnotation(newAnnotation, match);
} else {
RutaAnnotation tma = stream.getCorrectTMA(annotationsInWindow, heuristicAnnotation);
if (tma != null) {
tma.removeFromIndexes();
double newScore = tma.getScore() + deltaScore;
tma.setScore(newScore);
tma.addToIndexes();
} else {
heuristicAnnotation.addToIndexes();
newAnnotation.addToIndexes();
stream.addAnnotation(newAnnotation, match);
}