Created
April 20, 2015 14:04
-
-
Save primenumber/25588158f3b97dc64c9c to your computer and use it in GitHub Desktop.
https://github.com/keitarou/pokemon_zukan/blob/master/data/xy/ja/name_table.json からしりとり用データを生成する
This file contains hidden or 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
# encoding: utf-8 | |
require 'json' | |
require 'nkf' | |
require 'unf' | |
def func(name) | |
fx = name.gsub(/♂/u, "オス") | |
fx = fx.gsub(/♀/u, "メス") | |
fx = fx.gsub(/2/u, "ツー") | |
fx = fx.gsub(/Z/u, "ゼット") | |
kr = fx.delete("ー") | |
hr = NKF.nkf("--hiragana -w", kr) | |
norm = hr.to_nfd.delete("\u3099").delete("\u309A") | |
norm = norm.tr("ぁぃぅぇぉゃゅょゎっ", "あいうえおやゆよわつ") | |
return norm | |
end | |
obj = JSON.parse(open('name_table.json').read) | |
$names = Array.new | |
obj.each_key do |key| | |
$names.push([key, func(key)]) | |
end | |
$names.sort! | |
#$names.uniq!{|n| n[1]} | |
if ARGV[0] == "python" then | |
puts "[#{$names.map{|n| "(u'#{n[0]}', u'#{n[1].to_s}')"}.join(", ")}]" | |
elsif ARGV[0] == "ruby" then | |
puts "[#{$names.map{|n| "{\"name\":\"#{n[0]}\",\"kana\":\"#{n[1].to_s}\"}"}.join(",")}]" | |
elsif ARGV[0] == "0" then | |
puts ($names.map {|n| n[0]}.join(" ")) | |
else | |
$names.each {|n| puts n[0].to_s} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment