// filter out document annotation!!
FSIterator<AnnotationFS> it = aCas.getAnnotationIndex().iterator();
Type tokenType = tmTokenAnnotation.getType();
FSIterator<AnnotationFS> leftIt = null;
FSIterator<AnnotationFS> rightIt = null;
TypeSystem ts = aCas.getTypeSystem();
Type tmRootType = ts.getType(RUTA_ALL_TYPE_NAME);
Set<String> allFilters = new HashSet<String>();
allFilters.add("uima.tcas.DocumentAnnotation");
allFilters.add(RutaEngine.BASIC_TYPE);
if (filterSet != null)
allFilters.addAll(filterSet);
for (; it.isValid(); it.moveToNext()) {
AnnotationFS fs = (AnnotationFS) it.get();
if (fs.getBegin() == tmTokenAnnotation.getBegin()
&& fs.getEnd() == tmTokenAnnotation.getEnd() && fs.getType().equals(tokenType)) {
leftIt = it;
rightIt = it.copy();
break;
}
}
if (leftIt == null)
return null; // the token annotation was not found !
if (leftIt.isValid())
leftIt.moveToPrevious(); // leave our token annotation behind us...
// search from the token annotation to the left
for (; leftIt.isValid(); leftIt.moveToPrevious()) {
AnnotationFS fs = (AnnotationFS) leftIt.get();
if (fs.getEnd() <= tmTokenAnnotation.getBegin())
break; // if that happens we are out of reach and can stop
if (fs.getBegin() <= tmTokenAnnotation.getBegin()
&& fs.getEnd() >= tmTokenAnnotation.getEnd()
&& !allFilters.contains(fs.getType().getName())
&& !ts.subsumes(tmRootType, fs.getType()))
result.add(fs);
}
// search from the token annotation to the right
if (rightIt.isValid())
rightIt.moveToNext(); // leave our token annotation behind us...
for (; rightIt.isValid(); rightIt.moveToNext()) {
AnnotationFS fs = (AnnotationFS) rightIt.get();
if (fs.getBegin() >= tmTokenAnnotation.getEnd())
break; // if that happens we are out of reach and can stop
if (fs.getBegin() <= tmTokenAnnotation.getBegin()
&& fs.getEnd() >= tmTokenAnnotation.getEnd()
&& !allFilters.contains(fs.getType().getName())
&& !ts.subsumes(tmRootType, fs.getType()))
result.add(fs);
}
return result;
}