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.

日本語をローマ字にする

Posted at

##pykakasiをインストールする
このモジュールを使うことで日本語文字をローマ字に変換できる

pip install pykakasi

##引値をローマ字に変換する関数を作る。

from pykakasi import kakasi
kakasi = kakasi()
def jp2rome(text):
    kakasi.setMode("H", "a")  # Hiragana to ascii
    kakasi.setMode("K", "a")  # Katakana to ascii
    kakasi.setMode("J", "a")  # Japanese(kanji) to ascii
    kakasi.setMode("r", "Hepburn")  # Use Hepburn romanization
    conv = kakasi.getConverter()
    result = conv.do(text)
    return(result)

##使用例

jp2rome("てすと")
→'tesuto'
jp2rome("テスト")
→'tesuto'
jp2rome("試験")
→'shiken'
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?