org.terrier.structures
Class MapLexicon

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

public abstract class MapLexicon
extends Lexicon<String>
implements 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
          Interface for getting the lexicon term index for a given term id
protected static class MapLexicon.IdIsIndex
          Lexicon map where the termid is the term index
 
Field Summary
protected  WriteableFactory<org.apache.hadoop.io.Text> keyFactory
           
 
Constructor Summary
MapLexicon(Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap)
          Construct an instance of the class with
MapLexicon(Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap, MapLexicon.Id2EntryIndexLookup idlookupobject)
          Construct an instance of the class with
 
Method Summary
 void close()
          
 Map.Entry<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.
 Map.Entry<String,LexiconEntry> getLexiconEntry(int termid)
          Get the term and LexiconEntry (contains statistics and a pointer) for a given term id.
 LexiconEntry getLexiconEntry(String term)
          Get the LexiconEntry (contains statistics and a pointer) for the given term.
 Iterator<Map.Entry<String,LexiconEntry>> getLexiconEntryRange(String from, String to)
          Returns an iterator over a set of LexiconEntries within a range of entries in the lexicon.
 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(Map<org.apache.hadoop.io.Text,LexiconEntry> backingMap)
Construct an instance of the class with

Parameters:
backingMap -

MapLexicon

public MapLexicon(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(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<String>
Parameters:
term - key to lookup the lexicon with
Returns:
LexiconEntry for that term, or null if not found

getIthLexiconEntry

public Map.Entry<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<String>
Parameters:
index - the entry number to lookup in the lexicon
Returns:
Map.Entry tuple containing the term and the LexiconEntry

getLexiconEntryRange

public Iterator<Map.Entry<String,LexiconEntry>> getLexiconEntryRange(String from,
                                                                     String to)
Returns an iterator over a set of LexiconEntries within a range of entries in the lexicon.

Specified by:
getLexiconEntryRange in class Lexicon<String>
Parameters:
from - low endpoint term in the subset, inclusive.
to - high endpoint term in the subset, exclusive.
Returns:
Iterator over the set.

getLexiconEntry

public Map.Entry<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<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<String>

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Throws:
IOException


Terrier 3.6. Copyright © 2004-2011 University of Glasgow