org.terrier.structures
Class MapLexicon

java.lang.Object
  extended by org.terrier.structures.Lexicon<java.lang.String>
      extended by org.terrier.structures.MapLexicon
All Implemented Interfaces:
java.io.Closeable, java.lang.Iterable<java.util.Map.Entry<java.lang.String,LexiconEntry>>
Direct Known Subclasses:
FSOMapFileLexicon

public abstract class MapLexicon
extends Lexicon<java.lang.String>
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
protected static interface MapLexicon.Id2EntryIndexLookup
           
protected static class MapLexicon.IdIsIndex
           
 
Field Summary
protected  WriteableFactory<org.apache.hadoop.io.Text> keyFactory
           
 
Constructor Summary
MapLexicon(java.util.Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap)
          Construct an instance of the class with
MapLexicon(java.util.Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap, MapLexicon.Id2EntryIndexLookup idlookupobject)
          Construct an instance of the class with
 
Method Summary
 void close()
          
 java.util.Map.Entry<java.lang.String,LexiconEntry> getIthLexiconEntry(int index)
          Get the term and LexiconEntry (contains statistics and a pointer) for the entry in the lexicon with the specified index.
 java.util.Map.Entry<java.lang.String,LexiconEntry> getLexiconEntry(int termid)
          Get the term and LexiconEntry (contains statistics and a pointer) for a given term id.
 LexiconEntry getLexiconEntry(java.lang.String term)
          Get the LexiconEntry (contains statistics and a pointer) for the given term.
 int numberOfEntries()
          Return the number of entries in the lexicon
protected  void setTermIdLookup(MapLexicon.Id2EntryIndexLookup idlookupobject)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

keyFactory

protected WriteableFactory<org.apache.hadoop.io.Text> keyFactory
Constructor Detail

MapLexicon

public MapLexicon(java.util.Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap)
Construct an instance of the class with

Parameters:
backingMap -

MapLexicon

public MapLexicon(java.util.Map<org.apache.hadoop.io.Text,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(java.lang.String term)
Get the LexiconEntry (contains statistics and a pointer) for the given term. Returns null if the term is not found in the lexicon.

Specified by:
getLexiconEntry in class Lexicon<java.lang.String>
Parameters:
term - key to lookup the lexicon with
Returns:
LexiconEntry for that term, or null if not found

getIthLexiconEntry

public java.util.Map.Entry<java.lang.String,LexiconEntry> getIthLexiconEntry(int index)
Get the term and LexiconEntry (contains 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<java.lang.String>
Parameters:
index - the entry number to lookup in the lexicon
Returns:
Map.Entry tuple containing the term and the LexiconEntry

getLexiconEntry

public java.util.Map.Entry<java.lang.String,LexiconEntry> getLexiconEntry(int termid)
Get the term and LexiconEntry (contains statistics and a pointer) for a given term id. Throws NoSuchElementException is the termid is not found.

Specified by:
getLexiconEntry in class Lexicon<java.lang.String>
Parameters:
termid - the term id to lookup in the lexicon
Returns:
Map.Entry tuple containing the term and the LexiconEntry

numberOfEntries

public int numberOfEntries()
Return the number of entries in the lexicon

Specified by:
numberOfEntries in class Lexicon<java.lang.String>

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException


Terrier 3.5. Copyright © 2004-2011 University of Glasgow