Skip to main content

Python implementation of kakasi - kana kanji simple inversion library

Project description

Overview

Documentation Status PyPI version Travis-CI Azure-Pipelines Coverage status

pykakasi is a Python Natural Language Processing (NLP) library to transliterate hiragana, katakana and kanji (Japanese text) into rōmaji (Latin/Roman alphabet).

It is based on the kakasi library, which is written in C.

Examples

Transliterate Japanese text to rōmaji:

>>> import pykakasi
>>>
>>> text = u"かな漢字交じり文"
>>> kakasi = pykakasi.kakasi()
>>> kakasi.setMode("H","a") # Hiragana to ascii, default: no conversion
>>> kakasi.setMode("K","a") # Katakana to ascii, default: no conversion
>>> kakasi.setMode("J","a") # Japanese to ascii, default: no conversion
>>> kakasi.setMode("r","Hepburn") # default: use Hepburn Roman table
>>> kakasi.setMode("s", True) # add space, default: no separator
>>> kakasi.setMode("C", True) # capitalize, default: no capitalize
>>> conv = kakasi.getConverter()
>>> result = conv.do(text)
>>> print(result)
kana Kanji Majiri Bun

Tokenize Japanese text (split by word boundaries), equivalent to kakasi’s wakati gaki option:

>>> wakati = pykakasi.wakati()
>>> conv = wakati.getConverter()
>>> result = conv.do(text)
>>> print(result)
かな 漢字 交じり 文

Add furigana (pronounciation aid) in rōmaji to text:

>>> kakasi = pykakasi.kakasi()
>>> kakasi.setMode("J","aF") # Japanese to furigana
>>> kakasi.setMode("H","aF") # Japanese to furigana
>>> conv = kakasi.getConverter()
>>> result = conv.do(text)
>>> print(result)
かな[kana] 漢字[Kanji] 交じり[Majiri] 文[Bun]

Input mode values: “J” (Japanese: kanji, hiragana and katakana), “H” (hiragana), “K” (katakana).

Output mode values: “H” (hiragana), “K” (katakana), “a” (alphabet / rōmaji), “aF” (furigana in rōmaji).

There are other setMode switches which control output:

  • “r”: Romanisation table: Hepburn (default), Kunrei or Passport

  • “s”: Separator: False adds no spaces between words (default), True adds spaces between words

  • “C”: Capitalize: False adds no capital letters (default), True makes each word start with a capital letter

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

pykakasi-1.1b1.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykakasi-1.1b1-py2.py3-none-any.whl (2.4 MB view details)

Uploaded Python 2Python 3

File details

Details for the file pykakasi-1.1b1.tar.gz.

File metadata

  • Download URL: pykakasi-1.1b1.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for pykakasi-1.1b1.tar.gz
Algorithm Hash digest
SHA256 868fee8855bb66a1dbc4c6b63c26a04bdbb6c31454415ccd322da79348bc5e13
MD5 ed20516f83ec51dcac997af0b6cba8c1
BLAKE2b-256 5e119b9f991441fd5478bcb0ae63e05842a0a352645ad35d5d5b07d8891423a0

See more details on using hashes here.

File details

Details for the file pykakasi-1.1b1-py2.py3-none-any.whl.

File metadata

  • Download URL: pykakasi-1.1b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for pykakasi-1.1b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b86ee1f17b8f4e0581fd82f3e859debce66bfc3be3d7012e7c5d2a404204bcc3
MD5 dadcecec93b24d791e2006270b04411b
BLAKE2b-256 071d2063135afd0a954457f9b3a4f04680ad4260a14a6e5dcd2f6c0018676b75

See more details on using hashes here.

Supported by

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