### Install mojimoji Source: https://github.com/studio-ousia/mojimoji/blob/master/README.rst Install the mojimoji library using pip. ```bash pip install mojimoji ``` -------------------------------- ### Compare zenhan performance Source: https://context7.com/studio-ousia/mojimoji/llms.txt This snippet benchmarks the performance of the `zenhan` library for text normalization. It requires separate installation. ```Python import zenhan t3 = timeit.timeit(lambda: zenhan.z2h(s), number=1_000_000) print(f'zenhan: {t3:.2f}s') ``` -------------------------------- ### Git Tagging and Pushing Source: https://github.com/studio-ousia/mojimoji/blob/master/CONTRIBUTING.md Use this command to tag a new version and push it to the GitHub repository. This action triggers the automated build and publish process. ```bash git tag v0.1.0 && git push origin v0.1.0 ``` -------------------------------- ### Performance comparison of mojimoji vs alternatives Source: https://context7.com/studio-ousia/mojimoji/llms.txt Benchmarking mojimoji's `zen_to_han` against `unicodedata.normalize` for large-scale text normalization. Mojimoji shows significant speed advantages. ```python import mojimoji import unicodedata import timeit s = 'ABCDEFG012345' * 10 # mojimoji t1 = timeit.timeit(lambda: mojimoji.zen_to_han(s), number=1_000_000) print(f'mojimoji: {t1:.2f}s') # ~2.9s ``` -------------------------------- ### Benchmark mojimoji vs. others Source: https://github.com/studio-ousia/mojimoji/blob/master/README.rst Performance comparison of mojimoji.zen_to_han against unicodedata.normalize and zenhan.z2h for converting a large string. ```python 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) ``` -------------------------------- ### Selective character conversion with mojimoji flags Source: https://context7.com/studio-ousia/mojimoji/llms.txt Combine `ascii`, `digit`, and `kana` flags in `han_to_zen` for targeted normalization. Demonstrates idempotent round-trip conversion for supported characters. ```python import mojimoji text = 'アイウabc012' # Digits only print(mojimoji.han_to_zen(text, ascii=False, kana=False)) # Output: アイウabc012 # Kana only print(mojimoji.han_to_zen(text, ascii=False, digit=False)) # Output: アイウabc012 # ASCII only print(mojimoji.han_to_zen(text, digit=False, kana=False)) # Output: アイウabc012 # Round-trip: zen_to_han followed by han_to_zen is idempotent for supported chars original = 'アイウabc012' roundtripped = mojimoji.han_to_zen(mojimoji.zen_to_han(original)) print(roundtripped == original) # Output: True ``` -------------------------------- ### Convert Zenkaku to Hankaku Source: https://github.com/studio-ousia/mojimoji/blob/master/README.rst Convert full-width Japanese characters to half-width. Options include controlling kana, digit, and ASCII conversion. ```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)) ``` -------------------------------- ### Convert Hankaku to Zenkaku Source: https://github.com/studio-ousia/mojimoji/blob/master/README.rst Convert half-width Japanese characters to full-width. Options include controlling kana, digit, and ASCII conversion. ```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)) ``` -------------------------------- ### zen_to_han Source: https://context7.com/studio-ousia/mojimoji/llms.txt Converts full-width characters in a string to their half-width equivalents. The boolean parameters `ascii`, `digit`, and `kana` control the conversion of ASCII/punctuation, numeric digits, and katakana characters, respectively. Characters without a half-width counterpart are passed through unchanged. ```APIDOC ## zen_to_han ### Description Converts full-width characters in a string to their half-width equivalents. The three boolean parameters `ascii`, `digit`, and `kana` (all `True` by default) independently control whether ASCII/punctuation, numeric digits, and katakana characters are converted. Characters that have no half-width counterpart (e.g., hiragana) are passed through unchanged. ### Parameters - **ascii** (bool) - Optional - Controls conversion of ASCII/punctuation characters. - **digit** (bool) - Optional - Controls conversion of numeric digits. - **kana** (bool) - Optional - Controls conversion of katakana characters. ### Request Example ```python import mojimoji # Default: convert all three categories print(mojimoji.zen_to_han('アイウabc012')) # Output: アイウabc012 # Skip katakana conversion — only convert ASCII and digits print(mojimoji.zen_to_han('アイウabc012', kana=False)) # Output: アイウabc012 # Skip digit conversion — only convert ASCII and katakana print(mojimoji.zen_to_han('アイウabc012', digit=False)) # Output: アイウabc012 # Skip ASCII/punctuation conversion — only convert katakana and digits print(mojimoji.zen_to_han('アイウabc012', ascii=False)) # Output: アイウabc012 # Voiced/semi-voiced katakana are split into base + combining mark print(mojimoji.zen_to_han('ガギグゲゴ')) # Output: ガギグゲゴ print(mojimoji.zen_to_han('パピプペポ')) # Output: パピプペポ # Hiragana is unchanged (no half-width form exists) print(mojimoji.zen_to_han('あいうえお')) # Output: あいうえお # Special characters and punctuation print(mojimoji.zen_to_han('#?!¥\')) # Output: #?!¥\ ``` ``` -------------------------------- ### Convert zenkaku to hankaku with mojimoji.zen_to_han Source: https://context7.com/studio-ousia/mojimoji/llms.txt Converts full-width Japanese characters to their half-width equivalents. Control conversion of ASCII, digits, and katakana independently using boolean flags. Hiragana characters are not converted. ```python import mojimoji # Default: convert all three categories print(mojimoji.zen_to_han('アイウabc012')) # Output: アイウabc012 # Skip katakana conversion — only convert ASCII and digits print(mojimoji.zen_to_han('アイウabc012', kana=False)) # Output: アイウabc012 # Skip digit conversion — only convert ASCII and katakana print(mojimoji.zen_to_han('アイウabc012', digit=False)) # Output: アイウabc012 # Skip ASCII/punctuation conversion — only convert katakana and digits print(mojimoji.zen_to_han('アイウabc012', ascii=False)) # Output: アイウabc012 # Voiced/semi-voiced katakana are split into base + combining mark print(mojimoji.zen_to_han('ガギグゲゴ')) # Output: ガギグゲゴ print(mojimoji.zen_to_han('パピプペポ')) # Output: パピプペポ # Hiragana is unchanged (no half-width form exists) print(mojimoji.zen_to_han('あいうえお')) # Output: あいうえお # Special characters and punctuation print(mojimoji.zen_to_han('#?!¥\')) # Output: #?!¥\ ``` -------------------------------- ### Convert hankaku to zenkaku with mojimoji.han_to_zen Source: https://context7.com/studio-ousia/mojimoji/llms.txt Converts half-width Japanese characters to their full-width equivalents. Control conversion of ASCII, digits, and katakana independently using boolean flags. This function merges two-character hankaku sequences (base katakana + dakuten/handakuten) into single zenkaku characters. ```python import mojimoji # Default: convert all three categories print(mojimoji.han_to_zen('アイウabc012')) # Output: アイウabc012 # Skip katakana conversion print(mojimoji.han_to_zen('アイウabc012', kana=False)) # Output: アイウabc012 # Skip digit conversion print(mojimoji.han_to_zen('アイウabc012', digit=False)) # Output: アイウabc012 # Skip ASCII/punctuation conversion print(mojimoji.han_to_zen('アイウabc012', ascii=False)) # Output: アイウabc012 # Voiced katakana: two hankaku chars merged into one zenkaku char print(mojimoji.han_to_zen('ガギグゲゴ')) # Output: ガギグゲゴ # Semi-voiced katakana: two hankaku chars merged into one zenkaku char print(mojimoji.han_to_zen('パピプペポ')) # Output: パピプペポ # Hiragana passes through unchanged print(mojimoji.han_to_zen('あいうえお')) # Output: あいうえお # Punctuation and special characters print(mojimoji.han_to_zen('#?!¥\')) # Output: #?!¥\ # Numeric digits print(mojimoji.han_to_zen('0123456789')) # Output: 0123456789 ``` -------------------------------- ### Selective conversion Source: https://context7.com/studio-ousia/mojimoji/llms.txt Demonstrates combining the `ascii`, `digit`, and `kana` flags for targeted normalization of specific character subsets. This is useful for NLP preprocessing. ```APIDOC ## Selective conversion ### Description All four possible selective conversions can be composed by mixing the `ascii`, `digit`, and `kana` flags. This is useful in NLP preprocessing where only a subset of character classes should be normalized. ### Parameters - **ascii** (bool) - Optional - Controls conversion of ASCII/punctuation characters. - **digit** (bool) - Optional - Controls conversion of numeric digits. - **kana** (bool) - Optional - Controls conversion of katakana characters. ### Request Example ```python import mojimoji text = 'アイウabc012' # Digits only print(mojimoji.han_to_zen(text, ascii=False, kana=False)) # Output: アイウabc012 # Kana only print(mojimoji.han_to_zen(text, ascii=False, digit=False)) # Output: アイウabc012 # ASCII only print(mojimoji.han_to_zen(text, digit=False, kana=False)) # Output: アイウabc012 # Round-trip: zen_to_han followed by han_to_zen is idempotent for supported chars original = 'アイウabc012' roundtripped = mojimoji.han_to_zen(mojimoji.zen_to_han(original)) print(roundtripped == original) # Output: True ``` ``` -------------------------------- ### han_to_zen Source: https://context7.com/studio-ousia/mojimoji/llms.txt Converts half-width characters in a string to their full-width equivalents. The boolean flags `ascii`, `digit`, and `kana` control the conversion of ASCII/punctuation, numeric digits, and katakana characters, respectively. This function correctly merges two-character hankaku sequences (e.g., base katakana with dakuten) into a single full-width character. ```APIDOC ## han_to_zen ### Description Converts half-width characters in a string to their full-width equivalents. The same three boolean flags apply. Notably, this function correctly merges two-character hankaku sequences — a base katakana followed by a dakuten `゙` or handakuten `゚` — into a single full-width voiced/semi-voiced katakana character. ### Parameters - **ascii** (bool) - Optional - Controls conversion of ASCII/punctuation characters. - **digit** (bool) - Optional - Controls conversion of numeric digits. - **kana** (bool) - Optional - Controls conversion of katakana characters. ### Request Example ```python import mojimoji # Default: convert all three categories print(mojimoji.han_to_zen('アイウabc012')) # Output: アイウabc012 # Skip katakana conversion print(mojimoji.han_to_zen('アイウabc012', kana=False)) # Output: アイウabc012 # Skip digit conversion print(mojimoji.han_to_zen('アイウabc012', digit=False)) # Output: アイウabc012 # Skip ASCII/punctuation conversion print(mojimoji.han_to_zen('アイウabc012', ascii=False)) # Output: アイウabc012 # Voiced katakana: two hankaku chars merged into one zenkaku char print(mojimoji.han_to_zen('ガギグゲゴ')) # Output: ガギグゲゴ # Semi-voiced katakana: two hankaku chars merged into one zenkaku char print(mojimoji.han_to_zen('パピプペポ')) # Output: パピプペポ # Hiragana passes through unchanged print(mojimoji.han_to_zen('あいうえお')) # Output: あいうえお # Punctuation and special characters print(mojimoji.han_to_zen('#?!¥\')) # Output: #?!¥\ # Numeric digits print(mojimoji.han_to_zen('0123456789')) # Output: 0123456789 ``` ``` -------------------------------- ### Compare unicodedata.normalize performance Source: https://context7.com/studio-ousia/mojimoji/llms.txt This snippet benchmarks the performance of Python's built-in `unicodedata.normalize` function for text normalization. ```Python t2 = timeit.timeit(lambda: unicodedata.normalize('NFKC', s), number=1_000_000) print(f'unicodedata: {t2:.2f}s') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.