Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
require "rubygems"
require "lingua/stemmer"
stemmer =
tag_counts = {}
STDIN.lines.each{|l| c, t = l.split; tag_counts[t.strip] = c.to_i }
duplicates ={|h, k| h[k] = []}
tag_counts.keys.each{|k| duplicates[k.split("_").map{|x| stemmer.stem(x)}] << k }
duplicates.values.each{|vs| vs.sort!{|x, y| tag_counts[y] <=> tag_counts[x]} }
new_tag_counts = {}
duplicates.values.each{|vs| new_tag_counts[vs[0]] ={|v| tag_counts[v]}.inject(0, &:+)}
puts new_tag_counts.to_a.sort{|x, y| y[1] <=> x[1]}.map{|t, c| " #{c} #{t}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.