Skip to content

Instantly share code, notes, and snippets.

@haru01
Created June 23, 2015 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haru01/9efecb76243b714796e3 to your computer and use it in GitHub Desktop.
Save haru01/9efecb76243b714796e3 to your computer and use it in GitHub Desktop.
require 'natto'
word_counters = {}
nm = Natto::MeCab.new
Dir::entries(".").select { |f| f.match /^ch.*\.re$/}.each do |file|
File.open(file, "r") do |f|
f.each_line do |line|
nm.parse(line) do |n|
word_counters[n.surface] = word_counters[n.surface] ? word_counters[n.surface] + 1 : 1
end
end
end
end
word_counters = word_counters.sort_by {|k, v| v}
word_counters.each do |word, count|
puts "#{word} - #{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment