智能Unicode部首转换工具
Project description
Unicode Radical Converter
一个智能的Unicode部首转换工具,用于将CJK(中日韩)部首字符转换为对应的完整汉字。
特性
- 🚀 智能识别:自动识别Unicode中的CJK部首字符
- 🎯 精准转换:基于Unicode名称和预设映射的高效转换
- 🔧 灵活配置:支持多种转换方法和自定义映射
- 📦 易于使用:简单的API和命令行工具
- 🧪 完全测试:高覆盖率的单元测试
安装
# 使用pip安装
pip install unicode-radical-converter
# 从源码安装
git clone https://github.com/yourusername/unicode-radical-converter.git
cd unicode-radical-converter
pip install -e .
快速开始
Python API
from unicode_radical_converter import convert
# 基本转换
print(convert('⻩金时代')) # 输出: 黄金时代
print(convert('⻌向未来')) # 输出: 走向未来
print(convert('⻨田风光')) # 输出: 麦田风光
# 批量转换
texts = ['⻩金时代', '⻌向未来', '普通文本']
results = convert_batch(texts)
print(results) # ['黄金时代', '走向未来', '普通文本']
命令行工具
# 转换文本
urc convert "⻩金时代"
# 从文件读取并转换
urc convert -f input.txt -o output.txt
# 分析文本中的部首
urc analyze "⻩⻌⻨⻬"
# 列出所有映射
urc list
# 检查字符是否是部首
urc check "⻩"
# 添加新映射
urc add "⻡" "象"
# 查看统计信息
urc stats
高级用法
自定义转换器
from unicode_radical_converter import RadicalConverter
# 创建转换器实例
converter = RadicalConverter()
# 转换文本
result = converter.convert('⻩金⻌在⻨田')
# 分析文本
analysis = converter.analyze_text('⻩金⻌在⻨田')
for item in analysis:
print(f"位置{item['position']}: {item['radical']} -> {item['maps_to']}")
# 添加自定义映射
converter.add_mapping('⚡', '闪')
print(converter.convert('⚡光')) # 输出: 闪光
转换方法
from unicode_radical_converter import convert
text = '⻩金时代'
# 自动转换(先尝试Unicode标准化,再使用映射表)
print(convert(text, method='auto'))
# 仅使用映射表
print(convert(text, method='mapping_only'))
# 仅使用Unicode标准化
print(convert(text, method='normalize_only'))
支持的部首
本工具支持多种类型的部首:
-
CJK部首补充 (U+2E80-U+2EFF)
- 例:⻩ (黄), ⻌ (走), ⻨ (麦)
-
康熙部首 (U+2F00-U+2FDF)
- 例:⾚ (赤), ⾨ (門), ⾛ (走)
-
CJK简化部首
- 例:⻬ (黑), ⻭ (黹)
API 参考
函数接口
convert(text, method='auto')- 转换文本convert_batch(text_list, method='auto')- 批量转换analyze_text(text)- 分析文本中的部首is_radical(char)- 检查是否是部首add_mapping(radical, hanzi)- 添加映射
类接口
RadicalConverter- 核心转换器类MappingStrategy- 映射策略类
贡献
欢迎贡献代码!请遵循以下步骤:
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
开发环境设置
# 克隆仓库
git clone https://github.com/yourusername/unicode-radical-converter.git
cd unicode-radical-converter
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 代码格式化
black unicode_radical_converter tests
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
更新日志
v0.1.0 (2024-01-01)
- 初始版本发布
- 支持基本的部首转换功能
- 提供Python API和命令行工具
- 包含完整的测试套件
致谢
- Unicode标准中的CJK部首定义
- 康熙部首系统
- 所有贡献者和用户的支持
联系方式
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unicode_radical_converter-0.1.0.tar.gz.
File metadata
- Download URL: unicode_radical_converter-0.1.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33762d9c347ac558ac6d25d441e4c38e50c2d718bb44943f90c1eccac57f1c8d
|
|
| MD5 |
9b84b4fd9cd21a737640ff13eecb1ad8
|
|
| BLAKE2b-256 |
9d5db1379b5b2a0f9ed9b33fee25cee34ad86b9ae4355cde675741ff4e4468e9
|
File details
Details for the file unicode_radical_converter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: unicode_radical_converter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df263defdb548d6bb6b7a393f80ea1c70aa87ee38eb469fb57bd57434cedbe35
|
|
| MD5 |
a10ae636f2a8ebf6151eaddc609f1cf4
|
|
| BLAKE2b-256 |
a97e522c018fa69968c6d862807865f2d38ea00a55622c556bb9e9b1de8d2d31
|