Class AnnotationIndexImpl<T extends AnnotationFS>
- java.lang.Object
-
- org.apache.uima.cas.impl.AnnotationIndexImpl<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,FSIndex<T>,AnnotationIndex<T>
public class AnnotationIndexImpl<T extends AnnotationFS> extends java.lang.Object implements AnnotationIndex<T>
Implementation of annotation indexes. A wrapper not an extend, because the constructor argument index has customization for additional fns and a ref to it's enclosing instance of the FSIndexRepositoryImpl.
-
-
Field Summary
-
Fields inherited from interface org.apache.uima.cas.FSIndex
BAG_INDEX, DEFAULT_BAG_INDEX, SET_INDEX, SORTED_INDEX
-
-
Constructor Summary
Constructors Constructor Description AnnotationIndexImpl(FSIndex<T> index)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(FeatureStructure fs1, FeatureStructure fs2)Compare two feature structures according to the ordering relation of the index.booleancontains(FeatureStructure fs)Check if the index contains an element equal to the given feature structure according to the comparators defined for this index.FeatureStructurefind(FeatureStructure fs)Find an entry in the index "equal to" the given feature structure according to the comparators specified for this index.intgetIndexingStrategy()Return the indexing strategy.TypegetType()Return the type of feature structures this index contains.FSIterator<T>iterator()Return an iterator over the index.FSIterator<T>iterator(boolean ambiguous)Return an iterator over annotations that can be constrained to be unambiguous.FSIterator<T>iterator(FeatureStructure fs)Return an iterator over the index.intsize()Return the number of feature structures in this index.FSIterator<T>subiterator(AnnotationFS annot)Return a subiterator whose bounds are defined by the input annotation.FSIterator<T>subiterator(AnnotationFS annot, boolean ambiguous, boolean strict)Return a subiterator whose bounds are defined by theannot.AnnotationTree<T>tree(T annot)Create an annotation tree withannotas root node.FSIndex<T>withSnapshotIterators()Creates a shared copy of this FSIndex configured to produce snapshot iterators that don't throw ConcurrentModificationExceptions.
-
-
-
Method Detail
-
size
public int size()
Description copied from interface:FSIndexReturn the number of feature structures in this index.- Specified by:
sizein interfaceFSIndex<T extends AnnotationFS>- Returns:
- The number of FSs in this index.
-
getType
public Type getType()
Description copied from interface:FSIndexReturn the type of feature structures this index contains.- Specified by:
getTypein interfaceFSIndex<T extends AnnotationFS>- Returns:
- The type of feature structures in this index.
-
contains
public boolean contains(FeatureStructure fs)
Description copied from interface:FSIndexCheck if the index contains an element equal to the given feature structure according to the comparators defined for this index. For bag indexes (which have no comparators), the equality test means the identical feature structure. Note that this is in general not the same as feature structure identity.- Specified by:
containsin interfaceFSIndex<T extends AnnotationFS>- Parameters:
fs- A Feature Structure used a template to match for equality with the FSs in the index.- Returns:
trueif the index contains such an element.
-
find
public FeatureStructure find(FeatureStructure fs)
Description copied from interface:FSIndexFind an entry in the index "equal to" the given feature structure according to the comparators specified for this index. Note that this is in general not the same as feature structure identity. For BAG indexes, it is identity, for others it means the found feature structure compares equal with the parameter in terms of the defined comparators for the index.- Specified by:
findin interfaceFSIndex<T extends AnnotationFS>- Parameters:
fs- A Feature Structure used a template to match with the Feature Structures in the index.- Returns:
- A FS equal to the template argument, or
nullif no such FS exists. - See Also:
FSIterator.moveTo(FeatureStructure)
-
compare
public int compare(FeatureStructure fs1, FeatureStructure fs2)
Description copied from interface:FSIndexCompare two feature structures according to the ordering relation of the index. If the input feature structures are not of the type of the index, the result is undefined.- Specified by:
comparein interfaceFSIndex<T extends AnnotationFS>- Parameters:
fs1- the first Feature Structure to comparefs2- the second Feature Structure to compare- Returns:
-1iffs1 < fs2;0iffs1 = fs2;1else.
-
iterator
public FSIterator<T> iterator()
Description copied from interface:FSIndexReturn an iterator over the index. The iterator will be set to the start position of the index.- Specified by:
iteratorin interfaceFSIndex<T extends AnnotationFS>- Specified by:
iteratorin interfacejava.lang.Iterable<T extends AnnotationFS>- Returns:
- An iterator over the index.
-
iterator
public FSIterator<T> iterator(FeatureStructure fs)
Description copied from interface:FSIndexReturn an iterator over the index. The position of the iterator will be set such that the feature structure returned by a call to the iterator'sget()method is greater than or equal tofs, and any previous FS is less thanFS(the iterator is positioned at the earliest of equal values). If no such position exists, the iterator will be invalid.- Specified by:
iteratorin interfaceFSIndex<T extends AnnotationFS>- Parameters:
fs- The feature structure at which the iterator should be positioned.- Returns:
- An iterator positioned at
fs, if it exists. An invalid iterator, else.
-
getIndexingStrategy
public int getIndexingStrategy()
Description copied from interface:FSIndexReturn the indexing strategy.- Specified by:
getIndexingStrategyin interfaceFSIndex<T extends AnnotationFS>- Returns:
- One of
SORTED_INDEX,BAG_INDEXorSET_INDEX.
-
iterator
public FSIterator<T> iterator(boolean ambiguous)
Description copied from interface:AnnotationIndexReturn an iterator over annotations that can be constrained to be unambiguous.A disambiguated iterator is defined as follows. The first annotation returned is the same as would be returned by the corresponding ambiguous iterator. If the unambiguous iterator has returned
apreviously, it will next return the smallestbs.t. a < b and a.getEnd() <= b.getBegin(). In other words, thebannotation's start will be large enough to not overlap the span ofa.An unambiguous iterator makes a snapshot copy of the index containing just the disambiguated items, and iterates over that. It doesn't check for concurrent index modifications (the ambiguous iterator does check for this).
- Specified by:
iteratorin interfaceAnnotationIndex<T extends AnnotationFS>- Parameters:
ambiguous- If set to false, iterator will be unambiguous.- Returns:
- A annotation iterator.
-
subiterator
public FSIterator<T> subiterator(AnnotationFS annot)
Description copied from interface:AnnotationIndexReturn a subiterator whose bounds are defined by the input annotation.The
annotis used for 3 purposes:- It is used to compute the position in the index where the iteration starts.
- It is used to compute end point where the iterator stops when moving forward.
- It is used to specify which annotations will be skipped while iterating.
The starting position is computed by first finding a position whose annotation compares equal with the
annot(this might be one of several), and then advancing until reaching a position where the annotation there is not equal to theannot. If no item in the index is equal (meaning it has the same begin, the same end, and is the same type as theannot) then the iterator is positioned to the first annotation which is greater than theannot, or if there are no annotations greater than theannot, the iterator is marked invalid.The iterator will stop (become invalid) when
- it runs out of items in the index going forward or backwards, or
- while moving forward, it reaches a point where the annotation at that position has a
start is beyond the
annot'send position, or - while moving backwards, it reaches a position in front of its original starting position.
While iterating, it operates like a
strictiterator; annotations whose end positions are > the end position ofannotare skipped.This is equivalent to returning annotations
bsuch thatannot < b, andannot.getEnd() >= b.getBegin(), skippingb'swhose end position is > annot.getEnd().
For annotations x, y,
x < yhere is to be interpreted as "x comes before y in the index", according to the rules defined in the description ofthis class.This definition implies that annotations
bthat have the same span asannotmay or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotationbif the type ofannotprecedes the type ofbin the type priorities definition. If you have not specified the priority, or ifannotandbare of the same type, then the behavior is undefined.For example, if you have an annotation
Sof typeSentenceand an annotationPof typeParagraphthat have the same span, and you have definedParagraphbeforeSentencein your type priorities, thensubiterator(P)will give you an iterator that will returnS, butsubiterator(S)will give you an iterator that will NOT returnP. The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the type priorities.Calling
subiterator(a)is equivalent to callingsubiterator(a, true, true).. Seesubiterator(AnnotationFS, boolean, boolean).- Specified by:
subiteratorin interfaceAnnotationIndex<T extends AnnotationFS>- Parameters:
annot- Defines the boundaries of the subiterator.- Returns:
- A subiterator.
-
subiterator
public FSIterator<T> subiterator(AnnotationFS annot, boolean ambiguous, boolean strict)
Description copied from interface:AnnotationIndexReturn a subiterator whose bounds are defined by theannot.The
annotis used in 2 or 3 ways.- It specifies the left-most position in the index where the iteration starts.
- It specifies an end point where the iterator stops.
- If
strictis specified, the end point also specifies which annotations will be skipped while iterating.
The starting position is computed by first finding the position whose annotation compares equal with the
annot, and then advancing until reaching a position where the annotation there is not equal to theannot. If no item in the index is equal (meaning it has the same begin, the same end, and is the same type as theannot) then the iterator is positioned to the first annotation which is greater than theannot, or if there are no annotations greater than theannot, the iterator is marked invalid.The iterator will stop (become invalid) when
- it runs out of items in the index going forward or backwards, or
- while moving forward, it reaches a point where the annotation at that position has a
start is beyond the
annot'send position, or - while moving backwards, it reaches a position in front of its original starting position
Ignoring
strictandambiguousfor a moment, this is equivalent to returning annotationsbsuch thatannot < busing the standard annotation comparator, andannot.getEnd() >= b.getBegin(), and also bounded by the index itself.
A
strictsubiterator skips annotations whereannot.getEnd() < b.getEnd().A
ambiguous = falsespecification produces an unambiguous iterator, which computes a subset of the annotations, going forward, such that annotations whosebeginis contained within the previous returned annotation's span, are skipped.For annotations x,y,
x < yhere is to be interpreted as "x comes before y in the index", according to the rules defined in the description ofthis class.If
strict = truethen annotations whose end is >annot.getEnd()are skipped.These definitions imply that annotations
bthat have the same span asannotmay or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotationbif the type ofannotprecedes the type ofbin the type priorities definition. If you have not specified the priority, or ifannotandbare of the same type, then the behavior is undefined.For example, if you have an annotation
Sof typeSentenceand an annotationPof typeParagraphthat have the same span, and you have definedParagraphbeforeSentencein your type priorities, thensubiterator(P)will give you an iterator that will returnS, butsubiterator(S)will give you an iterator that will NOT returnP. The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the type priorities.- Specified by:
subiteratorin interfaceAnnotationIndex<T extends AnnotationFS>- Parameters:
annot- Annotation setting boundary conditions for subiterator.ambiguous- If set tofalse, resulting iterator will be unambiguous.strict- Controls if annotations that overlap to the right are considered in or out.- Returns:
- A subiterator.
-
tree
public AnnotationTree<T> tree(T annot)
Description copied from interface:AnnotationIndexCreate an annotation tree withannotas root node. The tree is defined as follows: for each node in the tree, the children are the sequence of annotations that would be obtained from a strict, unambiguous subiterator of the node's annotation.- Specified by:
treein interfaceAnnotationIndex<T extends AnnotationFS>- Parameters:
annot- The annotation at the root of the tree. This must be of type T or a subtype- Returns:
- The annotation tree rooted at
annot.
-
withSnapshotIterators
public FSIndex<T> withSnapshotIterators()
Description copied from interface:FSIndexCreates a shared copy of this FSIndex configured to produce snapshot iterators that don't throw ConcurrentModificationExceptions.- Specified by:
withSnapshotIteratorsin interfaceFSIndex<T extends AnnotationFS>- Returns:
- a light-weight copy of this FSIndex, configured such that any iterator created using it will be a snapshot iterator - one where a snapshot is made of the state of the index at the time the iterator is created, and where subsequent modifications to the underlying index are allowed, but don't affect the iterator (which iterates over the read-only snapshot). Iterators produced with this won't throw ConcurrentModificationExceptions.
-
-