|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.stats.ClassicCounter<E>
public class ClassicCounter<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. If you use the
setCount
method, then you cannot go wrong.
Constructor Summary | |
---|---|
ClassicCounter()
Constructs a new (empty) Counter. |
|
ClassicCounter(Collection<E> collection)
Constructs a new Counter by counting the elements in the given Collection. |
|
ClassicCounter(Counter<E> c)
Constructs a new Counter with the contents of the given Counter. |
|
ClassicCounter(MapFactory<E,MutableDouble> mapFactory)
Pass in a MapFactory and the map it vends will back your counter. |
Method Summary | |
---|---|
void |
addAll(Collection<E> collection)
Deprecated. Use own loop. |
void |
addAll(Counter<E> counter)
Deprecated. Use Counters.addInPlace(Counter, Counter) . |
void |
addMultiple(Counter<E> counter,
double d)
Deprecated. Use Counters.addInPlace(Counter, Counter, double) |
PriorityQueue<E> |
asPriorityQueue()
Deprecated. Use Counters.toPriorityQueue(Counter) |
double |
averageCount()
Deprecated. Use Counters.mean(Counter) . |
void |
clear()
Removes all counts from this Counter. |
Object |
clone()
|
Comparator<E> |
comparator()
Deprecated. Use Counters.toComparator(edu.stanford.nlp.stats.Counter |
Comparator<E> |
comparator(boolean ascending)
Deprecated. Use Counters.toComparator(edu.stanford.nlp.stats.Counter and Collections.reverseOrder(Comparator) if necessary. |
Comparator<E> |
comparator(boolean ascending,
boolean useMagnitude)
Deprecated. Use Counters.toComparator(edu.stanford.nlp.stats.Counter |
boolean |
containsKey(E key)
|
double |
decrementCount(E key)
Subtracts 1.0 from the count for the given key. |
double |
decrementCount(E key,
double count)
Subtracts the given count from the current count for the given key. |
void |
decrementCounts(Collection<E> keys)
Deprecated. Use your own loop |
void |
decrementCounts(Collection<E> keys,
double count)
Deprecated. Use your own loop |
double |
defaultReturnValue()
Returns the default return value. |
void |
defaultReturnValue(double rv)
Sets the default return value. |
void |
divideBy(ClassicCounter<E> counter)
Deprecated. Use Counters.divideInPlace(Counter, Counter) |
void |
divideBy(double divisor)
Deprecated. Use Counters.scaleInPlace(Counter, double) |
Set<Map.Entry<E,Double>> |
entrySet()
Returns a view of the doubles in this map. |
boolean |
equals(Object o)
|
static ClassicCounter<String> |
fromString(String s)
converts from format printed by toString method back into a Counter |
double |
getCount(E key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
String |
getCountAsString(E key)
Deprecated. Use Double.toString |
Factory<Counter<E>> |
getFactory()
Returns a factory that can create new instances of this kind of Counter. |
double |
getNormalizedCount(E key)
Deprecated. Use a Distribution or divide getCount by totalCount |
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). |
double |
incrementCount(E key)
Adds 1.0 to the count for the given key. |
double |
incrementCount(E key,
double count)
Adds the given count to the current count for the given key. |
void |
incrementCounts(Collection<E> keys)
Deprecated. Use your own loop |
void |
incrementCounts(Collection<E> keys,
double count)
Deprecated. Use your own loop |
boolean |
isEmpty()
|
Iterator<E> |
iterator()
|
Set<E> |
keysAbove(double countThreshold)
Deprecated. Use Counters.keysAbove(Counter, double) |
Set<E> |
keysAt(double count)
Deprecated. Use Counters.keysAt(Counter, double) |
Set<E> |
keysBelow(double countThreshold)
Deprecated. Use Counters.keysBelow(Counter, double) |
Set<E> |
keySet()
Returns the Set of keys in this counter. |
double |
logIncrementCount(E key,
double count)
If the current count for the object is c1, and you call logIncrementCount with a value of c2, then the new value will be log(e^c1 + e^c2). |
void |
logNormalize()
Deprecated. Use Counters.logNormalize(Counter) . |
double |
logSum()
Deprecated. Use Counters.logSum(Counter) . |
static void |
main(String[] args)
For internal debugging purposes only. |
void |
multiplyBy(double multiplier)
Deprecated. Use Counters.scaleInPlace(Counter, double) |
void |
normalize()
Deprecated. Use Counters#normalize(Counter) |
double |
remove(E key)
Removes the given key from this Counter. |
void |
removeAll(Collection<E> keys)
Removes all the given keys from this Counter. |
void |
removeZeroCounts()
Deprecated. Use Counters.retainNonZeros(Counter) |
void |
retainTop(int num)
Deprecated. Use Counters.retainTop(edu.stanford.nlp.stats.Counter |
void |
setCount(E key,
double count)
Sets the current count for the given key. |
void |
setCount(E key,
String s)
Deprecated. Use setCount after Double.parseDouble |
int |
size()
Returns the number of keys stored in the counter. |
void |
subtractAll(Counter<E> counter)
Deprecated. Use Counters.subtractInPlace(Counter, Counter) |
void |
subtractAll(Counter<E> counter,
boolean removeZeroKeys)
Deprecated. Use Counters.subtractInPlace(Counter, Counter)
and then Counters.retainNonZeros(Counter) |
void |
subtractMultiple(Counter<E> counter,
double d)
Deprecated. Use Counters.addInPlace(Counter, Counter, double) |
String |
toString()
|
String |
toString(int maxKeysToPrint)
Returns a string representation which includes no more than the maxKeysToPrint elements with largest counts. |
String |
toString(NumberFormat nf)
Deprecated. Use Counters.toString(Counter, NumberFormat) |
String |
toString(NumberFormat nf,
String preAppend,
String postAppend,
String keyValSeparator,
String itemSeparator)
Pretty print a Counter. |
double |
totalCount()
Returns the current total count for all objects in this Counter. |
double |
totalCount(Filter<E> filter)
Deprecated. Use own loop? |
double |
totalDoubleCount()
Deprecated. Use totalCount() . |
static ClassicCounter<String> |
valueOf(String s)
Returns the Counter over Strings specified by this String. |
static ClassicCounter<String> |
valueOfIgnoreComments(String s)
Similar to valueOf in that it returns the Counter over Strings specified by this String. |
Collection<Double> |
values()
Returns a copy of the values currently in this counter. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ClassicCounter()
public ClassicCounter(MapFactory<E,MutableDouble> mapFactory)
public ClassicCounter(Counter<E> c)
public ClassicCounter(Collection<E> collection)
Method Detail |
---|
public void defaultReturnValue(double rv)
Counter
defaultReturnValue
in interface Counter<E>
rv
- The default valuepublic double defaultReturnValue()
Counter
defaultReturnValue
in interface Counter<E>
public Factory<Counter<E>> getFactory()
Counter
getFactory
in interface Counter<E>
public double getCount(E key)
get
that casts
and extracts the primitive value.
getCount
in interface Counter<E>
key
- The key
public void setCount(E key, double count)
incrementCount(Object,double)
.
setCount
in interface Counter<E>
key
- The keycount
- The countpublic double remove(E key)
remove
in interface Counter<E>
public boolean containsKey(E key)
containsKey
in interface Counter<E>
public Set<E> keySet()
Counter
keySet
in interface Counter<E>
public Collection<Double> values()
Counter
values
in interface Counter<E>
public void clear()
clear
in interface Counter<E>
public int size()
size
in interface Counter<E>
public double totalCount()
totalCount
in interface Counter<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
public void removeAll(Collection<E> keys)
public boolean isEmpty()
public Set<Map.Entry<E,Double>> entrySet()
entrySet
in interface Counter<E>
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public String toString(int maxKeysToPrint)
maxKeysToPrint
-
public String toString(NumberFormat nf, String preAppend, String postAppend, String keyValSeparator, String itemSeparator)
@Deprecated public String toString(NumberFormat nf)
Counters.toString(Counter, NumberFormat)
public Object clone()
clone
in class Object
@Deprecated public double totalDoubleCount()
totalCount()
.
@Deprecated public double totalCount(Filter<E> filter)
totalCount()
.
@Deprecated public double logSum()
Counters.logSum(Counter)
.
@Deprecated public void logNormalize()
Counters.logNormalize(Counter)
.
@Deprecated public double averageCount()
Counters.mean(Counter)
.
@Deprecated public String getCountAsString(E key)
@Deprecated public void setCount(E key, String s)
@Deprecated public double getNormalizedCount(E key)
Distribution
instead of using this
method.
public double incrementCount(E key, double count)
incrementCount(Object)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
incrementCount
in interface Counter<E>
key
- The key to incrementcount
- The amount to increment it by
public double logIncrementCount(E key, double count)
setCount(Object,double)
.
logIncrementCount
in interface Counter<E>
key
- The key to incrementcount
- The amount to increment it by, in log space
public double incrementCount(E key)
incrementCount(Object,double)
.
To set a count to a specifc value instead of incrementing it, use
setCount(Object,double)
.
incrementCount
in interface Counter<E>
key
- The key to increment by 1.0
@Deprecated public void incrementCounts(Collection<E> keys, double count)
@Deprecated public void incrementCounts(Collection<E> keys)
public void incrementAll(double count)
count
- The amount to be addedpublic double decrementCount(E key, double count)
decrementCount(Object)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
decrementCount
in interface Counter<E>
key
- The key to decrementcount
- The amount to decrement it by
public double decrementCount(E key)
decrementCount(Object,double)
.
To set a count to a specifc value instead of decrementing it, use
setCount(Object,double)
.
decrementCount
in interface Counter<E>
key
- The key to decrement by 1.0
@Deprecated public void decrementCounts(Collection<E> keys, double count)
@Deprecated public void decrementCounts(Collection<E> keys)
@Deprecated public void addAll(Counter<E> counter)
Counters.addInPlace(Counter, Counter)
.
@Deprecated public void addMultiple(Counter<E> counter, double d)
Counters.addInPlace(Counter, Counter, double)
@Deprecated public void subtractAll(Counter<E> counter)
Counters.subtractInPlace(Counter, Counter)
@Deprecated public void subtractMultiple(Counter<E> counter, double d)
Counters.addInPlace(Counter, Counter, double)
@Deprecated public void addAll(Collection<E> collection)
@Deprecated public void multiplyBy(double multiplier)
Counters.scaleInPlace(Counter, double)
@Deprecated public void divideBy(double divisor)
Counters.scaleInPlace(Counter, double)
@Deprecated public void divideBy(ClassicCounter<E> counter)
Counters.divideInPlace(Counter, Counter)
counter
- Entries in argument scale individual keys in this counterpublic void subtractAll(Counter<E> counter, boolean removeZeroKeys)
Counters.subtractInPlace(Counter, Counter)
and then Counters.retainNonZeros(Counter)
@Deprecated public void normalize()
Distribution
instead.
@Deprecated public void removeZeroCounts()
Counters.retainNonZeros(Counter)
@Deprecated public PriorityQueue<E> asPriorityQueue()
Counters.toPriorityQueue(Counter)
@Deprecated public void retainTop(int num)
Counters.retainTop(edu.stanford.nlp.stats.Counter, int)
@Deprecated public Set<E> keysAbove(double countThreshold)
Counters.keysAbove(Counter, double)
@Deprecated public Set<E> keysBelow(double countThreshold)
Counters.keysBelow(Counter, double)
@Deprecated public Set<E> keysAt(double count)
Counters.keysAt(Counter, double)
@Deprecated public Comparator<E> comparator(boolean ascending)
Counters.toComparator(edu.stanford.nlp.stats.Counter)
and Collections.reverseOrder(Comparator)
if necessary.
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))
@Deprecated public Comparator<E> comparator(boolean ascending, boolean useMagnitude)
Counters.toComparator(edu.stanford.nlp.stats.Counter)
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))
@Deprecated public Comparator<E> comparator()
Counters.toComparator(edu.stanford.nlp.stats.Counter)
comparator(true)
.
public static ClassicCounter<String> valueOf(String s)
s
- A String representation of a Counter, where the entries are
one-per-line ('\n') and each line is key \t value
public static ClassicCounter<String> valueOfIgnoreComments(String s)
s
- String representation of a coounter, where entries are one per line such that each
line is either a comment (begins with #) or key \t value
public static ClassicCounter<String> fromString(String s)
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 |