-
-
Save geckotang/9246255 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
source "https://rubygems.org/" | |
gem 'romankana' | |
gem 'moji' |
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
#!/bin/env ruby | |
# encoding: utf-8 | |
# Author: kimoto | |
require 'pp' | |
require 'MeCab' | |
require 'kconv' | |
require 'bundler' | |
Bundler.require | |
def nihongo_to_roma(japanese, join_word=" ") | |
m = MeCab::Tagger.new('-Ochasen') | |
node = m.parseToNode(japanese) | |
elements = [] | |
while node | |
item = node.feature.toutf8.split(",")[-2] | |
pp item | |
if item != "*" | |
elements << item | |
else | |
elements << Moji.zen_to_han(node.surface) | |
end | |
node = node.next | |
end | |
Moji.zen_to_han(elements.map(&:katakana_to_roman).join(join_word)) | |
end | |
p japanese = "天二郎V2「CSSはかんたんです。よゆう!」" | |
p nihongo_to_roma(japanese) | |
#" ten ni rou V 2 「 CSS ha kan ta n desu 。 yo yuu ! 」 " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment