mojimoji

repository·master·Indexed 41 days ago

https://github.com/studio-ousia/mojimoji

A high-performance Cython-based library for fast conversion between Japanese half-width (hankaku) and full-width (zenkaku) characters, featuring functions like mojimoji.zen_to_han and mojimoji.han_to_zen with configurable flags for kana, digits, and ASCII.

Tokens
585
Snippets
3
Records
3
Agent score
50%

What's inside mojimoji

  1. Convert Hankaku to Zenkaku characters

    master

    Use mojimoji.han_to_zen(text, ...) to convert half-width (hankaku) characters to full-width (zenkaku) characters. You can control which character sets are converted using boolean flags:

    • kana: If False, katakana characters are not converted.
    • digit: If False, numeric digits are not converted.
    • ascii: If False, ASCII characters are not converted.
    import mojimoji
    
    # Default conversion
    print(mojimoji.han_to_zen('アイウabc012'))
    # Output: アイウabc012
    
    # Selective conversion
    print(mojimoji.han_to_zen('アイウabc012', kana=False))  # Output: アイウabc012
    print(mojimoji.han_to_zen('アイウabc012', digit=False)) # Output: アイウabc012
    print(mojimoji.han_to_zen('アイウabc012', ascii=False)) # Output: アイウabc012
  2. Convert Zenkaku to Hankaku characters

    master

    Use mojimoji.zen_to_han(text, ...) to convert full-width (zenkaku) characters to half-width (hankaku) characters. You can control which character sets are converted using boolean flags:

    • kana: If False, katakana characters are not converted.
    • digit: If False, numeric digits are not converted.
    • ascii: If False, ASCII characters are not converted.
    import mojimoji
    
    # Default conversion
    print(mojimoji.zen_to_han('アイウabc012'))
    # Output: アイウabc012
    
    # Selective conversion
    print(mojimoji.zen_to_han('アイウabc012', kana=False))  # Output: アイウabc012
    print(mojimoji.zen_to_han('アイウabc012', digit=False)) # Output: アイウabc012
    print(mojimoji.zen_to_han('アイウabc012', ascii=False)) # Output: アイウabc012