An annotation index provides additional iterator functionality that applies only to instances of
uima.tcas.Annotation
. You can obtain an AnnotationIndex by calling:
AnnotationIndex idx = (AnnotationIndex)cas.getAnnotationIndex();
(the typecast is necessary for historical reasons).
Note that the AnnotationIndex defines the following sort order between two annotations:
- Annotations are sorted in increasing order of their start offset. That is, for any annotations a and b, if
a.start < b.start
then a < b
. - Annotations whose start offsets are equal are next sorted by decreasing order of their end offsets. That is, if
a.start = b.start
and a.end > b.end
, then a < b
. This causes annotations with larger to be sorted before annotations with smaller spans, which produces an iteration order similar to a preorder tree traversal. - Annotations whose start offsets are equal and whose end offsets are equal are sorted based on {@link org.apache.uima.resource.metadata.TypePriorities} (which is an element of the componentdescriptor). That is, if
a.start = b.start
, a.end = b.end
, and the type of a
is defined before the type of b
in the type priorities, then a < b
. -
- If none of the above rules apply, then the ordering is arbitrary. This will occur if you have two annotations of the exact same type that also have the same span. It will also occur if you have not defined any type priority between two annotations that have the same span.
In the method descriptions below, the notation
a < b
, where
a
and
b
are annotations, should be taken to mean
a
comes before
b
in the index, according to the above rules.