gov.sandia.cognition.text.term
Class DefaultTermIndex

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.text.term.AbstractTermIndex
          extended by gov.sandia.cognition.text.term.DefaultTermIndex
All Implemented Interfaces:
TermIndex, CloneableSerializable, Serializable, Cloneable

public class DefaultTermIndex
extends AbstractTermIndex

A default implementation of the TermIndex interface.

Since:
3.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  List<DefaultIndexedTerm> termList
          The list of terms ordered by indices.
protected  Map<Term,DefaultIndexedTerm> termMap
          The mapping of terms to their corresponding (unique) indices.
 
Constructor Summary
DefaultTermIndex()
          Creates a new, empty DefaultTermIndex.
 
Method Summary
 IndexedTerm add(Term term)
          Adds the given term to the index.
 DefaultTermIndex clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 DefaultIndexedTerm getIndexedTerm(int index)
          Gets the index-term pair for the given index.
 DefaultIndexedTerm getIndexedTerm(Term term)
          Gets the index-term pair for the given term, if it is in the index.
 int getTermCount()
          Gets the number of terms.
protected  List<DefaultIndexedTerm> getTermList()
          Sets the list of terms, ordered by index.
protected  Map<Term,DefaultIndexedTerm> getTermMap()
          Gets the mapping of terms to their indices.
 List<DefaultIndexedTerm> getTerms()
          Gets all of the terms in the index.
protected  void setTermList(List<DefaultIndexedTerm> termList)
          Gets the list of terms, ordered by index.
protected  void setTermMap(Map<Term,DefaultIndexedTerm> termMap)
          Sets the mapping of terms to their indices.
 
Methods inherited from class gov.sandia.cognition.text.term.AbstractTermIndex
add, addAll, getIndex, getIndex, getIndexedTerm, getTerm, hasIndex, hasIndexedTerm, hasTerm, hasTerm
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

termMap

protected Map<Term,DefaultIndexedTerm> termMap
The mapping of terms to their corresponding (unique) indices.


termList

protected List<DefaultIndexedTerm> termList
The list of terms ordered by indices.

Constructor Detail

DefaultTermIndex

public DefaultTermIndex()
Creates a new, empty DefaultTermIndex.

Method Detail

clone

public DefaultTermIndex clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

add

public IndexedTerm add(Term term)
Description copied from interface: TermIndex
Adds the given term to the index. The returned value will be the index of that term and if it is not in the index already, it will be added.

Parameters:
term - The term to add.
Returns:
The index of the term.

getTermCount

public int getTermCount()
Description copied from interface: TermIndex
Gets the number of terms.

Returns:
The total number of terms.

getTerms

public List<DefaultIndexedTerm> getTerms()
Description copied from interface: TermIndex
Gets all of the terms in the index.

Returns:
A list of all the terms in the index.

getIndexedTerm

public DefaultIndexedTerm getIndexedTerm(Term term)
Description copied from interface: TermIndex
Gets the index-term pair for the given term, if it is in the index. Otherwise, null is returned.

Parameters:
term - The term to get the index-term pair for.
Returns:
The index-term pair for the given term, if it is in the index. Otherwise, null.

getIndexedTerm

public DefaultIndexedTerm getIndexedTerm(int index)
Description copied from interface: TermIndex
Gets the index-term pair for the given index.

Parameters:
index - The index to get the index-term pair for.
Returns:
The index-term pair for the given index.

getTermMap

protected Map<Term,DefaultIndexedTerm> getTermMap()
Gets the mapping of terms to their indices.

Returns:
The mapping of terms to their indices.

setTermMap

protected void setTermMap(Map<Term,DefaultIndexedTerm> termMap)
Sets the mapping of terms to their indices.

Parameters:
termMap - The mapping of terms to their indices.

getTermList

protected List<DefaultIndexedTerm> getTermList()
Sets the list of terms, ordered by index.

Returns:
The list of terms, ordered by index.

setTermList

protected void setTermList(List<DefaultIndexedTerm> termList)
Gets the list of terms, ordered by index.

Parameters:
termList - The list of terms, ordered by index.