/** * Removes all annotations of type removeAnnotationType which are contained by annotations of type * containerAnnotationType. * * @param cas * @param containerAnnotationType * @param removeAnnotationType */ public static void removeAnnotations( CAS cas, AnnotationFS containerAnnotation, Type removeAnnotationType) { FSIndex<AnnotationFS> allRemoveAnnotations = cas.getAnnotationIndex(removeAnnotationType); ContainingConstraint containingConstraint = new ContainingConstraint(containerAnnotation); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator(allRemoveAnnotations.iterator(), containingConstraint); Collection<AnnotationFS> removeAnnotations = new LinkedList<AnnotationFS>(); while (containingTokens.hasNext()) { removeAnnotations.add(containingTokens.next()); } for (Iterator<AnnotationFS> it = removeAnnotations.iterator(); it.hasNext(); ) { cas.removeFsFromIndexes(it.next()); } }