|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.Counter
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 | |
Counter()
Constructs a new (empty) Counter. |
|
Counter(Counter 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(Counter counter)
Adds the counts in the given Counter to the counts in this Counter. |
Object |
argmax()
Finds and returns the key in this Counter with the largest count. |
Object |
argmax(Comparator tieBreaker)
Finds and returns the key in this Counter with the largest count. |
Object |
argmin()
Finds and returns the key in this Counter with the smallest count. |
Object |
argmin(Comparator tieBreaker)
Finds and returns the key in this Counter with the smallest count. |
Counter |
average(Counter other)
Deprecated. Use Counters.average(Counter, Counter) instead. |
double |
averageCount()
Returns the mean of all the counts (totalCount/size). |
void |
clear()
Removes all counts from this Counter. |
Object |
clone()
|
Comparator |
comparator()
Comparator that sorts objects by (increasing) count. |
Comparator |
comparator(boolean ascending)
Returns a comparator suitable for sorting this Counter's keys or entries by their respective counts. |
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(Object key)
|
void |
decrementCount(Object key)
Subtracts 1.0 from the count for the given key. |
void |
decrementCount(Object key,
double count)
Subtracts the given count from the current count for the given key. |
void |
decrementCounts(Collection keys)
Subtracts 1.0 from the counts of each of the given keys. |
void |
decrementCounts(Collection keys,
double count)
Subtracts the given count from the current counts for each of the given keys. |
double |
entropy()
Deprecated. Use Counters.entropy(Counter) instead. |
boolean |
equals(Object o)
|
double |
getCount(Object key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
double |
getNormalizedCount(Object key)
Deprecated. Create a Distribution instead. |
int |
hashCode()
|
void |
incrementCount(Object key)
Adds 1.0 to the count for the given key. |
void |
incrementCount(Object key,
double count)
Adds the given count to the current count for the given key. |
void |
incrementCounts(Collection keys)
Adds 1.0 to the counts for each of the given keys. |
void |
incrementCounts(Collection keys,
double count)
Adds the given count to the current counts for each of the given keys. |
double |
informationRadius(Counter other)
Deprecated. Use Counters.informationRadius(Counter, Counter) instead. |
boolean |
isEmpty()
|
Set |
keysAbove(double countThreshold)
Returns the set of keys whose counts are at or above the given threshold. |
Set |
keysAt(double count)
Returns the set of keys that have exactly the given count. |
Set |
keysBelow(double countThreshold)
Returns the set of keys whose counts are at or below the given threshold. |
Set |
keySet()
|
double |
klDivergence(Counter other)
Deprecated. Use Counters.klDivergence(Counter, Counter) instead. |
static void |
main(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 |
normalize()
Deprecated. Create a Distribution instead. |
Object |
remove(Object key)
Removes the given key from this Counter. |
void |
removeAll(Collection c)
Removes all the given keys from this Counter. |
void |
removeZeroCounts()
Removes all keys whose count is 0. |
void |
setCount(Object key,
double count)
Sets the current count for the given key. |
void |
setCounts(Collection keys,
double count)
Sets the current count for each of the given keys. |
int |
size()
|
void |
subtractAll(Counter counter)
Subtracts the counts in the given Counter from the counts in this Counter. |
String |
toString()
|
double |
totalCount()
Returns the current total count for all objects in this Counter. |
double |
totalCount(Filter filter)
Returns the total count for all objects in this Counter that pass the given Filter. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Counter()
public Counter(MapFactory mapFactory)
public Counter(Counter c)
Method Detail |
public double totalCount()
public double totalCount(Filter filter)
totalCount()
.
public double averageCount()
public double getCount(Object key)
get
that casts
and extracts the primitive value.
public double getNormalizedCount(Object key)
Distribution
instead.
public void setCount(Object key, double count)
To add to a count instead of replacing it, use
incrementCount(Object,double)
.
public void setCounts(Collection keys, double count)
To add to the counts of a collection of objects instead of replacing them,
use incrementCounts(Collection,double)
.
public void incrementCount(Object key, double count)
To more conviently increment the count by 1.0, use
incrementCount(Object)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
public void incrementCount(Object key)
To increment the count by a value other than 1.0, use
incrementCount(Object,double)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
public void incrementCounts(Collection keys, double count)
To more conviniently increment the counts of a collection of objects by
1.0, use 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(Collection keys)
To increment the counts of a collection of object by a value other
than 1.0, use 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 decrementCount(Object key, double count)
To more conviently decrement the count by 1.0, use
decrementCount(Object)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
public void decrementCount(Object key)
To decrement the count by a value other than 1.0, use
decrementCount(Object,double)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
public void decrementCounts(Collection keys, double count)
To more conviniently decrement the counts of a collection of objects by
1.0, use 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(Collection keys)
To decrement the counts of a collection of object by a value other
than 1.0, use 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(Counter counter)
To copy the values from another Counter rather than adding them, use
public void subtractAll(Counter counter)
To copy the values from another Counter rather than subtracting them, use
public boolean containsKey(Object key)
public Object remove(Object key)
public void removeAll(Collection c)
public void clear()
public int size()
public boolean isEmpty()
public Set keySet()
public boolean equals(Object o)
public int hashCode()
public String toString()
public Object clone()
public void normalize()
Distribution
instead.
public void removeZeroCounts()
Maybe in the future we should try to do this more on-the-fly, though it's not clear whether a distinction should be made between "never seen" (i.e. null count) and "seen with 0 count". Certainly there's no distinction in getCount() but there is in containsKey().
public double max()
public double min()
public Object argmax(Comparator tieBreaker)
public Object argmax()
argmax(Comparator)
. Returns null if this Counter is empty.
public Object argmin(Comparator tieBreaker)
public Object argmin()
argmin(Comparator)
. Returns null if this Counter is empty.
public Set keysAbove(double countThreshold)
public Set keysBelow(double countThreshold)
public Set keysAt(double count)
public double entropy()
Counters.entropy(Counter)
instead.
public double klDivergence(Counter other)
Counters.klDivergence(Counter, Counter)
instead.
public double informationRadius(Counter other)
Counters.informationRadius(Counter, Counter)
instead.
public Counter average(Counter other)
Counters.average(Counter, Counter)
instead.
public Comparator comparator(boolean ascending)
Sample usage:
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 Comparator comparator(boolean ascending, boolean useMagnitude)
Sample usage:
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 Comparator comparator()
comparator(true)
.
public static void main(String[] args) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |