Create a gist now

Instantly share code, notes, and snippets.

@inaniwa3 /m1.rb
Last active Nov 29, 2015

#! ruby -Ku
# coding: utf-8
require "json"
require "natto"
require "moji"
names = []
raw = JSON.parse(open("./combi_nagashi.json").read)
raw["combi"].each do |combi|
names << combi["combiname"]
end
words = []
nm = Natto::MeCab.new
names.each do |name|
nm_nodes = nm.enum_parse(name)
nm_nodes.each do |nm_node|
next if nm_node.surface.nil?
next unless nm_node.feature.split(",")[0] == "名詞"
words << nm_node.surface
end
end
results = {}
names_str = names.join(",")
words.uniq.sort.each do |word|
next if word.length == 1 && Moji.type(word) != Moji::ZEN_KANJI
num = names_str.scan(word).size
if !results.has_key?(num)
results[num] = word
else
results[num] = results[num] + ", " + word
end
end
results = results.sort{|(k1, v1), (k2, v2)| k2 <=> k1 }
puts "| 回数 | 単語 |"
puts "|------|------|"
results.each do |key, value|
puts "| #{key} | #{value} |"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment