If you do not want to use uimaFIT, you can create a filtered iterator to view the annotations of interest. UIMA reference documentation is here: UIMA reference documentation
I recently used this approach in some code to find a sentence annotation that covered a regular expression annotation (this approach was acceptable for our project because all regular expression matches were shorter than the sentences in the document and there was only one regular match per sentence Obviously, based on indexing rules, your mileage may vary. If you are afraid of running into another shorterAnnotationType , put the internal code in the while loop):
static ArrayList<annotationsPair> process(Annotation shorterAnnotationType, Annotation longerAnnotationType, JCas aJCas){ ArrayList<annotationsPair> annotationsList = new ArrayList<annotationsPair>(); FSIterator it = aJCas.getAnnotationIndex().iterator(); FSTypeConstraint constraint = aJCas.getConstraintFactory().createTypeConstraint(); constraint.add(shorterAnnotationType.getType()); constraint.add(longerAnnotationType.getType()); it = aJCas.createFilteredIterator(it, constraint); Annotation a = null; int shorterBegin = -1; int shorterEnd = -1; it.moveTo((shorterAnnotationType)); while (it.isValid()) { a = (Annotation) it.get(); if (a.getClass() == shorterAnnotationType.getClass()){ shorterBegin = a.getBegin(); shorterEnd = a.getEnd(); System.out.println("Target annotation from " + shorterBegin + " to " + shorterEnd);
Hope this helps! Disclaimer: I am new to UIMA.
source share