Class JCoReOverlapAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>

  • Type Parameters:
    E - The annotation type the index should be over.
    All Implemented Interfaces:
    JCoReAnnotationIndex<E>

    public class JCoReOverlapAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>
    extends java.lang.Object
    implements JCoReAnnotationIndex<E>

    Use when: You need to access arbitrary annotations that are in any way overlapped by an input annotation (warning: these quite loose restrictions cause a relatively high search complexity, see below).

    Note: If it can be guaranteed that the index elements do not overlap themselves, a JCoReSetAnnotationIndex with an Comparators.overlapComparator() should be used instead of this class.

    This index allows to index annotations and then retrieve all those annotations overlapping in any way with another annotation or an arbitrary given pair of begin and end offsets. Each search has the complexity O(n/2) where n is the size of the index. This rather bad complexity class stems from the fast that this class handles the general case of overlapping: Suppose we search for an annotation a that happens to be in the middle of the document. The only thing we know is that we can rule out all index elements then begin after a and those that end before a. All other annotations might still overlap a. We have to compare to all index elements from the beginning (or the end) up to the point where we know that we can omit the rest of the index elements. Those are - in the case a lies in the middle of the index elements - n/2.

    Author:
    faessler
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(E a)  
      void freeze()  
      void index​(E annotation)  
      void index​(org.apache.uima.jcas.JCas jCas, int type)
      Indexes the whole contents of the CAS annotation index of type type.
      void index​(org.apache.uima.jcas.JCas jCas, org.apache.uima.cas.Type type)
      Indexes the whole contents of the CAS annotation index of type type.
      void melt()
      Un-freeze the index to allow new elements to be added.
      <T extends org.apache.uima.jcas.tcas.Annotation>
      java.util.stream.Stream<E>
      search​(T a)
      Returns all annotation in the index overlapping in any way with a (embedded, covering, partial overlappings).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JCoReOverlapAnnotationIndex

        public JCoReOverlapAnnotationIndex()
      • JCoReOverlapAnnotationIndex

        public JCoReOverlapAnnotationIndex​(org.apache.uima.jcas.JCas jcas,
                                           int type)
      • JCoReOverlapAnnotationIndex

        public JCoReOverlapAnnotationIndex​(org.apache.uima.jcas.JCas jcas,
                                           org.apache.uima.cas.Type type)
    • Method Detail

      • index

        public void index​(org.apache.uima.jcas.JCas jCas,
                          int type)
        Indexes the whole contents of the CAS annotation index of type type. For each annotation, the #indexTermGenerator is used to create terms with which the annotation will be associated in the index and can be retrieved by a search method.
        Specified by:
        index in interface JCoReAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>
        Parameters:
        jCas - A CAS instance.
        type - The annotation type to index.
      • index

        public void index​(org.apache.uima.jcas.JCas jCas,
                          org.apache.uima.cas.Type type)
        Indexes the whole contents of the CAS annotation index of type type. For each annotation, the #indexTermGenerator is used to create terms with which the annotation will be associated in the index and can be retrieved by a search method.
        Specified by:
        index in interface JCoReAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>
        Parameters:
        jCas - A CAS instance.
        type - The annotation type to index.
      • index

        public void index​(E annotation)
        Specified by:
        index in interface JCoReAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>
      • freeze

        public void freeze()
      • search

        public <T extends org.apache.uima.jcas.tcas.Annotation> java.util.stream.Stream<E> search​(T a)
        Returns all annotation in the index overlapping in any way with a (embedded, covering, partial overlappings). The resulting list is either sorted by begin or end offset. It is not easily predictable which case it is (could be added as a return value if that would be useful in any way).
        Parameters:
        a - The annotation to retrieve overlapping annotations from the index for.
        Returns:
        All annotations in the index overlapping a.
      • melt

        public void melt()
        Un-freeze the index to allow new elements to be added.
      • add

        public void add​(E a)
        Specified by:
        add in interface JCoReAnnotationIndex<E extends org.apache.uima.jcas.tcas.Annotation>