-
-
Save aristotll/3a262b5136fcf5ac2fc6 to your computer and use it in GitHub Desktop.
convert from kana(hiragana japanese character) to romaji using python
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
// | |
def kana_to_romaji(text): | |
dict={ | |
u'あ':'a',u'い':'i',u'う':'u',u'え':'e',u'お':'o', | |
u'か':'ka',u'き':'ki',u'く':'ku',u'け':'ke',u'こ':'ko', | |
u'さ':'sa',u'し':'si',u'す':'su',u'せ':'se',u'そ':'so', | |
u'た':'ta',u'ち':'ti',u'つ':'tu',u'て':'te',u'と':'to', | |
u'な':'na',u'に':'ni',u'ぬ':'nu',u'ね':'ne',u'の':'no', | |
u'は':'ha',u'ひ':'hi',u'ふ':'hu',u'へ':'he',u'ほ':'ho', | |
u'ま':'ma',u'み':'mi',u'む':'mu',u'め':'me',u'も':'mo', | |
u'や':'ya',u'ゆ':'yu',u'よ':'yo', | |
u'ら':'ra',u'り':'ri',u'る':'ru',u'れ':'re',u'ろ':'ro', | |
u'わ':'wa',u'を':'wo',u'ん':'n', | |
u'が':'ga',u'ぎ':'gi',u'ぐ':'gu',u'げ':'ge',u'ご':'go', | |
u'ざ':'za',u'じ':'zi',u'ず':'zu',u'ぜ':'ze',u'ぞ':'zo', | |
u'だ':'da',u'ぢ':'di',u'づ':'du',u'で':'de',u'ど':'do', | |
u'ば':'ba',u'び':'bi',u'ぶ':'bu',u'べ':'be',u'ぼ':'bo', | |
u'ぱ':'pa',u'ぴ':'pi',u'ぷ':'pu',u'ぺ':'pe',u'ぽ':'po', | |
u'ぁ':'a',u'ぃ':'i',u'ぅ':'u',u'ぇ':'e',u'ぉ':'o', | |
u'っ':'tu', | |
u'ゃ':'ya',u'ゅ':'yu',u'ょ':'yo', | |
u'ゎ':'wa', | |
u'ゐ':'i',u'ゑ':'e', | |
u'ー':'', | |
u'0':'0',u'1':'1',u'2':'2',u'3':'3',u'4':'4', | |
u'5':'5',u'6':'6',u'7':'7',u'8':'8',u'9':'9', | |
u'A':'a',u'B':'b',u'C':'c',u'D':'d',u'E':'e',u'F':'f',u'G':'g',u'H':'h',u'I':'i', | |
u'J':'j',u'K':'k',u'L':'l',u'M':'m',u'N':'n',u'O':'o',u'P':'p',u'Q':'q',u'R':'r', | |
u'S':'s',u'T':'t',u'U':'u',u'V':'v',u'W':'w',u'X':'x',u'Y':'y',u'Z':'z', | |
u'a':'a',u'b':'b',u'c':'c',u'd':'d',u'e':'e',u'f':'f',u'g':'g',u'h':'h',u'i':'i', | |
u'j':'j',u'k':'k',u'l':'l',u'm':'m',u'n':'n',u'o':'o',u'p':'p',u'q':'q',u'r':'r', | |
u's':'s',u't':'t',u'u':'u',u'v':'v',u'w':'w',u'x':'x',u'y':'y',u'z':'z', | |
} | |
for key in dict: | |
value=dict[key] | |
p=re.compile(key) | |
r=p.sub( value, r ) | |
return r | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment