Class Subiterator<T extends AnnotationFS>

java.lang.Object
org.apache.uima.cas.impl.FSIteratorImplBase<T>
org.apache.uima.cas.impl.Subiterator<T>
All Implemented Interfaces:
Iterator<T>, FSIterator<T>

public class Subiterator<T extends AnnotationFS> extends FSIteratorImplBase<T>
Subiterator implementation. There are two bounding styles and 2 underlying forms. The 2nd form is produced lazily when needed, and is made by a one-time forward traversal to compute unambigious subsets and store them into a list. - The 2nd form is needed only for unambiguous style if backwards or moveto(fs) operation. The 1st form uses the underlying iterator directly, and does skipping as needed, while iterating - going forward: skip if unambigious and start is within prev span skip if strict and end lies outside of scope span - going backward: if unambiguous - convert to form 2 skip if strict and end lies outside of scope span - going to particular fs (left most match) if unambiguous - convert to form 2 skip (forward) if strict and end lies outside of scope span - going to first: unambiguous - no testing needed, no prior span skip if strict and end lies outside of scope span - going to last: unambigious - convert to 2nd form skip backwards if strict and end lies outside of scope span There are two styles of the bounding information. - the traditional one uses the standard comparator for annotations: begin (ascending), end (descending) and type priority ordering - the 2nd style uses just a begin value and an end value, no type priority ordering.
  • Field Details

    • list

      private ArrayList<T extends AnnotationFS> list
    • pos

      private int pos
    • it

      private final FSIteratorImplBase<T extends AnnotationFS> it
    • fsIndexRepo

      private final FSIndexRepositoryImpl fsIndexRepo
    • boundingAnnotation

      private final AnnotationFS boundingAnnotation
    • boundingBegin

      private final int boundingBegin
    • boundingEnd

      private final int boundingEnd
    • prevEnd

      private int prevEnd
    • ambiguous

      private final boolean ambiguous
    • strict

      private final boolean strict
    • isBounded

      private final boolean isBounded
    • isListForm

      private boolean isListForm
    • isBeginEndCompare

      private final boolean isBeginEndCompare
  • Constructor Details

    • Subiterator

      Subiterator(FSIterator<T> it, AnnotationFS boundingAnnotation, int boundingBegin, int boundingEnd, boolean ambiguous, boolean strict, boolean isBounded, FSIndexRepositoryImpl fsIndexRepo)
      Constructor called with annot == null and boundingBegin and boundingEnd specified, or called with annot != null (boundingBegin/End ignored) if annot == null, then this implies the comparisons should use just begin and end (not type priorities) and the range is inclusive with the begin/ end boundaries != null, then this implies the comparisons use the normal Annotation compare and the range is exclusive on the left with the boundaries.
      Parameters:
      it - the iterator to use
      boundingAnnotation - null or the bounding annotation
      boundingBegin - if boundingAnnotation is null, this is used as the bounding begin (inclusive); ignored if boundingAnnotation is not null
      boundingEnd - if annot is null, this is used as the bounding end (inclusive); ignored if boundingAnnotation is not null
      ambiguous - true means normal iteration, false means to skip annotations whose begin lies between previous begin (inclusive) and end (exclusive)
      strict - true means to skip annotations whose end is greater than the bounding end position (ignoring type priorities)
      isBounded - false means its an unambiguous iterator with no bounds narrowing; ambiguous taken to be false
      fsIndexRepo - the index repository for this iterator
  • Method Details

    • convertToListForm

      private void convertToListForm()
      Converting to list form - called for unambiguous iterator going backwards, unambiguous iterator doing a moveTo(fs) operation iterator doing a moveToLast() operation
    • moveToExact

      private void moveToExact(FeatureStructureImpl targetAnnotation)
    • moveToStart

      private void moveToStart()
      Move to the starting position of the sub iterator Annotation bounding: move to the annotation, then move forwards until you're at an element not equal to the annot. (by definition of the iterator) and adjust for strict
    • setPrevEnd

      private void setPrevEnd()
    • movePastAnnot

      private void movePastAnnot()
      For subiterators bounded by Annotations, the starting place is the item past the elements that are equal to the the bounding annot, adjusted for strict exclusions
    • getAnnotationComparator

      private Comparator<AnnotationFS> getAnnotationComparator()
    • adjustAfterMoveToForBeginEndComparator

      private void adjustAfterMoveToForBeginEndComparator(AnnotationFS fs)
      Called for begin/end compare, after moveTo(fs) to eliminate the effect of the type order comparison before any adjustment for strict. Move backwards while equal with begin/end iterator.
    • adjustForStrictForward

      private void adjustForStrictForward()
      For strict mode, advance iterator until the end is within the bounding end
    • movePastPrevAnnotation

      private void movePastPrevAnnotation()
      For unambiguous, going forwards
    • adjustForStrictBackward

      private void adjustForStrictBackward()
    • isValid

      public boolean isValid()
      Description copied from interface: FSIterator
      Check if this iterator is valid.
      Returns:
      true if the iterator is valid.
    • get

      public T get() throws NoSuchElementException
      Description copied from interface: FSIterator
      Get the structure the iterator is pointing at.
      Returns:
      The structure the iterator is pointing at.
      Throws:
      NoSuchElementException - If the iterator is not valid.
    • moveToNext

      public void moveToNext()
      Description copied from interface: FSIterator
      Advance the iterator. This may invalidate the iterator.
    • moveToPrevious

      public void moveToPrevious()
      Description copied from interface: FSIterator
      Move the iterator one element back. This may invalidate the iterator.
    • moveToFirst

      public void moveToFirst()
      Description copied from interface: FSIterator
      Move the iterator to the first element. The iterator will be valid iff the underlying collection is non-empty. Allowed even if the underlying indexes being iterated over were modified.
    • moveToLast

      public void moveToLast()
      Description copied from interface: FSIterator
      Move the iterator to the last element. The iterator will be valid iff the underlying collection is non-empty. Allowed even if the underlying indexes being iterated over were modified.
    • getAnnotationBeginEndComparator

      static Comparator<AnnotationFS> getAnnotationBeginEndComparator(int boundingBegin, int boundingEnd)
    • moveTo

      public void moveTo(FeatureStructure fs)
      Description copied from interface: FSIterator
      Move the iterator to the first Feature Structure that is equal to fs. First means the earliest one occurring in the index, in case multiple FSs that are "equal" to fs are in the index. If no such feature structure exists in the underlying collection, set the iterator to the "insertion point" for fs, i.e., to a point where the current feature structure is greater than fs, and the previous one is less than fs.

      If the fs is greater than all of the entries in the index, the moveTo cannot set the iterator to an insertion point where the current feature structure is greater than fs, so it marks the iterator "invalid".

      If the underlying index is a bag index, no ordering is present, and the moveTo operation moves to the fs which is the same identical fs as the key. If no such fs is in the index, the iterator is marked invalid.

      Parameters:
      fs - The feature structure the iterator that supplies the comparison information. It must be of type T or a subtype of T.
    • moveTo

      <TT extends AnnotationFS> void moveTo(int begin, int end)
      Description copied from class: FSIteratorImplBase
      A special version of moveTo for subtypes of AnnotationFS, which moves to a particular begin/end (no type priority).
      Overrides:
      moveTo in class FSIteratorImplBase<T extends AnnotationFS>
      Parameters:
      begin - the starting point (inclusive)
      end - the ending point (inclusive)
    • copy

      public FSIterator<T> copy()
      Description copied from interface: FSIterator
      Copy this iterator.
      Returns:
      A copy of this iterator, pointing at the same element.