|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.stats.Counter<E>
public class Counter<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.
Implementation note: Note that this class stores atotalCount
field as well as the map. This makes certain
operations much more efficient, but means that any methods that change the
map must also update totalCount
appropriately.
Constructor Summary | |
---|---|
Counter()
Constructs a new (empty) Counter. |
|
Counter(GenericCounter<E> c)
Constructs a new Counter with the contents of the given Counter. |
|
Counter(MapFactory mapFactory)
Pass in a MapFactory and the map it vends will back your counter. |
Method Summary | |
---|---|
void |
addAll(GenericCounter<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 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 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()
|
java.util.Comparator |
comparator()
Comparator that sorts objects by (increasing) count. |
java.util.Comparator |
comparator(boolean ascending)
Returns a comparator suitable for sorting this Counter's keys or entries by their respective counts. |
java.util.Comparator |
comparator(boolean ascending,
boolean useMagnitude)
Returns a comparator suitable for sorting this Counter's keys or entries by their respective value or magnitude (unsigned value). |
boolean |
containsKey(E key)
|
void |
decrementCount(E key)
Subtracts 1.0 from the count for the given key. |
void |
decrementCount(E key,
double count)
Subtracts the given count from the current count for the given key. |
void |
decrementCounts(java.util.Collection<E> keys)
Subtracts 1.0 from the counts of each of the given keys. |
void |
decrementCounts(java.util.Collection<E> keys,
double count)
Subtracts the given count from the current counts for each of the given keys. |
void |
divideBy(Counter<E> counter)
Divides every non-zero count by the count for the corresponding key in the argument Counter. |
double |
doubleMax()
Returns the value of the maximum entry in this counter, as a double. |
java.util.Set<java.util.Map.Entry<E,MutableDouble>> |
entrySet()
|
boolean |
equals(java.lang.Object o)
|
double |
getCount(E 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)
Returns the count for this key as a String. |
MapFactory |
getMapFactory()
Returns the MapFactory used by this counter. |
double |
getNormalizedCount(E key)
Return the proportion of the Counter mass under this key. |
int |
hashCode()
|
void |
incrementAll(double count)
Adds the same amount to every count, that is to every key currently stored in the counter (with no lookups). |
void |
incrementCount(E key)
Adds 1.0 to the count for the given key. |
void |
incrementCount(E key,
double count)
Adds the given count to the current count for the given key. |
void |
incrementCounts(java.util.Collection<E> keys)
Adds 1.0 to the counts for each of the given keys. |
void |
incrementCounts(java.util.Collection<E> keys,
double count)
Adds the given count to the current counts for each of the given keys. |
boolean |
isEmpty()
|
java.util.Set<E> |
keysAbove(double countThreshold)
Returns the set of keys whose counts are at or above the given threshold. |
java.util.Set<E> |
keysAt(double count)
Returns the set of keys that have exactly the given count. |
java.util.Set<E> |
keysBelow(double 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. |
static void |
main(java.lang.String[] args)
For internal debugging purposes only. |
double |
max()
Finds and returns the largest count in this Counter. |
double |
min()
Finds and returns the smallest count in this Counter. |
void |
multiplyBy(double d)
|
void |
normalize()
This has been de-deprecated in order to reduce compilation warnings, but really you should create a Distribution
instead. |
MutableDouble |
remove(E key)
Removes the given key from this Counter. |
void |
removeAll(java.util.Collection<E> keys)
Removes all the given keys from this Counter. |
void |
removeZeroCounts()
Removes all keys whose count is 0. |
void |
setCount(E key,
double count)
Sets the current count for the given key. |
void |
setCount(E key,
java.lang.String s)
Sets the count for this key to be the number encoded in the given String. |
void |
setCounts(java.util.Collection<E> keys,
double count)
Sets the current count for each of the given keys. |
int |
size()
Returns the number of keys stored in the counter. |
void |
subtractAll(Counter<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)
Pretty print a Counter. |
java.lang.String |
toString(java.text.NumberFormat nf,
java.lang.String preAppend,
java.lang.String postAppend,
java.lang.String keyValSeparator,
java.lang.String itemSeparator)
Pretty print a Counter. |
double |
totalCount()
Returns the current total count for all objects in this Counter. |
double |
totalCount(Filter<E> filter)
Returns the total count for all objects in this Counter that pass the given Filter. |
double |
totalDoubleCount()
Computes the total of all counts in this counter, and returns it as a double. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Counter()
public Counter(MapFactory mapFactory)
public Counter(GenericCounter<E> c)
Method Detail |
---|
public MapFactory getMapFactory()
GenericCounter
getMapFactory
in interface GenericCounter<E>
public double totalCount()
public double totalDoubleCount()
GenericCounter
totalDoubleCount
in interface GenericCounter<E>
public double totalCount(Filter<E> filter)
totalCount()
.
public double averageCount()
public double getCount(E key)
get
that casts
and extracts the primitive value.
getCount
in interface GenericCounter<E>
public java.lang.String getCountAsString(E key)
GenericCounter
getCountAsString
in interface GenericCounter<E>
public double getNormalizedCount(E key)
Distribution
instead of using this
method.
public void setCount(E key, double count)
incrementCount(Object,double)
.
public void setCount(E key, java.lang.String s)
GenericCounter
setCount
in interface GenericCounter<E>
public void setCounts(java.util.Collection<E> keys, double count)
incrementCounts(Collection,double)
.
public void incrementCount(E key, double count)
incrementCount(Object)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
public void incrementCount(E key)
incrementCount(Object,double)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
public void incrementCounts(java.util.Collection<E> keys, double count)
incrementCounts(Collection)
.
To set the counts of a collection of objects to a specific value instead
of incrementing them, use setCounts(Collection,double)
.
public void incrementCounts(java.util.Collection<E> keys)
incrementCounts(Collection,double)
.
To set the counts of a collection of objects to a specifc value instead
of incrementing them, use setCounts(Collection,double)
.
public void incrementAll(double count)
count
- The amount to be addedpublic void decrementCount(E key, double count)
decrementCount(Object)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
public void decrementCount(E key)
decrementCount(Object,double)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
public void decrementCounts(java.util.Collection<E> keys, double count)
decrementCounts(Collection)
.
To set the counts of a collection of objects to a specific value instead
of decrementing them, use setCounts(Collection,double)
.
public void decrementCounts(java.util.Collection<E> keys)
decrementCounts(Collection,double)
.
To set the counts of a collection of objects to a specifc value instead
of decrementing them, use setCounts(Collection,double)
.
public void addAll(GenericCounter<E> counter)
public void divideBy(Counter<E> counter)
counter
- Entries in argument scale individual keys in this counterpublic void subtractAll(Counter<E> counter)
public boolean containsKey(E key)
containsKey
in interface GenericCounter<E>
public MutableDouble remove(E key)
public void removeAll(java.util.Collection<E> keys)
public void clear()
public int size()
size
in interface GenericCounter<E>
public boolean isEmpty()
public java.util.Set<E> keySet()
GenericCounter
keySet
in interface GenericCounter<E>
public java.util.Set<java.util.Map.Entry<E,MutableDouble>> entrySet()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public 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.Object
public void normalize()
Distribution
instead.
public void removeZeroCounts()
public double max()
public double doubleMax()
GenericCounter
doubleMax
in interface GenericCounter<E>
public double min()
public E argmax(java.util.Comparator tieBreaker)
public E argmax()
argmax(Comparator)
. Returns null if this Counter is empty.
public E argmin(java.util.Comparator tieBreaker)
public E argmin()
argmin(Comparator)
. Returns null if this Counter is empty.
public java.util.Set<E> keysAbove(double countThreshold)
public java.util.Set<E> keysBelow(double countThreshold)
public java.util.Set<E> keysAt(double count)
public java.util.Comparator comparator(boolean ascending)
Counter c = new Counter(); // add to the counter... List biggestKeys = new ArrayList(c.keySet()); Collections.sort(biggestKeys, c.comparator(false)); List smallestEntries = new ArrayList(c.entrySet()); Collections.sort(smallestEntries, c.comparator(true))
public java.util.Comparator comparator(boolean ascending, boolean useMagnitude)
Counter c = new Counter(); // add to the counter... List biggestKeys = new ArrayList(c.keySet()); Collections.sort(biggestKeys, c.comparator(false, true)); List smallestEntries = new ArrayList(c.entrySet()); Collections.sort(smallestEntries, c.comparator(true))
public java.util.Comparator comparator()
comparator(true)
.
comparator
in interface GenericCounter<E>
public void multiplyBy(double d)
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |