Class MapLexicon<K1,​K2 extends org.apache.hadoop.io.WritableComparable>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<java.util.Map.Entry<K1,​LexiconEntry>>
    Direct Known Subclasses:
    FSOMapFileLexiconGeneric, MemoryLexicon

    public abstract class MapLexicon<K1,​K2 extends org.apache.hadoop.io.WritableComparable>
    extends Lexicon<K1>
    implements java.io.Closeable
    Implementation of a lexicon. This class should be subclassed by any lexicon implementation which use a java.util.Map for storing entries.
    Since:
    3.0
    Author:
    Craig Macdonald
    • Field Detail

      • keyFactory

        protected WriteableFactory<K2 extends org.apache.hadoop.io.WritableComparable> keyFactory
      • modificationLock

        protected java.lang.Object modificationLock
      • map

        protected final java.util.Map<K2 extends org.apache.hadoop.io.WritableComparable,​LexiconEntry> map
    • Constructor Detail

      • MapLexicon

        public MapLexicon​(java.util.Map<K2,​LexiconEntry> backingMap)
        Construct an instance of the class with
        Parameters:
        backingMap -
    • Method Detail

      • getLexiconEntry

        public LexiconEntry getLexiconEntry​(K1 term)
        Returns the LexiconEntry (containing statistics and a pointer) for the given term. Returns null if the term is not present in the lexicon.
        Specified by:
        getLexiconEntry in class Lexicon<K1>
        Parameters:
        term - the key to lookup the lexicon with
        Returns:
        LexiconEntry for that term, or null if the term is not present in the lexicon.
      • getIthLexiconEntry

        public java.util.Map.Entry<K1,​LexiconEntry> getIthLexiconEntry​(int index)
        Returns the term and LexiconEntry (containing statistics and a pointer) for the entry in the lexicon with the specified index. Throws NoSuchElementException is the termid is not found.
        Specified by:
        getIthLexiconEntry in class Lexicon<K1>
        Parameters:
        index - the entry number to lookup in the lexicon.
        Returns:
        the Map.Entry containing the term and the LexiconEntry.
      • getLexiconEntryRange

        public java.util.Iterator<java.util.Map.Entry<K1,​LexiconEntry>> getLexiconEntryRange​(K1 from,
                                                                                                   K1 to)
        Returns an iterator over a set of LexiconEntries within a range of entries in the lexicon.
        Specified by:
        getLexiconEntryRange in class Lexicon<K1>
        Parameters:
        from - low endpoint term in the subset, inclusive.
        to - high endpoint term in the subset, exclusive.
        Returns:
        a Iterator over the set of Map.Entrys.
      • getLexiconEntry

        public java.util.Map.Entry<K1,​LexiconEntry> getLexiconEntry​(int termid)
        Returns the term and LexiconEntry (containing statistics and a pointer) for the given term id. Throws NoSuchElementException is the termid is not found.
        Specified by:
        getLexiconEntry in class Lexicon<K1>
        Parameters:
        termid - the term id to lookup in the lexicon.
        Returns:
        the Map.Entry containing the term and the LexiconEntry.
      • numberOfEntries

        public int numberOfEntries()
        Return the number of terms in the lexicon.
        Specified by:
        numberOfEntries in class Lexicon<K1>
        Returns:
        the number of terms in the lexicon.
      • toK1

        protected abstract K1 toK1​(K2 key)
      • setK2

        protected abstract void setK2​(K1 key,
                                      K2 instance)
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException