Skip to main content

A fast converter between Japanese hankaku and zenkaku characters

Project description

https://badge.fury.io/py/mojimoji.png https://github.com/studio-ousia/mojimoji/workflows/build%20manylinux/badge.svg https://github.com/studio-ousia/mojimoji/workflows/build%20macos%20and%20win/badge.svg

A fast converter between Japanese hankaku and zenkaku characters.

Installation

$ pip install mojimoji

Examples

Zenkaku to Hankaku

>>> import mojimoji
>>> print mojimoji.zen_to_han(u'アイウabc012')
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', kana=False)
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', digit=False)
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', ascii=False)
アイウabc012

Hankaku to Zenkaku

>>> import mojimoji
>>> print mojimoji.han_to_zen(u'アイウabc012')
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', kana=False)
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', digit=False)
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', ascii=False)
アイウabc012

Benchmarks

Library versions

Results

In [19]: s = u'ABCDEFG012345' * 10

In [20]: %time for n in range(1000000): mojimoji.zen_to_han(s)
CPU times: user 2.86 s, sys: 0.10 s, total: 2.97 s
Wall time: 2.88 s

In [21]: %time for n in range(1000000): unicodedata.normalize('NFKC', s)
CPU times: user 5.43 s, sys: 0.12 s, total: 5.55 s
Wall time: 5.44 s

In [22]: %time for n in range(1000000): zenhan.z2h(s)
CPU times: user 69.18 s, sys: 0.11 s, total: 69.29 s
Wall time: 69.48 s

Project details


Download files

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

Files for mojimoji, version 0.0.11
Filename, size File type Python version Upload date Hashes
Filename, size mojimoji-0.0.11-cp35-cp35m-macosx_10_14_x86_64.whl (38.4 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp35-cp35m-manylinux1_x86_64.whl (122.6 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp35-cp35m-win_amd64.whl (34.0 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp36-cp36m-macosx_10_14_x86_64.whl (41.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp36-cp36m-manylinux1_x86_64.whl (126.3 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp36-cp36m-win_amd64.whl (35.5 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp37-cp37m-macosx_10_14_x86_64.whl (41.5 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp37-cp37m-manylinux1_x86_64.whl (127.6 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp37-cp37m-win_amd64.whl (35.5 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp38-cp38-macosx_10_14_x86_64.whl (41.9 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp38-cp38-manylinux1_x86_64.whl (131.3 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size mojimoji-0.0.11-cp38-cp38-win_amd64.whl (35.9 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size mojimoji-0.0.11.tar.gz (42.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page