Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
mojimoji
https://pypi.org/project/mojimoji/
Admin
mojimoji is a fast Cython-based converter between Japanese hankaku and zenkaku characters.
Tokens:
2,562
Snippets:
32
Trust Score:
10
Update:
5 months ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Install mojimoji Source: https://pypi.org/project/mojimoji Install the mojimoji library using pip. This is the standard way to add Python packages to your project. ```bash pip install mojimoji ``` -------------------------------- ### Benchmark mojimoji vs unicodedata and zenhan Source: https://pypi.org/project/mojimoji Benchmark results show the performance of mojimoji.zen_to_han compared to unicodedata.normalize('NFKC', s) and zenhan.z2h(s) for converting a large string of full-width characters to half-width. The benchmarks are run using IPython's %time magic command. ```python import mojimoji s = 'ABCDEFG012345' * 10 %time for n in range(1000000): mojimoji.zen_to_han(s) ``` ```python %time for n in range(1000000): unicodedata.normalize('NFKC', s) ``` ```python %time for n in range(1000000): zenhan.z2h(s) ``` -------------------------------- ### Convert Hankaku to Zenkaku Characters Source: https://pypi.org/project/mojimoji Use the `han_to_zen` function to convert half-width Japanese characters to full-width. Options `kana`, `digit`, and `ascii` can be set to `False` to disable conversion for specific character types. ```python import mojimoji print(mojimoji.han_to_zen('アイウabc012')) ``` ```python print(mojimoji.han_to_zen('アイウabc012', kana=False)) ``` ```python print(mojimoji.han_to_zen('アイウabc012', digit=False)) ``` ```python print(mojimoji.han_to_zen('アイウabc012', ascii=False)) ``` -------------------------------- ### Convert Zenkaku to Hankaku Characters Source: https://pypi.org/project/mojimoji Use the `zen_to_han` function to convert full-width Japanese characters to half-width. Options `kana`, `digit`, and `ascii` can be set to `False` to disable conversion for specific character types. ```python import mojimoji print(mojimoji.zen_to_han('アイウabc012')) ``` ```python print(mojimoji.zen_to_han('アイウabc012', kana=False)) ``` ```python print(mojimoji.zen_to_han('アイウabc012', digit=False)) ``` ```python print(mojimoji.zen_to_han('アイウabc012', ascii=False)) ```