gov.sandia.cognition.text.term
Class DefaultTermCounts

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

public class DefaultTermCounts
extends AbstractCloneableSerializable
implements TermCounts

A default implementation of the TermCounts interface.

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

Field Summary
protected  HashMap<Term,Integer> termToCountMap
          The mapping of terms to their respective counts.
protected  int totalCount
          The total of all counts.
 
Constructor Summary
DefaultTermCounts()
          Creates a new, empty DefaultTermCounts.
 
Method Summary
 void add(Termable term)
          Increments the count for a given term.
 void add(Term term, int count)
          Adds the given amount for the given term.
 void addAll(Iterable<? extends Termable> terms)
          Adds all of the given terms to the counters; one for each term occurrence.
 int getCount(Term term)
          Get the count for a given term.
 Set<Term> getTerms()
          Gets the set of all terms the counts are over.
protected  HashMap<Term,Integer> getTermToCountMap()
          Gets the mapping of terms to their respective counts.
 int getTotalCount()
          Gets the total count of all terms.
protected  void setTermToCountMap(HashMap<Term,Integer> termToCountMap)
          Gets the mapping of terms to their respective counts.
protected  void setTotalCount(int totalCount)
          Sets the total count.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalCount

protected int totalCount
The total of all counts.


termToCountMap

protected HashMap<Term,Integer> termToCountMap
The mapping of terms to their respective counts.

Constructor Detail

DefaultTermCounts

public DefaultTermCounts()
Creates a new, empty DefaultTermCounts.

Method Detail

add

public void add(Termable term)
Increments the count for a given term.

Parameters:
term - The term to add.

add

public void add(Term term,
                int count)
Adds the given amount for the given term.

Parameters:
term - The term to add.
count - The amount to add to the count of the term. Must be positive.

addAll

public void addAll(Iterable<? extends Termable> terms)
Adds all of the given terms to the counters; one for each term occurrence.

Parameters:
terms - The terms to add.

getCount

public int getCount(Term term)
Description copied from interface: TermCounts
Get the count for a given term.

Specified by:
getCount in interface TermCounts
Parameters:
term - The term to get the counts for.
Returns:
The counts for the given term, if it is known. Otherwise, 0.

getTerms

public Set<Term> getTerms()
Description copied from interface: TermCounts
Gets the set of all terms the counts are over.

Specified by:
getTerms in interface TermCounts
Returns:
The set of terms the counts are over.

getTotalCount

public int getTotalCount()
Description copied from interface: TermCounts
Gets the total count of all terms. It is the sum of the count for all terms that are known to this object.

Specified by:
getTotalCount in interface TermCounts
Returns:
The total count of all terms.

setTotalCount

protected void setTotalCount(int totalCount)
Sets the total count.

Parameters:
totalCount - The total count.

getTermToCountMap

protected HashMap<Term,Integer> getTermToCountMap()
Gets the mapping of terms to their respective counts.

Returns:
The mapping of terms to their respective counts.

setTermToCountMap

protected void setTermToCountMap(HashMap<Term,Integer> termToCountMap)
Gets the mapping of terms to their respective counts.

Parameters:
termToCountMap - The mapping of terms to their respective counts.