A Chinese character and language processing toolkit for Python
Project description
cnchar
一个中文成语搜索工具包,提供基于模式匹配和新华字典风格的成语查询功能。
特性
- 🔍 多种搜索模式: 支持模式搜索和新华字典风格搜索
- 📝 详细信息: 提供成语的拼音、解释、例句和出处
- 💻 命令行工具: 提供便捷的命令行界面
- 🐍 Python API: 提供完整的 Python 编程接口
- 💾 结果导出: 支持将结果保存为文本文件或 JSON 格式
安装
pip install cnchar
快速开始
命令行使用
# 模式搜索(第一位是"一",第三位是"二")
cnchar-idiom "一,,二,"
# 新华字典风格搜索
cnchar-idiom --xinhuadict "一:0" "二:2" --limit 5
# 交互模式
cnchar-idiom --interactive
Python API
from cnchar import IdiomSearcher
# 创建搜索器(自动加载包内成语数据)
searcher = IdiomSearcher()
# 模式搜索
results = searcher.search_by_pattern(["字", "", "母", ""])
for idiom in results:
print(f"{idiom['word']} - {idiom['pinyin']}")
# 新华字典风格搜索
results = searcher.get_idiom_by_xinhuadict_detailed(["字", "母"], [0, 2], limit=5)
更多示例
参见 examples/ 目录。
项目结构
cnchar/
└── cnidiom/ # 成语搜索模块
├── core.py # 核心搜索逻辑
├── cli.py # 命令行界面
├── utils.py # 工具函数
└── idiom.json # 成语数据
数据来源
本工具使用新华字典成语数据,数据文件随包分发。
许可证
MIT License
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
cnchar-0.1.0.tar.gz
(3.6 MB
view details)
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 cnchar-0.1.0.tar.gz.
File metadata
- Download URL: cnchar-0.1.0.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
376d550c4ad985ef7ce61a22f468f06c2063ca055d3b54e9292246dcacb50cd9
|
|
| MD5 |
8e7da1510b6638f41876bab0bb5eb084
|
|
| BLAKE2b-256 |
a5bec9ecd02b5adcecbe694968a9f060dbd95437a580e7fa3b073d04dc0d4cb6
|
File details
Details for the file cnchar-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cnchar-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5df4e7dcc426e398b034bd5d7c75900b292ae84ba47551d09e2df57308417135
|
|
| MD5 |
f9ef4848bb656abef78080cce8008115
|
|
| BLAKE2b-256 |
8fcef0a52bfb03f8fa87c4c2006d3759a5be8b3e672947686f819b434fde080c
|