$ show Yurunsoft/ChineseUtil
This is a PHP library for Chinese text processing, providing functions for pinyin conversion (with tone marks, tone numbers, and first letters), pinyin segmentation, simplified/traditional Chinese conversion, number-to-Chinese-spoken conversion, and number-to-Chinese-financial (money) conversion. The library supports multiple data backends: Memory (loads all data from SQLite into memory for performance), SQLite (queries on demand with low memory), JSON (compatibility mode with reduced data), FFI (uses a C++ shared library via PHP FFI for maximum performance), and SwooleFFI (non-blocking FFI for Swoole coroutines). The architecture follows a strategy pattern with a facade (`Chinese` class) that delegates to mode-specific drivers. The code is well-structured, includes comprehensive tests for all modes, and handles edge cases such as multiple character readings (ε€ι³ε) and zero values. The library is self-contained with bundled data files and precompiled FFI binaries for multiple platforms.
The LLM identified 2 files worth highlighting for reuse:
Implements pinyin string segmentation into all possible valid pinyin combinations using a trie-like structure built from the pinyin relation data. The algorithm efficiently explores all possible segmentations by traversing a character-level state machine, handling both pure pinyin strings and mixed Chinese/pinyin text. This is a non-trivial algorithm that could be extracted and reused in other Chinese text processing projects with minimal adaptation, provided the same pinyin relation data structure is available.
Converts numeric values to Chinese financial uppercase (e.g., 123.45 -> ε£Ήδ½°θ΄°ζΎεεθθ§δΌε) and back. Handles large numbers, decimal places, negative values, and zero correctly. The implementation uses arbitrary-precision arithmetic (bcadd, bcmul, bcpow) to avoid floating-point errors. The code is well-organized with separate methods for integer and decimal parts, and includes options like 'tenMin' to control output format. This component is self-contained and could be reused in financial applications requiring Chinese money representation.