|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.stanford.nlp.stats.AbstractCounter<E>
edu.stanford.nlp.stats.IntCounter<E>
public class IntCounter<E>
A specialized kind of hash table (or map) for storing numeric counts for objects. It works like a Map, but with different methods for easily getting/setting/incrementing counts for objects and computing various functions with the counts. The Counter constructor and addAll method can be used to copy another Counter's contents over. This class also provides access to Comparators that can be used to sort the keys or entries of this Counter by the counts, in either ascending or descending order.
| Constructor Summary | |
|---|---|
IntCounter()
Constructs a new (empty) Counter. |
|
IntCounter(IntCounter<E> c)
Constructs a new Counter with the contents of the given Counter. |
|
IntCounter(MapFactory<E,MutableInteger> mapFactory)
Pass in a MapFactory and the map it vends will back your counter. |
|
| Method Summary | |
|---|---|
void |
addAll(IntCounter<E> counter)
Adds the counts in the given Counter to the counts in this Counter. |
E |
argmax()
Finds and returns the key in this Counter with the largest count. |
E |
argmax(java.util.Comparator<E> tieBreaker)
Finds and returns the key in this Counter with the largest count. |
E |
argmin()
Finds and returns the key in this Counter with the smallest count. |
E |
argmin(java.util.Comparator<E> tieBreaker)
Finds and returns the key in this Counter with the smallest count. |
double |
averageCount()
Returns the mean of all the counts (totalCount/size). |
void |
clear()
Removes all counts from this Counter. |
java.lang.Object |
clone()
|
boolean |
containsKey(E key)
Returns whether a Counter contains a key. |
double |
decrementCount(E key)
Subtracts 1 from the count for the given key. |
int |
decrementCount(E key,
int count)
Subtracts the given count from the current count for the given key. |
void |
decrementCounts(java.util.Collection<E> keys)
Subtracts 1 from the counts of each of the given keys. |
void |
decrementCounts(java.util.Collection<E> keys,
int count)
Subtracts the given count from the current counts for each of the given keys. |
double |
defaultReturnValue()
Returns the default return value. |
double |
doubleMax()
|
java.util.Set<java.util.Map.Entry<E,java.lang.Double>> |
entrySet()
Returns a view of the doubles in this map. |
boolean |
equals(java.lang.Object o)
|
double |
getCount(java.lang.Object key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
java.lang.String |
getCountAsString(E key)
|
Factory<Counter<E>> |
getFactory()
Returns a factory that can create new instances of this kind of Counter. |
int |
getIntCount(java.lang.Object key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
MapFactory<E,MutableInteger> |
getMapFactory()
|
double |
getNormalizedCount(E key)
This has been de-deprecated in order to reduce compilation warnings, but really you should create a Distribution instead of using this method. |
int |
hashCode()
|
double |
incrementCount(E key)
Adds 1 to the count for the given key. |
double |
incrementCount(E key,
double value)
Increments the count for the given key by the given value. |
int |
incrementCount(E key,
int count)
Adds the given count to the current count for the given key. |
void |
incrementCounts(java.util.Collection<E> keys)
Adds 1 to the counts for each of the given keys. |
void |
incrementCounts(java.util.Collection<E> keys,
int count)
Adds the given count to the current counts for each of the given keys. |
boolean |
isEmpty()
|
java.util.Iterator<E> |
iterator()
|
java.util.Set<E> |
keysAbove(int countThreshold)
Returns the set of keys whose counts are at or above the given threshold. |
java.util.Set<E> |
keysAt(int count)
Returns the set of keys that have exactly the given count. |
java.util.Set<E> |
keysBelow(int countThreshold)
Returns the set of keys whose counts are at or below the given threshold. |
java.util.Set<E> |
keySet()
Returns the Set of keys in this counter. |
int |
max()
Finds and returns the largest count in this Counter. |
int |
min()
Finds and returns the smallest count in this Counter. |
void |
prettyLog(Redwood.RedwoodChannels channels,
java.lang.String description)
Pretty logs the current object to specific Redwood channels. |
double |
remove(E key)
Removes the given key from this Counter. |
void |
removeAll(java.util.Collection<E> c)
Removes all the given keys from this Counter. |
void |
removeZeroCounts()
Removes all keys whose count is 0. |
void |
setCount(E key,
double value)
Sets the count for the given key to be the given value. |
void |
setCount(E key,
int count)
Sets the current count for the given key. |
void |
setCount(E key,
java.lang.String s)
|
void |
setCounts(java.util.Collection<E> keys,
int count)
Sets the current count for each of the given keys. |
void |
setDefaultReturnValue(double rv)
Sets the default return value. |
void |
setDefaultReturnValue(int rv)
|
int |
size()
Returns the number of entries stored in this counter. |
void |
subtractAll(IntCounter<E> counter)
Subtracts the counts in the given Counter from the counts in this Counter. |
java.lang.String |
toString()
|
java.lang.String |
toString(java.text.NumberFormat nf)
|
java.lang.String |
toString(java.text.NumberFormat nf,
java.lang.String preAppend,
java.lang.String postAppend,
java.lang.String keyValSeparator,
java.lang.String itemSeparator)
|
double |
totalCount()
Computes the total of all counts in this counter, and returns it as a double. |
double |
totalCount(Filter<E> filter)
|
double |
totalDoubleCount()
|
double |
totalDoubleCount(Filter<E> filter)
|
int |
totalIntCount()
Returns the current total count for all objects in this Counter. |
int |
totalIntCount(Filter<E> filter)
Returns the total count for all objects in this Counter that pass the given Filter. |
java.util.Collection<java.lang.Double> |
values()
Returns a copy of the values currently in this counter. |
| Methods inherited from class edu.stanford.nlp.stats.AbstractCounter |
|---|
addAll, decrementCount, logIncrementCount |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IntCounter()
public IntCounter(MapFactory<E,MutableInteger> mapFactory)
public IntCounter(IntCounter<E> c)
| Method Detail |
|---|
public MapFactory<E,MutableInteger> getMapFactory()
public void setDefaultReturnValue(double rv)
Counter
setDefaultReturnValue in interface Counter<E>rv - The default valuepublic void setDefaultReturnValue(int rv)
public double defaultReturnValue()
Counter
defaultReturnValue in interface Counter<E>public int totalIntCount()
public double totalDoubleCount()
public int totalIntCount(Filter<E> filter)
totalCount().
public double totalDoubleCount(Filter<E> filter)
public double totalCount(Filter<E> filter)
public double averageCount()
public double getCount(java.lang.Object key)
get that casts
and extracts the primitive value.
getCount in interface Counter<E>key - The key
public java.lang.String getCountAsString(E key)
public int getIntCount(java.lang.Object key)
get that casts
and extracts the primitive value.
public double getNormalizedCount(E key)
Distribution instead of using this method.
public void setCount(E key,
int count)
incrementCount(Object,int).
public void setCount(E key,
java.lang.String s)
public void setCounts(java.util.Collection<E> keys,
int count)
incrementCounts(Collection,int).
public int incrementCount(E key,
int count)
incrementCount(Object).
To set a count to a specific value instead of incrementing it, use
setCount(Object,int).
public double incrementCount(E key)
incrementCount(Object,int).
To set a count to a specific value instead of incrementing it, use
setCount(Object,int).
incrementCount in interface Counter<E>incrementCount in class AbstractCounter<E>key - The key to increment by 1.0
public void incrementCounts(java.util.Collection<E> keys,
int count)
incrementCounts(Collection).
To set the counts of a collection of objects to a specific value instead
of incrementing them, use setCounts(Collection,int).
public void incrementCounts(java.util.Collection<E> keys)
incrementCounts(Collection,int).
To set the counts of a collection of objects to a specific value instead
of incrementing them, use setCounts(Collection,int).
public int decrementCount(E key,
int count)
decrementCount(Object).
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int).
public double decrementCount(E key)
decrementCount(Object,int).
To set a count to a specifc value instead of decrementing it, use
setCount(Object,int).
decrementCount in interface Counter<E>decrementCount in class AbstractCounter<E>key - The key to decrement by 1.0
public void decrementCounts(java.util.Collection<E> keys,
int count)
decrementCounts(Collection).
To set the counts of a collection of objects to a specific value instead
of decrementing them, use setCounts(Collection,int).
public void decrementCounts(java.util.Collection<E> keys)
decrementCounts(Collection,int).
To set the counts of a collection of objects to a specifc value instead
of decrementing them, use setCounts(Collection,int).
public void addAll(IntCounter<E> counter)
public void subtractAll(IntCounter<E> counter)
public boolean containsKey(E key)
Counter
containsKey in interface Counter<E>key - The key
public double remove(E key)
remove in interface Counter<E>key - The key
public void removeAll(java.util.Collection<E> c)
public void clear()
clear in interface Counter<E>public int size()
Counter
size in interface Counter<E>public boolean isEmpty()
public java.util.Set<E> keySet()
Counter
keySet in interface Counter<E>public java.util.Set<java.util.Map.Entry<E,java.lang.Double>> entrySet()
entrySet in interface Counter<E>public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
public java.lang.String toString(java.text.NumberFormat nf,
java.lang.String preAppend,
java.lang.String postAppend,
java.lang.String keyValSeparator,
java.lang.String itemSeparator)
public java.lang.String toString(java.text.NumberFormat nf)
public java.lang.Object clone()
clone in class java.lang.Objectpublic void removeZeroCounts()
public int max()
public double doubleMax()
public int min()
public E argmax(java.util.Comparator<E> tieBreaker)
public E argmax()
argmax(Comparator). Returns null if this Counter is empty.
public E argmin(java.util.Comparator<E> tieBreaker)
public E argmin()
argmin(Comparator). Returns null if this Counter is empty.
public java.util.Set<E> keysAbove(int countThreshold)
public java.util.Set<E> keysBelow(int countThreshold)
public java.util.Set<E> keysAt(int count)
public Factory<Counter<E>> getFactory()
Counter
getFactory in interface Counter<E>
public void setCount(E key,
double value)
CounterCounter.incrementCount(Object,double).
setCount in interface Counter<E>key - The keyvalue - The count
public double incrementCount(E key,
double value)
CounterCounter.incrementCount(Object).
To set a count to a specific value instead of incrementing it, use
Counter.setCount(Object,double).
incrementCount in interface Counter<E>incrementCount in class AbstractCounter<E>key - The key to incrementvalue - The amount to increment it by
public double totalCount()
Counter
totalCount in interface Counter<E>public java.util.Collection<java.lang.Double> values()
Counter
values in interface Counter<E>public java.util.Iterator<E> iterator()
public void prettyLog(Redwood.RedwoodChannels channels,
java.lang.String description)
prettyLog in interface PrettyLoggablechannels - the channels which should be logged to -- all logging calls should
use logging methods on the channels (e.g. channels.log(), etc.)description - The description of the object. It will potentially identify the
object's functional role or (failing that) its class. This is
typically used as a track name surrounding the contents of this
object.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||