Skip to main content

Simple tool to translate from Roma-ji into Hiragana.

Project description

pyokaka

Simple tool for converting Roma-ji sentences into Hiragana one.
ローマ字の文を平仮名に変換するシンプルなツールです。

The origin of package name

An homage to pykakashi that provides highly function to convert Kana-Kanji into Roma-ji. Okaka(おかか) is easy Japanese word that mean bonito flakes.

Demo

As command line tool
Use as REPL just by calling from terminal. To quit, send EOF.

$ python -m pyokaka.okaka

Roman >>> ohayougozaimasu
JKana ... おはようございます
Roman >>> kon'nichiwa
JKana ... こんにちわ
Roman >>> oyasuminasai
JKana ... おやすみなさい

You can indicate file you want to convert.

$ cat sample.txt
Ima wa mukashi, taketori no okina to iu mono ari keri.

$ python -m pyokaka.okaka sample.txt
いま わ むかし, たけとり の おきな と いう もの あり けり.

To apply additional rule, load utf-8 encoded json file.

{
    "ら": ["la"], "り": ["li"], "る": ["lu"], "れ": ["le"], "ろ": ["lo"],
    "ふぁ": ["pha", "hua"], "ふぃ": ["phi"]
}
$ cat sample.txt
elephant
lalallalalla

$ python -m pyokaka.okaka sample.txt
えlえpはんt
lあlあllあlあllあ

$ python -m pyokaka.okaka sample.txt --load sample.json
load for sample.json...
えれふぁんt
ららっららっら

For more information, view python -m pyokaka.okaka --help.

As library

>>> from pyokaka import okaka
>>> okaka.convert('katsuobushi')
'かつおぶし'

You can add more vocabulary as described below.

>>> okaka.convert('philipps')
'pひlいpps'
>>>
>>> okaka.update_convert_dct({
...     'p': 'ぷ', 's': 'す'
... })
>>>
>>> okaka.convert('philips')
'ぷひlいぷす'
>>>
>>> import json
>>> with open('sample.json', encoding='utf-8') as fin:
...     table = json.load(fin)
...
>>> okaka.update_transtable(table)
>>> okaka.convert('philips')
'ふぃりぷす'

Notes

  • You cannot reset convert table without restart.

  • Though converter ignores letter what can be not interpret as a part of Roma-ji, remaining letters always be converted.

    $ python -m pyokaka.okaka
    Roman >>> Oh dear, this is English!
    JKana ... おh であr, tひs いs えんglいsh!
    
  • Hyphen always be replaced with Cho'onpu.

    $ python -m pyokaka.okaka
    Roman >>> Roma-ji
    JKana ... ろまーじ
    
  • Converter never analyze sentence structure. So it cannot recognize 'wa', 'o' and 'e' as postpositional particle.

    $ python -m pyokaka.okaka
    Roman >>> Watashi wa depa-to e enpitsu o kai ni ikimashita.
    JKana ... わたし わ でぱーと え えんぴつ お かい に いきました.
    
  • Conversion is based on greedy algorithm. Single quote can be used as separater if you need.

    Roman >>> honya
    JKana ... ほにゃ
    Roman >>> honnya
    JKana ... ほっにゃ
    Roman >>> honnnya
    JKana ... ほんにゃ
    
    Roman >>> hon'ya
    JKana ... ほんや
    

Install

This module is registered at PyPI. PyPI - pyokaka

$ pip install pyokaka

License

MIT

Author

LouiS0616

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyokaka-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

pyokaka-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file pyokaka-1.0.0.tar.gz.

File metadata

  • Download URL: pyokaka-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for pyokaka-1.0.0.tar.gz
Algorithm Hash digest
SHA256 12c963c5245bd335ba070cfd273f7e34d5fa481416c74371bebe5e6e3746d57c
MD5 c06081ae98ca95edbeee0154fbddef4d
BLAKE2b-256 801f98b23ee9f4910a27df6c1976abad02abade5d3d5b9e66d1be292ebe54fc2

See more details on using hashes here.

File details

Details for the file pyokaka-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyokaka-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for pyokaka-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 332ea1595316c2c870d5c8b7dc4623cd777c1721eb0231c562694d23111c890e
MD5 cfda7716f79196d3f8a5f8685299c35c
BLAKE2b-256 76221683e079784efe30cb58fab92be0e0ba4d812364739d9c1555e821bab8fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page