stats module

frequency (elements)

frequency() counts the number of occurence of each elements in the specified elemnts, and returns a org.pnuts.stats.FrequencyCounter object. elements could be Collection, Iterator, Enumeration, StreamTokenizer, or Object arrray.

To retrieve the number of occurence for a patricular word:
map = frequency(split(`\W+`, readText("largefile.txt"))).getMap()
int(map.the) // the number of occurence of 'the'
int(map.get("the"))
To convert the word -> #occurence map to #occurence -> words map:
r = frequency(split(`\W+`,readText("largefile.txt"))).getReverseMap()
mapFunction(
  function(k, v){
    for (i : v) printf("%s (%d)\n", i, int(k))
  },
  r)