Package org.terrier.structures
Class Lexicon<KEY>
- java.lang.Object
-
- org.terrier.structures.Lexicon<KEY>
-
- Type Parameters:
KEY
- the type of the key. Usually String to denote a term.
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Iterable<java.util.Map.Entry<KEY,LexiconEntry>>
- Direct Known Subclasses:
MapLexicon
,MultiLexicon
public abstract class Lexicon<KEY> extends java.lang.Object implements java.io.Closeable, java.lang.Iterable<java.util.Map.Entry<KEY,LexiconEntry>>
A lexicon (a.k.a. dictionary, vocabulary) typically represents the list of terms in the index, together with their statistics (seeEntryStatistics
) and the pointer (Pointer
) to the offset of that term's postings in thePostingIndex
returned byIndex.getInvertedIndex()
. TheEntryStatistics
andPointer
are combined in a singleLexiconEntry
object. This class is an abstract class implementing a lexicon.- Since:
- 1.0.0
- Author:
- Craig Macdonald
- See Also:
EntryStatistics
,Pointer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Lexicon.LexiconFileEntry<KEY2>
-
Constructor Summary
Constructors Constructor Description Lexicon()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract java.util.Map.Entry<KEY,LexiconEntry>
getIthLexiconEntry(int index)
Returns the term andLexiconEntry
(containing statistics and a pointer) for the entry in the lexicon with the specified index.abstract java.util.Map.Entry<KEY,LexiconEntry>
getLexiconEntry(int termid)
Returns the term andLexiconEntry
(containing statistics and a pointer) for the given term id.abstract LexiconEntry
getLexiconEntry(KEY term)
Returns theLexiconEntry
(containing statistics and a pointer) for the given term.abstract java.util.Iterator<java.util.Map.Entry<KEY,LexiconEntry>>
getLexiconEntryRange(KEY from, KEY to)
Returns an iterator over a set of LexiconEntries within a range of entries in the lexicon.abstract int
numberOfEntries()
Return the number of terms in the lexicon.
-
-
-
Method Detail
-
numberOfEntries
public abstract int numberOfEntries()
Return the number of terms in the lexicon.- Returns:
- the number of terms in the lexicon.
-
getLexiconEntry
public abstract LexiconEntry getLexiconEntry(KEY term)
Returns theLexiconEntry
(containing statistics and a pointer) for the given term. Returnsnull
if the term is not present in the lexicon.- 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.
-
getLexiconEntry
public abstract java.util.Map.Entry<KEY,LexiconEntry> getLexiconEntry(int termid)
Returns the term andLexiconEntry
(containing statistics and a pointer) for the given term id. Throws NoSuchElementException is the termid is not found.- Parameters:
termid
- the term id to lookup in the lexicon.- Returns:
- the
Map.Entry
containing the term and theLexiconEntry
.
-
getIthLexiconEntry
public abstract java.util.Map.Entry<KEY,LexiconEntry> getIthLexiconEntry(int index)
Returns the term andLexiconEntry
(containing statistics and a pointer) for the entry in the lexicon with the specified index. Throws NoSuchElementException is the termid is not found.- Parameters:
index
- the entry number to lookup in the lexicon.- Returns:
- the
Map.Entry
containing the term and theLexiconEntry
.
-
getLexiconEntryRange
public abstract java.util.Iterator<java.util.Map.Entry<KEY,LexiconEntry>> getLexiconEntryRange(KEY from, KEY to)
Returns an iterator over a set of LexiconEntries within a range of entries in the lexicon.- Parameters:
from
- low endpoint term in the subset, inclusive.to
- high endpoint term in the subset, exclusive.- Returns:
- a
Iterator
over the set ofMap.Entry
s.
-
-