edu.stanford.nlp.stats
Class GeneralizedCounter

java.lang.Object
  extended by edu.stanford.nlp.stats.GeneralizedCounter

public class GeneralizedCounter
extends Object

A class for keeping double counts of Lists of a prespecified length. A depth n GeneralizedCounter can be thought of as a conditionalized count over n classes of objects, in a prespecified order. Also offers a read-only view as a Counter.

This class is serializable but no guarantees are made about compatibility version to version.

Author:
Roger Levy

Constructor Summary
GeneralizedCounter(int depth)
          Constructs a new GeneralizedCounter of a specified depth
 
Method Summary
 GeneralizedCounter conditionalize(List l)
          returns a GeneralizedCounter conditioned on the objects in the List argument.
 GeneralizedCounter conditionalizeOnce(Object o)
          Returns a GeneralizedCounter conditioned on the given top level object.
 boolean containsKey(List key)
          Like Counter, this currently returns true if the count is explicitly 0.0 for something
 Counter counterView()
          Returns a read-only synchronous view (not a snapshot) of this as a Counter.
 int depth()
          Returns the depth of the GeneralizedCounter (i.e., the dimension of the distribution).
 Set entrySet()
          returns the set of entries, where each key is a read-only List of size equal to the depth of the GeneralizedCounter, and each value is a Double.
 double getCount(Object o)
          Equivalent to getCounts(java.util.List)({o}); works only for depth 1 GeneralizedCounters
 double getCount(Object o1, Object o2)
          A convenience method equivalent to getCounts(java.util.List)({o1,o2}); works only for depth 2 GeneralizedCounters
 double getCount(Object o1, Object o2, Object o3)
          A convenience method equivalent to getCounts(java.util.List)({o1,o2,o3}); works only for depth 3 GeneralizedCounters
 double[] getCounts(List l)
          returns a double[] array of length depth+1, containing the conditional counts on a depth-length list given each level of conditional distribution from 0 to depth.
 void incrementCount(List l)
          Equivalent to incrementCount(l, 1.0).
 void incrementCount(List l, double count)
          adds to count for the depth()-dimensional key l.
 void incrementCount(List l, Object o)
          equivalent to incrementCount(l,o,1.0).
 void incrementCount(List l, Object o, double count)
          same as incrementCount(List, double) but as if Object o were at the end of the list
 void incrementCount1D(Object o)
          Equivalent to incrementCount1D(o, 1.0).
 void incrementCount1D(Object o, double count)
          Equivalent to incrementCount(java.util.List, java.lang.Object)({o}, count); only works for a depth 1 GeneralizedCounter.
 void incrementCount2D(Object first, Object second)
          Equivalent to incrementCount(first,second,1.0).
 void incrementCount2D(Object first, Object second, double count)
          Equivalent to incrementCount( new Object[] { first, second }, count ).
 boolean isEmpty()
          Returns true if nothing has a count.
 Set keySet()
          Returns the set of keys, as read-only Lists of size equal to the depth of the GeneralizedCounter.
 Set lowestLevelCounterEntrySet()
          Returns a set of entries, where each key is a read-only List of size one less than the depth of the GeneralizedCounter, and each value is a Counter.
static void main(String[] args)
          for testing purposes only
 Counter oneDimensionalCounterView()
          Returns a read-only synchronous view (not a snapshot) of this as a Counter.
 void prettyPrint()
          pretty-prints the GeneralizedCounter to System.out.
 void prettyPrint(PrintWriter pw)
          pretty-prints the GeneralizedCounter, using a buffer increment of two spaces.
 void prettyPrint(PrintWriter pw, String bufferIncrement)
          pretty-prints the GeneralizedCounter.
 GeneralizedCounter reverseKeys()
           
 Set topLevelKeySet()
          Returns the set of elements that occur in the 0th position of a List key in the GeneralizedCounter.
 String toString()
           
 String toString(String param)
           
 double totalCount()
          returns the total count of objects in the GeneralizedCounter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneralizedCounter

public GeneralizedCounter(int depth)
Constructs a new GeneralizedCounter of a specified depth

Parameters:
depth - the depth of the GeneralizedCounter
Method Detail

entrySet

public Set entrySet()
returns the set of entries, where each key is a read-only List of size equal to the depth of the GeneralizedCounter, and each value is a Double. Each entry is a Map.Entry object, but these objects do not support the Map.Entry#setValue method; attempts to call that method with result in an UnsupportedOperationException being thrown.


lowestLevelCounterEntrySet

public Set lowestLevelCounterEntrySet()
Returns a set of entries, where each key is a read-only List of size one less than the depth of the GeneralizedCounter, and each value is a Counter. Each entry is a Map.Entry object, but these objects do not support the Map.Entry#setValue method; attempts to call that method with result in an UnsupportedOperationException being thrown.


totalCount

public double totalCount()
returns the total count of objects in the GeneralizedCounter.


topLevelKeySet

public Set topLevelKeySet()
Returns the set of elements that occur in the 0th position of a List key in the GeneralizedCounter.

See Also:
conditionalize(java.util.List), getCount(java.lang.Object)

keySet

public Set keySet()
Returns the set of keys, as read-only Lists of size equal to the depth of the GeneralizedCounter.


depth

public int depth()
Returns the depth of the GeneralizedCounter (i.e., the dimension of the distribution).


isEmpty

public boolean isEmpty()
Returns true if nothing has a count.


getCount

public double getCount(Object o)
Equivalent to getCounts(java.util.List)({o}); works only for depth 1 GeneralizedCounters


getCount

public double getCount(Object o1,
                       Object o2)
A convenience method equivalent to getCounts(java.util.List)({o1,o2}); works only for depth 2 GeneralizedCounters


getCount

public double getCount(Object o1,
                       Object o2,
                       Object o3)
A convenience method equivalent to getCounts(java.util.List)({o1,o2,o3}); works only for depth 3 GeneralizedCounters


getCounts

public double[] getCounts(List l)
returns a double[] array of length depth+1, containing the conditional counts on a depth-length list given each level of conditional distribution from 0 to depth.


conditionalize

public GeneralizedCounter conditionalize(List l)
returns a GeneralizedCounter conditioned on the objects in the List argument. The length of the argument List must be less than the depth of the GeneralizedCounter.


conditionalizeOnce

public GeneralizedCounter conditionalizeOnce(Object o)
Returns a GeneralizedCounter conditioned on the given top level object. This is just shorthand (and more efficient) for conditionalize(new Object[] { o }).


incrementCount

public void incrementCount(List l,
                           Object o)
equivalent to incrementCount(l,o,1.0).


incrementCount

public void incrementCount(List l,
                           Object o,
                           double count)
same as incrementCount(List, double) but as if Object o were at the end of the list


incrementCount

public void incrementCount(List l)
Equivalent to incrementCount(l, 1.0).


incrementCount

public void incrementCount(List l,
                           double count)
adds to count for the depth()-dimensional key l.


incrementCount2D

public void incrementCount2D(Object first,
                             Object second)
Equivalent to incrementCount(first,second,1.0).


incrementCount2D

public void incrementCount2D(Object first,
                             Object second,
                             double count)
Equivalent to incrementCount( new Object[] { first, second }, count ). Makes the special case easier, and also more efficient.


incrementCount1D

public void incrementCount1D(Object o)
Equivalent to incrementCount1D(o, 1.0).


incrementCount1D

public void incrementCount1D(Object o,
                             double count)
Equivalent to incrementCount(java.util.List, java.lang.Object)({o}, count); only works for a depth 1 GeneralizedCounter.


containsKey

public boolean containsKey(List key)
Like Counter, this currently returns true if the count is explicitly 0.0 for something


reverseKeys

public GeneralizedCounter reverseKeys()

counterView

public Counter counterView()
Returns a read-only synchronous view (not a snapshot) of this as a Counter. Any calls to count-changing or entry-removing operations will result in an UnsupportedOperationException. At some point in the future, this view may gain limited writable functionality.


oneDimensionalCounterView

public Counter oneDimensionalCounterView()
Returns a read-only synchronous view (not a snapshot) of this as a Counter. Works only with one-dimensional GeneralizedCounters. Exactly like counterView(), except that getCount(java.lang.Object) operates on primitive objects of the counter instead of singleton lists. Any calls to count-changing or entry-removing operations will result in an UnsupportedOperationException. At some point in the future, this view may gain limited writable functionality.


toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(String param)

main

public static void main(String[] args)
for testing purposes only


prettyPrint

public void prettyPrint()
pretty-prints the GeneralizedCounter to System.out.


prettyPrint

public void prettyPrint(PrintWriter pw)
pretty-prints the GeneralizedCounter, using a buffer increment of two spaces.


prettyPrint

public void prettyPrint(PrintWriter pw,
                        String bufferIncrement)
pretty-prints the GeneralizedCounter.



Stanford NLP Group