edu.umd.cloud9.util
Class Histogram<T extends Comparable<T>>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by edu.umd.cloud9.util.Scorekeeper<T,Integer>
              extended by edu.umd.cloud9.util.Histogram<T>
Type Parameters:
T - type of object
All Implemented Interfaces:
Serializable, Cloneable, Map<T,Integer>

public class Histogram<T extends Comparable<T>>
extends Scorekeeper<T,Integer>

A class for keeping track of the number of times an object has been encountered. This is useful for counting things in a stream, e.g., POS tags, terms, etc. This object extends Scorekeeper.

Example usage:

 Histogram<String> h = new Histogram<String>();
 String[] terms = myString.split("\\s+");
 
 for (String term : terms) {
        h.count(term);
 }
 
 for (Map.Entry<String, Integer> e : h.entrySet()) {
        // do something with e.getKey()
        // do something with e.getValue()
 }
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
Histogram()
          Constructs an Histogram.
 
Method Summary
 void clear()
          Resets this histogram, purging all observations and counts.
 void count(T instance)
          Adds an instance to the set of observations.
 int getCount(T inst)
          Returns the number of times a particular instance has been observed.
 int getTotalCount()
          Returns the total number of observations.
 void printCounts()
          Prints each instance and how many times its been observed, sorted by the counts.
 
Methods inherited from class edu.umd.cloud9.util.Scorekeeper
getEntryByRank, getSortedEntries, getSortedEntries, getSortedKeys, getTopEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

Histogram

public Histogram()
Constructs an Histogram.

Method Detail

clear

public void clear()
Resets this histogram, purging all observations and counts.

Specified by:
clear in interface Map<T extends Comparable<T>,Integer>
Overrides:
clear in class HashMap<T extends Comparable<T>,Integer>

count

public void count(T instance)
Adds an instance to the set of observations.

Parameters:
instance - the instance observed

getCount

public int getCount(T inst)
Returns the number of times a particular instance has been observed.

Parameters:
inst - the instance
Returns:
the count of the instance

getTotalCount

public int getTotalCount()
Returns the total number of observations.

Returns:
the total number of observations

printCounts

public void printCounts()
Prints each instance and how many times its been observed, sorted by the counts.