Stats, ML, Data - Program to compute bigrams, trigrams, n-Grams

Ruby program to compute trigrams (in the fourth line, replace 3 with 2 for Bi-grams .. N for N-grams)


text = File.read("corpus")
h=Hash.new(0)
a=text.tr("^a-zA-Z0-9_ \n",'').downcase.split
a.each_cons(3){|e|h[e]+=1}
h.each do |key,value|
    puts "#{key}\n#{value}"
end