|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<K,V>
edu.umd.cloud9.util.Scorekeeper<T,Integer>
edu.umd.cloud9.util.Histogram<T>
T - type of objectpublic class Histogram<T extends Comparable<T>>
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()
}
| 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 |
|---|
public Histogram()
Histogram.
| Method Detail |
|---|
public void clear()
clear in interface Map<T extends Comparable<T>,Integer>clear in class HashMap<T extends Comparable<T>,Integer>public void count(T instance)
instance - the instance observedpublic int getCount(T inst)
inst - the instance
public int getTotalCount()
public void printCounts()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||