Hanzi Identifier is a Python module designed to identify Chinese text as either Simplified or Traditional characters. It leverages the CC-CEDICT data for character identification. The current stable version is 1.3.0. The library has an irregular release cadence, with major and minor updates occurring every few years.
pip install hanzidentifierVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionality of `hanzidentifier` including checking for Chinese characters, identifying a string's type (Simplified, Traditional, Both, Mixed, Unknown), and using the helper functions `is_simplified` and `is_traditional`.
Refer to the CHANGES.rst file in the GitHub repository for detailed migration steps if upgrading from pre-1.0 versions. Re-evaluate constant names used in your code.
Understand that `BOTH` signifies compatibility with both systems. If you need to confirm if a string *can* be interpreted as Simplified or Traditional, consider if `identify() in (hanzidentifier.SIMPLIFIED, hanzidentifier.BOTH, hanzidentifier.MIXED)` (for Simplified) or similar logic for Traditional, fits your use case.
If differentiating between Chinese, Japanese Kanji, and Korean Hanja is critical, combine `hanzidentifier` with other language detection libraries or specific CJK character set checkers.
Run `pip install hanzidentifier` in your terminal to install the package.
Check the output of `hanzidentifier.identify()` first. If it returns `hanzidentifier.BOTH`, it means the characters are valid in both Simplified and Traditional contexts. Consider what your desired outcome is for such cases.
Use `hanzidentifier.has_chinese()` to confirm the presence of any Chinese characters. `identify()` focuses on categorizing the *type* of Chinese characters, not merely their existence. If a string has few identifiable Chinese characters amidst many non-Chinese, the identification might default to `UNKNOWN`.