スクリプト/汎用関数/ローマ字文字列をひらがな文字列に変更する
最終投稿者: aoihikawa
更新:2013/02/20 19:49:30
ローマ字文字列をひらがな文字列に変更する
(ご自由にご利用ください)
使用例
ご意見やご質問などありましたら
こちらのブログ記事まで。
ツイート
(ご自由にご利用ください)
def isArray(arr) return getArrayLength(splitString(toString(arr),",")) != 1 end def toUpperCase(str) r = ""; if isArray(str) then list = splitString(str,"") else list = createArray(); list[0] = str; end i = 0; ilen = getArrayLength(list) while i < ilen case list[i] when "a" r = r + "A" when "b" r = r + "B" when "c" r = r + "C" when "d" r = r + "D" when "e" r = r + "E" when "f" r = r + "F" when "g" r = r + "G" when "h" r = r + "H" when "i" r = r + "I" when "j" r = r + "J" when "k" r = r + "K" when "l" r = r + "L" when "m" r = r + "M" when "n" r = r + "N" when "o" r = r + "O" when "p" r = r + "P" when "q" r = r + "Q" when "r" r = r + "R" when "s" r = r + "S" when "t" r = r + "T" when "u" r = r + "U" when "v" r = r + "V" when "w" r = r + "W" when "x" r = r + "X" when "y" r = r + "Y" when "z" r = r + "Z" else r = r + list[i] end i = i + 1 end return r end def toZen(cchar, lastchar, last2char) if lastchar != "" then ulastchar = toUpperCase(lastchar); else ulastchar = ""; end if last2char != "" then ulast2char = toUpperCase(last2char); else ulast2char = ""; end r = "" case cchar when "A" if (ulast2char == "B" && ulastchar == "Y") then r = "びゃ"; elsif (ulast2char == "C" && (ulastchar == "H" || ulastchar == "Y")) then r = "ちゃ"; elsif (ulast2char == "D" && ulastchar == "H") then r = "でゃ"; elsif (ulast2char == "D" && ulastchar == "Y") then r = "ぢゃ"; elsif (ulast2char == "F" && ulastchar == "Y") then r = "ふゃ"; elsif (ulast2char == "G" && ulastchar == "Y") then r = "ぎゃ"; elsif (ulast2char == "H" && ulastchar == "Y") then r = "ひゃ"; elsif (ulast2char == "J" && ulastchar == "Y") then r = "じゃ"; elsif (ulast2char == "K" && ulastchar == "W") then r = "くぁ"; elsif (ulast2char == "K" && ulastchar == "Y") then r = "きゃ"; elsif ((ulast2char == "L" || ulast2char == "X") && ulastchar == "Y") then r = "ゃ"; elsif (ulast2char == "M" && ulastchar == "Y") then r = "みゃ"; elsif (ulast2char == "N" && ulastchar == "Y") then r = "にゃ"; elsif (ulast2char == "P" && ulastchar == "Y") then r = "ぴゃ"; elsif (ulast2char == "R" && ulastchar == "Y") then r = "りゃ"; elsif (ulast2char == "S" && (ulastchar == "H" || ulastchar == "Y")) then r = "しゃ"; elsif (ulast2char == "T" && ulastchar == "H") then r = "てゃ"; elsif (ulast2char == "T" && ulastchar == "Y") then r = "ちゃ"; elsif (ulast2char == "W" && ulastchar == "H") then r = "うぁ"; elsif (ulast2char == "Z" && ulastchar == "Y") then r = "じゃ"; elsif (ulastchar == "B") then r = last2char + "ば"; elsif (ulastchar == "D") then r = last2char + "だ"; elsif (ulastchar == "F") then r = last2char + "ふぁ"; elsif (ulastchar == "G") then r = last2char + "が"; elsif (ulastchar == "H") then r = last2char + "は"; elsif (ulastchar == "J") then r = last2char + "じゃ"; elsif (ulastchar == "K") then r = last2char + "か"; elsif (ulastchar == "L" || ulastchar == "X") then r = last2char + "ぁ"; elsif (ulastchar == "M") then r = last2char + "ま"; elsif (ulastchar == "N") then r = last2char + "な"; elsif (ulastchar == "P") then r = last2char + "ぱ"; elsif (ulastchar == "R") then r = last2char + "ら"; elsif (ulastchar == "S") then r = last2char + "さ"; elsif (ulastchar == "T") then r = last2char + "た"; elsif (ulastchar == "V") then r = last2char + "う゛ぁ"; elsif (ulastchar == "W") then r = last2char + "わ"; elsif (ulastchar == "Y") then r = last2char + "や"; elsif (ulastchar == "Z") then r = last2char + "ざ"; else r = last2char + lastchar + "あ"; end when "I" if (ulast2char == "B" && ulastchar == "Y") then r = "びぃ"; elsif (ulast2char == "C" && ulastchar == "H") then r = "ち"; elsif (ulast2char == "C" && ulastchar == "Y") then r = "ちぃ"; elsif (ulast2char == "D" && ulastchar == "H") then r = "でぃ"; elsif (ulast2char == "D" && ulastchar == "Y") then r = "ぢぃ"; elsif (ulast2char == "F" && ulastchar == "Y") then r = "ふぃ"; elsif (ulast2char == "G" && ulastchar == "Y") then r = "ぎぃ"; elsif (ulast2char == "H" && ulastchar == "Y") then r = "ひぃ"; elsif (ulast2char == "J" && ulastchar == "Y") then r = "じぃ"; elsif (ulast2char == "K" && ulastchar == "Y") then r = "きぃ"; elsif ((ulast2char == "L" || ulast2char == "X") && ulastchar == "Y") then r = "ぃ"; elsif (ulast2char == "M" && ulastchar == "Y") then r = "みぃ"; elsif (ulast2char == "N" && ulastchar == "Y") then r = "にぃ"; elsif (ulast2char == "P" && ulastchar == "Y") then r = "ぴぃ"; elsif (ulast2char == "R" && ulastchar == "Y") then r = "りぃ"; elsif (ulast2char == "S" && ulastchar == "H") then r = "し"; elsif (ulast2char == "S" && ulastchar == "Y") then r = "しぃ"; elsif (ulast2char == "T" && ulastchar == "H") then r = "てぃ"; elsif (ulast2char == "T" && ulastchar == "Y") then r = "ちぃ"; elsif (ulast2char == "W" && ulastchar == "H") then r = "うぃ"; elsif (ulast2char == "Z" && ulastchar == "Y") then r = "じぃ"; elsif (ulastchar == "B") then r = last2char + "び"; elsif (ulastchar == "D") then r = last2char + "ぢ"; elsif (ulastchar == "F") then r = last2char + "ふぃ"; elsif (ulastchar == "G") then r = last2char + "ぎ"; elsif (ulastchar == "H") then r = last2char + "ひ"; elsif (ulastchar == "J") then r = last2char + "じ"; elsif (ulastchar == "K") then r = last2char + "き"; elsif (ulastchar == "L" || ulastchar == "X") then r = last2char + "ぃ"; elsif (ulastchar == "M") then r = last2char + "み"; elsif (ulastchar == "N") then r = last2char + "に"; elsif (ulastchar == "P") then r = last2char + "ぴ"; elsif (ulastchar == "R") then r = last2char + "り"; elsif (ulastchar == "S") then r = last2char + "し"; elsif (ulastchar == "T") then r = last2char + "ち"; elsif (ulastchar == "V") then r = last2char + "う゛ぃ"; elsif (ulastchar == "W") then r = last2char + "うぃ"; elsif (ulastchar == "Y") then r = last2char + "い"; elsif (ulastchar == "Z") then r = last2char + "じ"; else r = last2char + lastchar + "い"; end when "U" if (ulast2char == "B" && ulastchar == "Y") then r = "びゅ"; elsif (ulast2char == "C" && (ulastchar == "H" || ulastchar == "Y")) then r = "ちゅ"; elsif (ulast2char == "D" && ulastchar == "H") then r = "でゅ"; elsif (ulast2char == "D" && ulastchar == "Y") then r = "ぢゅ"; elsif (ulast2char == "F" && ulastchar == "Y") then r = "ふゅ"; elsif (ulast2char == "G" && ulastchar == "Y") then r = "ぎゅ"; elsif (ulast2char == "H" && ulastchar == "Y") then r = "ひゅ"; elsif (ulast2char == "J" && ulastchar == "Y") then r = "じゅ"; elsif (ulast2char == "K" && ulastchar == "Y") then r = "きゅ"; elsif ((ulast2char == "L" || ulast2char == "X") && ulastchar == "Y") then r = "ゅ"; elsif (ulast2char == "M" && ulastchar == "Y") then r = "みゅ"; elsif (ulast2char == "N" && ulastchar == "Y") then r = "にゅ"; elsif (ulast2char == "P" && ulastchar == "Y") then r = "ぴゅ"; elsif (ulast2char == "R" && ulastchar == "Y") then r = "りゅ"; elsif (ulast2char == "S" && (ulastchar == "H" || ulastchar == "Y")) then r = "しゅ"; elsif (ulast2char == "T" && ulastchar == "H") then r = "てゅ"; elsif (ulast2char == "T" && ulastchar == "S") then r = "つ"; elsif (ulast2char == "T" && ulastchar == "Y") then r = "ちゅ"; elsif (ulast2char == "W" && ulastchar == "H") then r = "う"; elsif (ulast2char == "Z" && ulastchar == "Y") then r = "じゅ"; elsif (ulastchar == "B") then r = last2char + "ぶ"; elsif (ulastchar == "D") then r = last2char + "づ"; elsif (ulastchar == "F") then r = last2char + "ふ"; elsif (ulastchar == "G") then r = last2char + "ぐ"; elsif (ulastchar == "H") then r = last2char + "ふ"; elsif (ulastchar == "J") then r = last2char + "じゅ"; elsif (ulastchar == "K") then r = last2char + "く"; elsif (ulastchar == "L" || ulastchar == "X") then r = last2char + "ぅ"; elsif (ulastchar == "M") then r = last2char + "む"; elsif (ulastchar == "N") then r = last2char + "ぬ"; elsif (ulastchar == "P") then r = last2char + "ぷ"; elsif (ulastchar == "R") then r = last2char + "る"; elsif (ulastchar == "S") then r = last2char + "す"; elsif (ulastchar == "T") then r = last2char + "つ"; elsif (ulastchar == "V") then r = last2char + "う゛"; elsif (ulastchar == "W") then r = last2char + "う"; elsif (ulastchar == "Y") then r = last2char + "ゆ"; elsif (ulastchar == "Z") then r = last2char + "ず"; else r = last2char + lastchar + "う"; end when "E" if (ulast2char == "B" && ulastchar == "Y") then r = "びぇ"; elsif (ulast2char == "C" && (ulastchar == "H" || ulastchar == "Y")) then r = "ちぇ"; elsif (ulast2char == "D" && ulastchar == "H") then r = "でぇ"; elsif (ulast2char == "D" && ulastchar == "Y") then r = "ぢぇ"; elsif (ulast2char == "F" && ulastchar == "Y") then r = "ふぇ"; elsif (ulast2char == "G" && ulastchar == "Y") then r = "ぎぇ"; elsif (ulast2char == "H" && ulastchar == "Y") then r = "ひぇ"; elsif (ulast2char == "J" && ulastchar == "Y") then r = "じぇ"; elsif (ulast2char == "K" && ulastchar == "Y") then r = "きぇ"; elsif ((ulast2char == "L" || ulast2char == "X") && ulastchar == "Y") then r = "ぇ"; elsif (ulast2char == "M" && ulastchar == "Y") then r = "みぇ"; elsif (ulast2char == "N" && ulastchar == "Y") then r = "にぇ"; elsif (ulast2char == "P" && ulastchar == "Y") then r = "ぴぇ"; elsif (ulast2char == "R" && ulastchar == "Y") then r = "りぇ"; elsif (ulast2char == "S" && (ulastchar == "H" || ulastchar == "Y")) then r = "しぇ"; elsif (ulast2char == "T" && ulastchar == "H") then r = "てぇ"; elsif (ulast2char == "T" && ulastchar == "Y") then r = "ちぇ"; elsif (ulast2char == "W" && ulastchar == "H") then r = "うぇ"; elsif (ulast2char == "Z" && ulastchar == "Y") then r = "じぇ"; elsif (ulastchar == "B") then r = last2char + "べ"; elsif (ulastchar == "D") then r = last2char + "で"; elsif (ulastchar == "F") then r = last2char + "ふぇ"; elsif (ulastchar == "G") then r = last2char + "げ"; elsif (ulastchar == "H") then r = last2char + "へ"; elsif (ulastchar == "J") then r = last2char + "じぇ"; elsif (ulastchar == "K") then r = last2char + "け"; elsif (ulastchar == "L" || ulastchar == "X") then r = last2char + "ぇ"; elsif (ulastchar == "M") then r = last2char + "め"; elsif (ulastchar == "N") then r = last2char + "ね"; elsif (ulastchar == "P") then r = last2char + "ぺ"; elsif (ulastchar == "R") then r = last2char + "れ"; elsif (ulastchar == "S") then r = last2char + "せ"; elsif (ulastchar == "T") then r = last2char + "て"; elsif (ulastchar == "V") then r = last2char + "う゛ぇ"; elsif (ulastchar == "W") then r = last2char + "うぇ"; elsif (ulastchar == "Y") then r = last2char + "いぇ"; elsif (ulastchar == "Z") then r = last2char + "ぜ"; else r = last2char + lastchar + "え"; end when "O" if (ulast2char == "B" && ulastchar == "Y") then r = "びょ"; elsif (ulast2char == "C" && (ulastchar == "H" || ulastchar == "Y")) then r = "ちょ"; elsif (ulast2char == "D" && ulastchar == "H") then r = "でょ"; elsif (ulast2char == "D" && ulastchar == "Y") then r = "ぢょ"; elsif (ulast2char == "F" && ulastchar == "Y") then r = "ふょ"; elsif (ulast2char == "G" && ulastchar == "Y") then r = "ぎょ"; elsif (ulast2char == "H" && ulastchar == "Y") then r = "ひょ"; elsif (ulast2char == "J" && ulastchar == "Y") then r = "じょ"; elsif (ulast2char == "K" && ulastchar == "Y") then r = "きょ"; elsif ((ulast2char == "L" || ulast2char == "X") && ulastchar == "Y") then r = "ょ"; elsif (ulast2char == "M" && ulastchar == "Y") then r = "みょ"; elsif (ulast2char == "N" && ulastchar == "Y") then r = "にょ"; elsif (ulast2char == "P" && ulastchar == "Y") then r = "ぴょ"; elsif (ulast2char == "R" && ulastchar == "Y") then r = "りょ"; elsif (ulast2char == "S" && (ulastchar == "H" || ulastchar == "Y")) then r = "しょ"; elsif (ulast2char == "T" && ulastchar == "H") then r = "てょ"; elsif (ulast2char == "T" && ulastchar == "Y") then r = "ちょ"; elsif (ulast2char == "W" && ulastchar == "H") then r = "うぉ"; elsif (ulast2char == "Z" && ulastchar == "Y") then r = "じょ"; elsif (ulastchar == "B") then r = last2char + "ぼ"; elsif (ulastchar == "D") then r = last2char + "ど"; elsif (ulastchar == "F") then r = last2char + "ふぉ"; elsif (ulastchar == "G") then r = last2char + "ご"; elsif (ulastchar == "H") then r = last2char + "ほ"; elsif (ulastchar == "J") then r = last2char + "じょ"; elsif (ulastchar == "K") then r = last2char + "こ"; elsif (ulastchar == "L" || ulastchar == "X") then r = last2char + "ぉ"; elsif (ulastchar == "M") then r = last2char + "も"; elsif (ulastchar == "N") then r = last2char + "の"; elsif (ulastchar == "P") then r = last2char + "ぽ"; elsif (ulastchar == "R") then r = last2char + "ろ"; elsif (ulastchar == "S") then r = last2char + "そ"; elsif (ulastchar == "T") then r = last2char + "と"; elsif (ulastchar == "V") then r = last2char + "う゛ぉ"; elsif (ulastchar == "W") then r = last2char + "を"; elsif (ulastchar == "Y") then r = last2char + "よ"; elsif (ulastchar == "Z") then r = last2char + "ぞ"; else r = last2char + lastchar + "お"; end end return r end def convertStr(str) cchar = ""; lastchar = ""; last2char = ""; converted = "" strlist = splitString(str,"") i = 0; ilen = getArrayLength(strlist) while i < ilen cchar = toUpperCase(strlist[i]) if cchar == lastchar if cchar == "N" converted = converted + last2char + "ん"; lastchar = ""; cchar = "" else converted = converted + last2char + "っ"; lastchar = "" end last2char = "" elsif cchar == "A" || cchar == "I" || cchar == "U" || cchar == "E" || cchar == "O" converted = converted + toZen(cchar, lastchar, last2char); lastchar = ""; last2char = ""; cchar = "" elsif cchar == "," if lastchar == "N" then lastchar = "ん"; end converted = converted + last2char + lastchar + ","; lastchar = ""; last2char = ""; cchar = "" elsif cchar == "." if lastchar == "N" then lastchar = "ん"; end converted = converted + last2char + lastchar + "。"; lastchar = ""; last2char = ""; cchar = "" elsif cchar == "-" if lastchar == "N" then lastchar = "ん"; end converted = converted + last2char + lastchar + "ー"; lastchar = ""; last2char = ""; cchar = "" else if last2char != "" then converted = converted + last2char; end if (lastchar == "N" && cchar != "Y") then converted = converted + "ん"; lastchar = ""; end end last2char = lastchar; lastchar = cchar; i = i + 1 end if lastchar == "N" then lastchar = "ん"; end return (converted + last2char + lastchar) end
使用例
str = convertStr("niximyan") speak(str)
ご意見やご質問などありましたら
こちらのブログ記事まで。
コメントする
コメントするには、ログインする必要があります。
コメント一覧
コメントはありません。