Class AnnotationIndexImpl<T extends AnnotationFS>

java.lang.Object
org.apache.uima.cas.impl.AnnotationIndexImpl<T>
All Implemented Interfaces:
Iterable<T>, FSIndex<T>, AnnotationIndex<T>

public class AnnotationIndexImpl<T extends AnnotationFS> extends 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 Details

  • Constructor Details

    • AnnotationIndexImpl

      public AnnotationIndexImpl(FSIndex<T> index)
  • Method Details

    • size

      public int size()
      Description copied from interface: FSIndex
      Return the number of feature structures in this index.
      Specified by:
      size in interface FSIndex<T extends AnnotationFS>
      Returns:
      The number of FSs in this index.
    • getType

      public Type getType()
      Description copied from interface: FSIndex
      Return the type of feature structures this index contains.
      Specified by:
      getType in interface FSIndex<T extends AnnotationFS>
      Returns:
      The type of feature structures in this index.
    • contains

      public boolean contains(FeatureStructure fs)
      Description copied from interface: FSIndex
      Check 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:
      contains in interface FSIndex<T extends AnnotationFS>
      Parameters:
      fs - A Feature Structure used a template to match for equality with the FSs in the index.
      Returns:
      true if the index contains such an element.
    • find

      Description copied from interface: FSIndex
      Find 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:
      find in interface FSIndex<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 null if no such FS exists.
      See Also:
    • compare

      public int compare(FeatureStructure fs1, FeatureStructure fs2)
      Description copied from interface: FSIndex
      Compare 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:
      compare in interface FSIndex<T extends AnnotationFS>
      Parameters:
      fs1 - the first Feature Structure to compare
      fs2 - the second Feature Structure to compare
      Returns:
      -1 if fs1 < fs2; 0 if fs1 = fs2; 1 else.
    • iterator

      public FSIterator<T> iterator()
      Description copied from interface: FSIndex
      Return an iterator over the index. The iterator will be set to the start position of the index.
      Specified by:
      iterator in interface FSIndex<T extends AnnotationFS>
      Specified by:
      iterator in interface Iterable<T extends AnnotationFS>
      Returns:
      An iterator over the index.
    • iterator

      public FSIterator<T> iterator(FeatureStructure fs)
      Description copied from interface: FSIndex
      Return 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's get() method is greater than or equal to fs, and any previous FS is less than FS (the iterator is positioned at the earliest of equal values). If no such position exists, the iterator will be invalid.
      Specified by:
      iterator in interface FSIndex<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: FSIndex
      Return the indexing strategy.
      Specified by:
      getIndexingStrategy in interface FSIndex<T extends AnnotationFS>
      Returns:
      One of SORTED_INDEX, BAG_INDEX or SET_INDEX.
    • iterator

      public FSIterator<T> iterator(boolean ambiguous)
      Description copied from interface: AnnotationIndex
      Return 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 a previously, it will next return the smallest b s.t. a < b and a.getEnd() <= b.getBegin(). In other words, the b annotation's start will be large enough to not overlap the span of a.

      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:
      iterator in interface AnnotationIndex<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: AnnotationIndex
      Return a subiterator whose bounds are defined by the input annotation.

      The subiterator will return annotations b s.t. annot < b, annot.getBegin() <= b.getBegin() and annot.getEnd() >= b.getEnd(). For annotations x, y, x < y here is to be interpreted as "x comes before y in the index", according to the rules defined in the description of this class.

      This definition implies that annotations b that have the same span as annot may or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotation b if the type of annot precedes the type of b in the type priorities definition. If you have not specified the priority, or if annot and b are of the same type, then the behavior is undefined.

      For example, if you an annotation s of type Sentence and an annotation p of type Paragraph that have the same span, and you have defined Paragraph before Sentence in your type priorities, then subiterator(p) will give you an iterator that will return s, but subiterator(s) will give you an iterator that will NOT return p. The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the type priorities.

      Calling subiterator(a) is equivalent to calling subiterator(a, true, true).. See subiterator(AnnotationFS, boolean, boolean).

      Specified by:
      subiterator in interface AnnotationIndex<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: AnnotationIndex
      Return a subiterator whose bounds are defined by the input annotation.

      A strict subiterator is defined as follows: it will return annotations b s.t. annot < b, annot.getBegin() <= b.getBegin() and annot.getEnd() >= b.getEnd(). For annotations x,y, x < y here is to be interpreted as "x comes before y in the index", according to the rules defined in the description of this class.

      If strict is set to false, the boundary conditions are relaxed as follows: return annotations b s.t. annot < b and annot.getBegin() <= b.getBegin() <= annot.getEnd(). The resulting iterator may also be disambiguated.

      These definitions imply that annotations b that have the same span as annot may or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotation b if the type of annot precedes the type of b in the type priorities definition. If you have not specified the priority, or if annot and b are of the same type, then the behavior is undefined.

      For example, if you an annotation s of type Sentence and an annotation p of type Paragraph that have the same span, and you have defined Paragraph before Sentence in your type priorities, then subiterator(p) will give you an iterator that will return s, but subiterator(s) will give you an iterator that will NOT return p. The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the type priorities.

      Specified by:
      subiterator in interface AnnotationIndex<T extends AnnotationFS>
      Parameters:
      annot - Annotation setting boundary conditions for subiterator.
      ambiguous - If set to false, 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: AnnotationIndex
      Create an annotation tree with annot as 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:
      tree in interface AnnotationIndex<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.
    • addChildren

      private void addChildren(AnnotationTreeNodeImpl<T> node, FSIterator<T> it)
    • withSnapshotIterators

      public FSIndex<T> withSnapshotIterators()
      Description copied from interface: FSIndex
      Creates a shared copy of this FSIndex configured to produce snapshot iterators that don't throw ConcurrentModificationExceptions.
      Specified by:
      withSnapshotIterators in interface FSIndex<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.