List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(null,
element.getContainer());
for (AnnotationFS matchedAnnotation : matchedAnnotations) {
StringBuilder newDocument = new StringBuilder();
RutaStream windowStream = stream.getWindowStream(matchedAnnotation,
stream.getDocumentAnnotationType());
windowStream.moveToFirst();
CAS newCAS = targetEngine.newCAS();
List<Type> types = newCAS.getTypeSystem()
.getProperlySubsumedTypes(newCAS.getAnnotationType());
Collection<AnnotationFS> fsToAdd = new HashSet<AnnotationFS>();
Map<Integer, Integer> new2oldBegin = new TreeMap<Integer, Integer>();
Map<Integer, Integer> new2oldEnd = new TreeMap<Integer, Integer>();
Map<Integer, Integer> old2newBegin = new TreeMap<Integer, Integer>();
Map<Integer, Integer> old2newEnd = new TreeMap<Integer, Integer>();
int localBegin = 0;
int localEnd = 0;
while (windowStream.isValid()) {
FeatureStructure fs = windowStream.get();
if (fs instanceof RutaBasic) {
RutaBasic basic = (RutaBasic) fs;
for (Type type : types) {
Collection<AnnotationFS> beginAnchors = basic.getBeginAnchors(type);
for (AnnotationFS a : beginAnchors) {
if (a != null && !a.getType().getName().equals("uima.tcas.DocumentAnnotation")
&& !(a instanceof RutaBasic)) {
fsToAdd.add(a);
}
}
}
int length = basic.getEnd() - basic.getBegin();
localEnd = localBegin + length;
new2oldBegin.put(localBegin, basic.getBegin());
old2newBegin.put(basic.getBegin(), localBegin);
new2oldEnd.put(localEnd, basic.getEnd());
old2newEnd.put(basic.getEnd(), localEnd);
newDocument.append(basic.getCoveredText());
localBegin += length;
}
windowStream.moveToNext();
}
String string = newDocument.toString();
newCAS.setDocumentText(string);
for (AnnotationFS each : fsToAdd) {