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 interface
MapLexicon.Id2EntryIndexLookup
Interface for getting the lexicon term index for a given term idprotected static class
MapLexicon.IdIsIndex
Lexicon 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>
keyFactory
protected java.util.Map<K2,LexiconEntry>
map
protected java.lang.Object
modificationLock
-
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 void
close()
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.LexiconEntry
getLexiconEntry(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.int
numberOfEntries()
Return the number of terms in the lexicon.protected abstract void
setK2(K1 key, K2 instance)
protected void
setTermIdLookup(MapLexicon.Id2EntryIndexLookup idlookupobject)
protected abstract K1
toK1(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. Returnsnull
if the term is not present in the lexicon.- Specified by:
getLexiconEntry
in classLexicon<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 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:
getIthLexiconEntry
in classLexicon<K1>
- Parameters:
index
- the entry number to lookup in the lexicon.- Returns:
- the
Map.Entry
containing 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:
getLexiconEntryRange
in classLexicon<K1>
- 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.
-
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:
getLexiconEntry
in classLexicon<K1>
- Parameters:
termid
- the term id to lookup in the lexicon.- Returns:
- the
Map.Entry
containing the term and theLexiconEntry
.
-
numberOfEntries
public int numberOfEntries()
Return the number of terms in the lexicon.- Specified by:
numberOfEntries
in classLexicon<K1>
- Returns:
- the number of terms in the lexicon.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-