Skip to content

Instantly share code, notes, and snippets.

@primenumber
Created April 20, 2015 14:04
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 primenumber/25588158f3b97dc64c9c to your computer and use it in GitHub Desktop.
Save primenumber/25588158f3b97dc64c9c to your computer and use it in GitHub Desktop.
# 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