Skip to main content

pyokaka

Simple tool for converting [Roma-ji]1 sentences into [Hiragana]2 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

  1. https://en.wikipedia.org/wiki/Romanization_of_Japanese

  2. https://en.wikipedia.org/wiki/Hiragana

Release files for pyokaka 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyokaka 1.0.0
File Size Uploaded
pyokaka-1.0.0.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyokaka 1.0.0
File Interpreter ABI Platform
pyokaka-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / pyokaka-1.0.0.tar.gz

Download URL pyokaka-1.0.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
12c963c5245bd335ba070cfd273f7e34d5fa481416c74371bebe5e6e3746d57c
BLAKE2b-256 checksum
How to use checksums
801f98b23ee9f4910a27df6c1976abad02abade5d3d5b9e66d1be292ebe54fc2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pyokaka-1.0.0-py3-none-any.whl

Download URL pyokaka-1.0.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
332ea1595316c2c870d5c8b7dc4623cd777c1721eb0231c562694d23111c890e
BLAKE2b-256 checksum
How to use checksums
76221683e079784efe30cb58fab92be0e0ba4d812364739d9c1555e821bab8fb
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page