Class JCoReTreeMapAnnotationIndex<K extends java.lang.Comparable<K>,​T extends org.apache.uima.jcas.tcas.Annotation>

  • Type Parameters:
    T - The annotation type the index is over.
    K - The key type used to index the annotations.
    All Implemented Interfaces:
    JCoReAnnotationIndex<T>

    public class JCoReTreeMapAnnotationIndex<K extends java.lang.Comparable<K>,​T extends org.apache.uima.jcas.tcas.Annotation>
    extends JCoReMapAnnotationIndex<K,​T>

    Use when: You want a fuzzy search on the index keys (please see the note in the next paragraph) or ou specifically need a TreeMap instead of a HashMap (if not, refer to JCoReHashMapAnnotationIndex) for some other reason. This only makes sense when you need to impose a specific ordering on the map keys that is useful for one of the searchFuzzy methods (e.g. searchFuzzy(Annotation)). This index allows to match multiple map keys with a single input key, for example by using a Comparators.longOverlapComparator() for the TreeMap and TermGenerators.longOffsetTermGenerator() for the keys.

    PLEASE NOTE: In order to retrieve the correct results, the index TreeSet comparator must be consistent with equals with regards to the index keys (see the JavaDoc to Comparator). That means, it does not need to be consistent with equals for the search key (in fact, not being consistent with the search key is the trick) but results will be undefined if the comparator is not consistent with equals with regards to the keys in the index.

    A trivial subclass of JCoReMapAnnotationIndex that uses a HashMap index.
    Author:
    faessler
    • Constructor Detail

      • JCoReTreeMapAnnotationIndex

        public JCoReTreeMapAnnotationIndex​(IndexTermGenerator<K> indexTermGenerator,
                                           IndexTermGenerator<K> searchTermGenerator,
                                           org.apache.uima.jcas.JCas jCas,
                                           org.apache.uima.cas.Type type)
      • JCoReTreeMapAnnotationIndex

        public JCoReTreeMapAnnotationIndex​(IndexTermGenerator<K> indexTermGenerator,
                                           IndexTermGenerator<K> searchTermGenerator,
                                           org.apache.uima.jcas.JCas jCas,
                                           int type)
      • JCoReTreeMapAnnotationIndex

        public JCoReTreeMapAnnotationIndex​(java.util.Comparator<K> comparator,
                                           IndexTermGenerator<K> indexTermGenerator,
                                           IndexTermGenerator<K> searchTermGenerator,
                                           org.apache.uima.jcas.JCas jCas,
                                           org.apache.uima.cas.Type type)
      • JCoReTreeMapAnnotationIndex

        public JCoReTreeMapAnnotationIndex​(java.util.Comparator<K> comparator,
                                           IndexTermGenerator<K> indexTermGenerator,
                                           IndexTermGenerator<K> searchTermGenerator,
                                           org.apache.uima.jcas.JCas jCas,
                                           int type)
    • Method Detail

      • searchFuzzy

        public java.util.stream.Stream<T> searchFuzzy​(org.apache.uima.jcas.tcas.Annotation a)
      • searchFuzzy

        public java.util.stream.Stream<T> searchFuzzy​(java.util.stream.Stream<K> searchTerms)
      • searchFuzzy

        public java.util.stream.Stream<T> searchFuzzy​(K key)

        Returns all annotations associated with an index key that is equal to the given key by means of the comparator given to the TreeMap that is used as an index.

        If that comparator is consistent with equals (see the JavaDoc to Comparator) the index will basically return the same results how a HashMap would. However, if the comparator is in general not consistent with equals, but it is for all elements in the index, and the index keys for which holds index.comparator().compare(indexkey, key) == 0 are located in the index without a gap between them (i.e. no indexkey that would not return 0 on comparison with key), then this method will return all annotations for the matching keys. This can be used to retrieve overlapping annotations, for example.

        Parameters:
        key - The key to retrieve annotations for.
        Returns:
        All annotations associated with an index key where index.comparator().compare(indexkey, key) == 0.