Last active
January 4, 2016 09:21
-
-
Save pnlybubbles/5ced601bff328356ec04 to your computer and use it in GitHub Desktop.
漢字混じりの文字列をローマ字列に変換する。input.txt(改行区切り)を読み込んでoutput.txtに吐き出す。YahooAPIを利用。
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
# A sample Gemfile | |
source "https://rubygems.org" | |
# gem "rails" | |
gem "yahoo-japanese-analysis" | |
gem "romaji" |
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
require 'yahoo-japanese-analysis' | |
require 'romaji' | |
require 'pp' | |
data = File.read('./sample.txt').split("\n"); | |
YahooJA.configure do |config| | |
config.app_key = 'dj0zaiZpPTlhNTluRTM1MGFZeSZzPWNvbnN1bWVyc2VjcmV0Jng9NWY-' | |
end | |
result = [] | |
puts "requesting..." | |
data.each { |str| | |
puts str | |
res = YahooJA.furigana(str) | |
pp res | |
next if res.nil? | |
kana = [res[:Result][:WordList][:Word]].flatten.inject('') { |r, v_| | |
add = v_[:Furigana] ? v_[:Furigana] : v_[:Surface] | |
r + add | |
} | |
puts kana | |
romaji = Romaji.kana2romaji(kana) | |
puts romaji | |
result << romaji | |
} | |
File.write('output.txt', result.join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment