C
C. Pohjanraito
Hi! I am studying various texts and code.
Word frequency calculator is one basic tool. I find it an interesting,
elementary problem to solve.
I found this word frequency analyser by William James:
freq = Hash.new(0)
loop {
data = (STDIN.read(4095) or break) + (STDIN.gets || "")
for word in data.downcase!.tr!('^a-z',' ').split
freq[word] += 1
end
}
print freq.to_a.map{|x| sprintf("%7d %s\n",x[1],x[0])}.sort.reverse
Whats yours like? And what about phrase frequency?
Casimir Pohjanraito
Word frequency calculator is one basic tool. I find it an interesting,
elementary problem to solve.
I found this word frequency analyser by William James:
freq = Hash.new(0)
loop {
data = (STDIN.read(4095) or break) + (STDIN.gets || "")
for word in data.downcase!.tr!('^a-z',' ').split
freq[word] += 1
end
}
print freq.to_a.map{|x| sprintf("%7d %s\n",x[1],x[0])}.sort.reverse
Whats yours like? And what about phrase frequency?
Casimir Pohjanraito