Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.nlp.stats
Interface Counter<E>

All Known Implementing Classes:
  AbstractCounter, ClassicCounter, IntCounter

    public interface Counter<E>

An Object to double map used for keeping weights or counts for objects. Utility functions are contained in `Counters`. The class previously known as Counter has been renamed to `ClassicCounter`. An alternative Counter implementation, which is more memory efficient but not necessarily faster, is `OpenAddressCounter`.

Implementation note: You shouldn't casually add further methods to this interface. Rather, they should be added to the `Counters` class.

Author:
  dramage, cer, pado

Method Summary
`void` | `addAll(Counter<E> counter)` Adds the counts in the given Counter to the counts in this Counter.
`void` | `clear()` Removes all entries from the counter.
`boolean` | `containsKey(E key)` Returns whether a Counter contains a key.
`double` | `decrementCount(E key)` Decrements the count for this key by 1.0.
`double` | `decrementCount(E key, double value)` Decrements the count for this key by the given value.
`double` | `defaultReturnValue()` Returns the default return value.
`Set<Map.Entry<E,Double>>` | `entrySet()` Returns a view of the entries in this counter.
`double` | `getCount(E key)` Returns the count for this key as a double.
`Factory<Counter<E>>` | `getFactory()` Returns a factory that can create new instances of this kind of Counter.
`double` | `incrementCount(E key)` Increments the count for this key by 1.0.
`double` | `incrementCount(E key, double value)` Increments the count for the given key by the given value.
`Set<E>` | `keySet()` Returns the Set of keys in this counter.
`double` | `logIncrementCount(E key, double value)` Increments the count stored in log space for this key by the given log-transformed value.
`double` | `remove(E key)` Removes the given key and its associated value from this Counter.
`void` | `setCount(E key, double value)` Sets the count for the given key to be the given value.
`void` | `setDefaultReturnValue(double rv)` Sets the default return value.
`int` | `size()` Returns the number of entries stored in this counter.
`double` | `totalCount()` Computes the total of all counts in this counter, and returns it as a double.
`Collection<Double>` | `values()` Returns a copy of the values currently in this counter.

Method Detail

### getFactory

    Factory<Counter<E>> getFactory()

  Returns a factory that can create new instances of this kind of Counter.

  Returns:
    A factory that can create new instances of this kind of Counter.

### setDefaultReturnValue

    void setDefaultReturnValue(double rv)

  Sets the default return value. This value is returned when you get the value for keys that are not in the Counter. It is zero by default, but can sometimes usefully by set to other values like Double.NaN or Double.NEGATIVE_INFINITY.

  Parameters:
    `rv` - The default value

### defaultReturnValue

    double defaultReturnValue()

  Returns the default return value.

  Returns:
    The default return value.

### getCount

    double getCount(E key)

  Returns the count for this key as a double. This is the defaultReturnValue (0.0, if it hasn't been set) if the key hasn't previously been seen.

  Parameters:
    `key` - The key
  Returns:
    The count

### setCount

    void setCount(E key,
                  double value)

  Sets the count for the given key to be the given value. This will replace any existing count for the key. To add to a count instead of replacing it, use `incrementCount(Object,double)`.

  Parameters:
    `key` - The key
    `value` - The count

### incrementCount

    double incrementCount(E key,
                          double value)

  Increments the count for the given key by the given value. If the key hasn't been seen before, it is assumed to have count 0.0, and thus this method will set its count to the given amount. Note that this is true regardless of the setting of defaultReturnValue. Negative increments are equivalent to calling `decrementCount`. To more conveniently 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)`.

  Parameters:
    `key` - The key to increment
    `value` - The amount to increment it by
  Returns:
    The value associated with they key, post-increment.

### incrementCount

    double incrementCount(E key)

  Increments the count for this key by 1.0. If the key hasn't been seen before, it is assumed to have count 0.0, and thus this method will set its count to 1.0. Note that this is true regardless of the setting of defaultReturnValue. 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)`.

  Parameters:
    `key` - The key to increment by 1.0
  Returns:
    The value associated with they key, post-increment.

### decrementCount

    double decrementCount(E key,
                          double value)

  Decrements the count for this key by the given value. If the key hasn't been seen before, it is assumed to have count 0.0, and thus this method will set its count to the negative of the given amount. Note that this is true regardless of the setting of defaultReturnValue. Negative increments are equivalent to calling `incrementCount`. 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)`.

  Parameters:
    `key` - The key to decrement
    `value` - The amount to decrement it by
  Returns:
    The value associated with they key, post-decrement.

### decrementCount

    double decrementCount(E key)

  Decrements the count for this key by 1.0. If the key hasn't been seen before, it is assumed to have count 0.0, and thus this method will set its count to -1.0. Note that this is true regardless of the setting of defaultReturnValue. 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)`.

  Parameters:
    `key` - The key to decrement by 1.0
  Returns:
    The value of associated with they key, post-decrement.

### logIncrementCount

    double logIncrementCount(E key,
                             double value)

  Increments the count stored in log space for this key by the given log-transformed value. If the current count for the key is v1, and you call logIncrementCount with a value of v2, then the new value will be log(e^v1 + e^v2). If the key hasn't been seen before, it is assumed to have count Double.NEGATIVE_INFINITY, and thus this method will set its count to the given amount. Note that this is true regardless of the setting of defaultReturnValue. To set a count to a specifc value instead of incrementing it, you need to first take the log yourself and then to call `setCount(Object,double)`.

  Parameters:
    `key` - The key to increment
    `value` - The amount to increment it by, in log space
  Returns:
    The value associated with they key, post-increment, in log space

### addAll

    void addAll(Counter<E> counter)

  Adds the counts in the given Counter to the counts in this Counter. This is identical in effect to calling Counters.addInPlace(this, counter).

  Parameters:
    `counter` - The Counter whose counts will be added. For each key in counter, if it is not in this, then it will be added with value `counter.getCount(key)`. Otherwise, it will have value `this.getCount(key) + counter.getCount(key)`.

### remove

    double remove(E key)

  Removes the given key and its associated value from this Counter. Its count will now be returned as the defaultReturnValue and it will no longer be considered previously seen. If a key not contained in the Counter is given, no action is performed on the Counter and Double.NaN is returned. This behavior echoes that of HashMap, but differs since a HashMap returns a Double (rather than double) and thus returns null if a key is not present. Any future revisions of Counter should preserve the ability to "remove" a key that is not present in the Counter.

  Parameters:
    `key` - The key
  Returns:
    The value removed from the map or the default value if no count was associated with that key.

### containsKey

    boolean containsKey(E key)

  Returns whether a Counter contains a key.

  Parameters:
    `key` - The key
  Returns:
    true iff key is a key in this Counter.

### keySet

    Set<E> keySet()

  Returns the Set of keys in this counter.

  Returns:
    The Set of keys in this counter.

### values

    Collection<Double> values()

  Returns a copy of the values currently in this counter. (You should regard this Collection as read-only for forward compatibility; at present implementations differ on how they respond to attempts to change this Collection.)

  Returns:
    A copy of the values currently in this counter.

### entrySet

    Set<Map.Entry<E,Double>> entrySet()

  Returns a view of the entries in this counter. The values can be safely modified with setValue().

  Returns:
    A view of the entries in this counter

### clear

    void clear()

  Removes all entries from the counter.

### size

    int size()

  Returns the number of entries stored in this counter.

  Returns:
    The number of entries in this counter.

### totalCount

    double totalCount()

  Computes the total of all counts in this counter, and returns it as a double. (Existing implementations cache this value, so that this operation is cheap.)

  Returns:
    The total (arithmetic sum) of all counts in this counter.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Stanford NLP Group