0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ローマ字-カナ対応辞書の作成【python】

Last updated at Posted at 2021-09-24

#概要
自作のローマ字カナ読み関数作るために、ローマ字とカナ1モウラの対応(例:"kya"="キャ")を定義した辞書を作りました。
一部、筆者仕様の定義になっているため、ご注意ください。

GitHub:
https://github.com/JiroShimaya/RomajiDict/

#コード
直接手で書いてもよいのですが、拗音の処理など、繰り返し処理で書ける部分が多そうだったので、Pythonでobjectを生成したあと、jsonとして出力しました。

generator.py
import json

def generate():
  obj = {}
  kana = {
    "k":"カキクケコ",
    "ky":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "kw":[""+v for v in "ヮ/ィ/ゥ/ェ/ォ".split("/")],
    "s":"サシスセソ",
    "sy":[""+v for v in "ャ//ュ/ェ/ョ".split("/")],
    "sh":[""+v for v in "ャ//ュ/ェ/ョ".split("/")],
    "sw":[""+v for v in "ヮ/ィ/ゥ/ェ/ォ".split("/")],
    "t":"タチツテト",
    "ty":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "th":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "ts":[""+v for v in "ァ/ィ//ェ/ォ".split("/")],
    "c":"カシクセコ",
    "ch":[""+v for v in "ャ//ュ/ェ/ョ".split("/")],
    "cy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "q":[""+v for v in "ァ/ィ//ェ/ォ".split("/")],
    "n":"ナニヌネノ",
    "ny":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "nw":[""+v for v in "ヮ/ィ/ゥ/ェ/ォ".split("/")],
    "h":"ハヒフヘホ",
    "hy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "f":[""+v for v in "ァ/ィ//ェ/ォ".split("/")],
    "fy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "m":"マミムメモ",
    "my":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "y":"ヤ/イ/ユ/イェ/ヨ".split("/"),
    "r":"ラリルレロ",
    "ry":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "w":"ワ/ウィ/ウ/ウェ/ウォ".split("/"), #ウォはヲでも可
    "g":"ガギグゲゴ",
    "gy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "z":"ザジズゼゾ",
    "zy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "j":[""+v for v in "ャ//ュ/ェ/ョ".split("/")],
    "jy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "d":"ダヂヅデド",
    "dh":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "dy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "b":"バビブベボ",
    "by":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "v":"ヴァ/ヴィ/ヴ/ヴェ/ヴォ".split("/"),
    "vy":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "p":"パピプペポ",
    "py":[""+v for v in "ャ/ィ/ュ/ェ/ョ".split("/")],
    "x":"ァィゥェォ",
    "xy":"ャィュェョ",
    "l":"ァィゥェォ",
    "ly":"ャィュェョ",
    }
  obj.update({r:k for r,k in zip("aiueo","アイウエオ")})
  for c, col in kana.items():
    obj.update({c+v:k for v, k in zip("aiueo",col)})
  
  obj.update({k+"tu":"" for k in "lx"})
  obj.update({k+"tsu":"" for k in "lx"})
  
  return obj

if __name__=="__main__":
  PATH = "./ramaji_dict.json"
  obj = generate()
  with open(PATH,"w") as f:
    json.dump(obj, f, ensure_ascii=False,indent=2)

#出力ファイル

romaji_dict.json
{
  "a": "ア",
  "i": "イ",
  "u": "ウ",
  "e": "エ",
  "o": "オ",
  "ka": "カ",
  "ki": "キ",
  "ku": "ク",
  "ke": "ケ",
  "ko": "コ",
  "kya": "キャ",
  "kyi": "キィ",
  "kyu": "キュ",
  "kye": "キェ",
  "kyo": "キョ",
  "kwa": "クヮ",
  "kwi": "クィ",
  "kwu": "クゥ",
  "kwe": "クェ",
  "kwo": "クォ",
  "sa": "サ",
  "si": "シ",
  "su": "ス",
  "se": "セ",
  "so": "ソ",
  "sya": "シャ",
  "syi": "シ",
  "syu": "シュ",
  "sye": "シェ",
  "syo": "ショ",
  "sha": "シャ",
  "shi": "シ",
  "shu": "シュ",
  "she": "シェ",
  "sho": "ショ",
  "swa": "スヮ",
  "swi": "スィ",
  "swu": "スゥ",
  "swe": "スェ",
  "swo": "スォ",
  "ta": "タ",
  "ti": "チ",
  "tu": "ツ",
  "te": "テ",
  "to": "ト",
  "tya": "チャ",
  "tyi": "チィ",
  "tyu": "チュ",
  "tye": "チェ",
  "tyo": "チョ",
  "tha": "テャ",
  "thi": "ティ",
  "thu": "テュ",
  "the": "テェ",
  "tho": "テョ",
  "tsa": "ツァ",
  "tsi": "ツィ",
  "tsu": "ツ",
  "tse": "ツェ",
  "tso": "ツォ",
  "ca": "カ",
  "ci": "シ",
  "cu": "ク",
  "ce": "セ",
  "co": "コ",
  "cha": "チャ",
  "chi": "チ",
  "chu": "チュ",
  "che": "チェ",
  "cho": "チョ",
  "cya": "チャ",
  "cyi": "チィ",
  "cyu": "チュ",
  "cye": "チェ",
  "cyo": "チョ",
  "qa": "クァ",
  "qi": "クィ",
  "qu": "ク",
  "qe": "クェ",
  "qo": "クォ",
  "na": "ナ",
  "ni": "ニ",
  "nu": "ヌ",
  "ne": "ネ",
  "no": "ノ",
  "nya": "ニャ",
  "nyi": "ニィ",
  "nyu": "ニュ",
  "nye": "ニェ",
  "nyo": "ニョ",
  "nwa": "ヌヮ",
  "nwi": "ヌィ",
  "nwu": "ヌゥ",
  "nwe": "ヌェ",
  "nwo": "ヌォ",
  "ha": "ハ",
  "hi": "ヒ",
  "hu": "フ",
  "he": "ヘ",
  "ho": "ホ",
  "hya": "ヒャ",
  "hyi": "ヒィ",
  "hyu": "ヒュ",
  "hye": "ヒェ",
  "hyo": "ヒョ",
  "fa": "ファ",
  "fi": "フィ",
  "fu": "フ",
  "fe": "フェ",
  "fo": "フォ",
  "fya": "フャ",
  "fyi": "フィ",
  "fyu": "フュ",
  "fye": "フェ",
  "fyo": "フョ",
  "ma": "マ",
  "mi": "ミ",
  "mu": "ム",
  "me": "メ",
  "mo": "モ",
  "mya": "ミャ",
  "myi": "ミィ",
  "myu": "ミュ",
  "mye": "ミェ",
  "myo": "ミョ",
  "ya": "ヤ",
  "yi": "イ",
  "yu": "ユ",
  "ye": "イェ",
  "yo": "ヨ",
  "ra": "ラ",
  "ri": "リ",
  "ru": "ル",
  "re": "レ",
  "ro": "ロ",
  "rya": "リャ",
  "ryi": "リィ",
  "ryu": "リュ",
  "rye": "リェ",
  "ryo": "リョ",
  "wa": "ワ",
  "wi": "ウィ",
  "wu": "ウ",
  "we": "ウェ",
  "wo": "ウォ",
  "ga": "ガ",
  "gi": "ギ",
  "gu": "グ",
  "ge": "ゲ",
  "go": "ゴ",
  "gya": "ギャ",
  "gyi": "ギィ",
  "gyu": "ギュ",
  "gye": "ギェ",
  "gyo": "ギョ",
  "za": "ザ",
  "zi": "ジ",
  "zu": "ズ",
  "ze": "ゼ",
  "zo": "ゾ",
  "zya": "ジャ",
  "zyi": "ジィ",
  "zyu": "ジュ",
  "zye": "ジェ",
  "zyo": "ジョ",
  "ja": "ジャ",
  "ji": "ジ",
  "ju": "ジュ",
  "je": "ジェ",
  "jo": "ジョ",
  "jya": "ジャ",
  "jyi": "ジィ",
  "jyu": "ジュ",
  "jye": "ジェ",
  "jyo": "ジョ",
  "da": "ダ",
  "di": "ヂ",
  "du": "ヅ",
  "de": "デ",
  "do": "ド",
  "dha": "デャ",
  "dhi": "ディ",
  "dhu": "デュ",
  "dhe": "デェ",
  "dho": "デョ",
  "dya": "ヂャ",
  "dyi": "ヂィ",
  "dyu": "ヂュ",
  "dye": "ヂェ",
  "dyo": "ヂョ",
  "ba": "バ",
  "bi": "ビ",
  "bu": "ブ",
  "be": "ベ",
  "bo": "ボ",
  "bya": "ビャ",
  "byi": "ビィ",
  "byu": "ビュ",
  "bye": "ビェ",
  "byo": "ビョ",
  "va": "ヴァ",
  "vi": "ヴィ",
  "vu": "ヴ",
  "ve": "ヴェ",
  "vo": "ヴォ",
  "vya": "ヴャ",
  "vyi": "ヴィ",
  "vyu": "ヴュ",
  "vye": "ヴェ",
  "vyo": "ヴョ",
  "pa": "パ",
  "pi": "ピ",
  "pu": "プ",
  "pe": "ペ",
  "po": "ポ",
  "pya": "ピャ",
  "pyi": "ピィ",
  "pyu": "ピュ",
  "pye": "ピェ",
  "pyo": "ピョ",
  "xa": "ァ",
  "xi": "ィ",
  "xu": "ゥ",
  "xe": "ェ",
  "xo": "ォ",
  "xya": "ャ",
  "xyi": "ィ",
  "xyu": "ュ",
  "xye": "ェ",
  "xyo": "ョ",
  "la": "ァ",
  "li": "ィ",
  "lu": "ゥ",
  "le": "ェ",
  "lo": "ォ",
  "lya": "ャ",
  "lyi": "ィ",
  "lyu": "ュ",
  "lye": "ェ",
  "lyo": "ョ",
  "ltu": "ッ",
  "xtu": "ッ",
  "ltsu": "ッ",
  "xtsu": "ッ"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?