Package org.terrier.structures
Class MapLexicon<K1,K2 extends org.apache.hadoop.io.WritableComparable>
- java.lang.Object
-
- org.terrier.structures.Lexicon<K1>
-
- org.terrier.structures.MapLexicon<K1,K2>
-
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceMapLexicon.Id2EntryIndexLookupInterface for getting the lexicon term index for a given term idprotected static classMapLexicon.IdIsIndexLexicon map where the termid is the term index-
Nested classes/interfaces inherited from class org.terrier.structures.Lexicon
Lexicon.LexiconFileEntry<KEY2>
-
-
Field Summary
Fields Modifier and Type Field Description protected WriteableFactory<K2>keyFactoryprotected java.util.Map<K2,LexiconEntry>mapprotected java.lang.ObjectmodificationLock
-
Constructor Summary
Constructors Constructor Description MapLexicon(java.util.Map<K2,LexiconEntry> backingMap)Construct an instance of the class withMapLexicon(java.util.Map<K2,LexiconEntry> backingMap, MapLexicon.Id2EntryIndexLookup idlookupobject)Construct an instance of the class with
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()java.util.Map.Entry<K1,LexiconEntry>getIthLexiconEntry(int index)Returns the term andLexiconEntry(containing statistics and a pointer) for the entry in the lexicon with the specified index.java.util.Map.Entry<K1,LexiconEntry>getLexiconEntry(int termid)Returns the term andLexiconEntry(containing statistics and a pointer) for the given term id.LexiconEntrygetLexiconEntry(K1 term)Returns theLexiconEntry(containing statistics and a pointer) for the given term.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.intnumberOfEntries()Return the number of terms in the lexicon.protected abstract voidsetK2(K1 key, K2 instance)protected voidsetTermIdLookup(MapLexicon.Id2EntryIndexLookup idlookupobject)protected abstract K1toK1(K2 key)
-
-
-
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-
-
MapLexicon
public MapLexicon(java.util.Map<K2,LexiconEntry> backingMap, MapLexicon.Id2EntryIndexLookup idlookupobject)
Construct an instance of the class with- Parameters:
backingMap-idlookupobject-
-
-
Method Detail
-
setTermIdLookup
protected void setTermIdLookup(MapLexicon.Id2EntryIndexLookup idlookupobject)
-
getLexiconEntry
public LexiconEntry getLexiconEntry(K1 term)
Returns theLexiconEntry(containing statistics and a pointer) for the given term. Returnsnullif the term is not present in the lexicon.- Specified by:
getLexiconEntryin classLexicon<K1>- Parameters:
term- the key to lookup the lexicon with- Returns:
- LexiconEntry for that term, or
nullif the term is not present in the lexicon.
-
getIthLexiconEntry
public java.util.Map.Entry<K1,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.- Specified by:
getIthLexiconEntryin classLexicon<K1>- Parameters:
index- the entry number to lookup in the lexicon.- Returns:
- the
Map.Entrycontaining the term and theLexiconEntry.
-
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:
getLexiconEntryRangein classLexicon<K1>- Parameters:
from- low endpoint term in the subset, inclusive.to- high endpoint term in the subset, exclusive.- Returns:
- a
Iteratorover the set ofMap.Entrys.
-
getLexiconEntry
public java.util.Map.Entry<K1,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.- Specified by:
getLexiconEntryin classLexicon<K1>- Parameters:
termid- the term id to lookup in the lexicon.- Returns:
- the
Map.Entrycontaining the term and theLexiconEntry.
-
numberOfEntries
public int numberOfEntries()
Return the number of terms in the lexicon.- Specified by:
numberOfEntriesin classLexicon<K1>- Returns:
- the number of terms in the lexicon.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-