Last active
November 29, 2015 10:42
-
-
Save inaniwa3/007a4e283b78e8ca2965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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