{"id":20839286,"url":"https://github.com/ailln/cn2an","last_synced_at":"2025-05-14T04:07:45.225Z","repository":{"id":44454225,"uuid":"132175966","full_name":"Ailln/cn2an","owner":"Ailln","description":"📦 快速转化「中文数字」和「阿拉伯数字」～ (最新特性：分数，日期、温度等转化）","archived":false,"fork":false,"pushed_at":"2024-12-21T14:53:05.000Z","size":701,"stargazers_count":716,"open_issues_count":22,"forks_count":79,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T03:37:18.244Z","etag":null,"topics":["arabic-numbers","arabic-numerals","asr","chinese-numerals","cn2an","nlp-library","nlp-tool","pypi","python","speech-recognition"],"latest_commit_sha":null,"homepage":"https://www.dovolopor.com/cn2an","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ailln.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-04T18:33:34.000Z","updated_at":"2025-04-11T01:40:43.000Z","dependencies_parsed_at":"2025-01-20T10:00:24.154Z","dependency_job_id":"2ef6120c-e425-4803-b758-fb35e8ae99a3","html_url":"https://github.com/Ailln/cn2an","commit_stats":{"total_commits":125,"total_committers":5,"mean_commits":25.0,"dds":0.06399999999999995,"last_synced_commit":"06369050592e1df7da44d273924edec2d8977601"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ailln%2Fcn2an","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ailln%2Fcn2an/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ailln%2Fcn2an/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ailln%2Fcn2an/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ailln","download_url":"https://codeload.github.com/Ailln/cn2an/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069596,"owners_count":22009558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arabic-numbers","arabic-numerals","asr","chinese-numerals","cn2an","nlp-library","nlp-tool","pypi","python","speech-recognition"],"created_at":"2024-11-18T01:13:10.765Z","updated_at":"2025-05-14T04:07:45.196Z","avatar_url":"https://github.com/Ailln.png","language":"Python","readme":"# cn2an: Chinese Numerals To Arabic Numerals\n\n[![Pypi](https://img.shields.io/pypi/v/cn2an.svg)](https://pypi.org/project/cn2an/)\n[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/Ailln/cn2an/blob/master/LICENSE)\n[![stars](https://img.shields.io/github/stars/Ailln/cn2an.svg)](https://github.com/Ailln/cn2an/stargazers)\n[![build](https://img.shields.io/github/actions/workflow/status/Ailln/cn2an/build.yml)](https://github.com/Ailln/cn2an/actions/workflows/build.yml)\n[![API](https://img.shields.io/badge/API-reference-pink.svg)](https://github.com/Ailln/cn2an/wiki/API)\n[![download month](https://img.shields.io/pypi/dm/cn2an)](https://pypistats.org/packages/cn2an)\n\n📦 **`cn2an`** 是一个快速转化 `中文数字` 和 `阿拉伯数字` 的工具包！\n\n[![](https://ailln.oss-cn-hangzhou.aliyuncs.com/github/cn2an/cn2an-site-latest.png)](https://www.dovolopor.com/cn2an)\n\n🔗[点击访问 DEMO](https://www.dovolopor.com/cn2an)\n\n\u003e 🎈 `v0.5.23 update`: delete setuptools in requirements.txt\n\u003e \n\u003e 🎈 [`en2an`](https://github.com/Ailln/en2an): 「英文数字」和「阿拉伯数字」互转正在收集需求中！ [详情](https://github.com/Ailln/en2an)\n\u003e\n\u003e 🎈 [`Cn2An.jl`](https://github.com/Ailln/Cn2An.jl): Julia 语言版本已经上线，正在丰富基础功能。[详情](https://github.com/Ailln/Cn2An.jl)\n\n## 1 功能\n\n### 1.1 `中文数字` =\u003e `阿拉伯数字`\n\n- 支持 `中文数字` =\u003e `阿拉伯数字`；\n- 支持 `大写中文数字` =\u003e `阿拉伯数字`；\n- 支持 `中文数字和阿拉伯数字` =\u003e `阿拉伯数字`；\n\n### 1.2 `阿拉伯数字` =\u003e `中文数字`\n\n- 支持 `阿拉伯数字` =\u003e `中文数字`；\n- 支持 `阿拉伯数字` =\u003e `大写中文数字`；\n- 支持 `阿拉伯数字` =\u003e `大写人民币`；\n\n### 1.3 句子转化\n\n- 支持 `中文数字` =\u003e `阿拉伯数字`；\n    - 支持 `日期`；\n    - 支持 `分数`；\n    - 支持 `百分比`；\n    - 支持 `摄氏度`；\n\n- 支持 `阿拉伯数字` =\u003e `中文数字`；\n    - 支持 `日期`；\n    - 支持 `分数`；\n    - 支持 `百分比`；\n    - 支持 `摄氏度`；\n\n### 1.4 其他\n\n- 支持 `小数`；\n- 支持 `负数`；\n- 支持 `HTTP API`。\n\n## 2 安装\n\n\u003e ⚠️ 注意：\n\u003e 1. 本地安装仅支持 Python 的 3.6 以上版本；\n\u003e 2. 其他语言用户可以考虑使用 [HTTP API](https://www.dovolopor.com/api/cn2an) ；\n\u003e 3. 尽可能使用 `cn2an` 的最新版本。\n\n### 2.1 使用 pip 安装\n\n```shell\npip install cn2an -U\n```\n\n### 2.2 从代码库安装\n\n```shell\ngit clone https://github.com/Ailln/cn2an.git\ncd cn2an \u0026\u0026 python setup.py install\n```\n\n## 3 使用\n\n```python\n# 在文件首部引入包\nimport cn2an\n\n# 查看当前版本号\nprint(cn2an.__version__)\n# 0.5.23\n```\n\n### 3.1 `中文数字` =\u003e `阿拉伯数字`\n\n\u003e 最大支持到 `10**16`，即 `千万亿`，最小支持到 `10**-16`。\n\n```python\nimport cn2an\n\n# 在 strict 模式（默认）下，只有严格符合数字拼写的才可以进行转化\noutput = cn2an.cn2an(\"一百二十三\")\n# 或者\noutput = cn2an.cn2an(\"一百二十三\", \"strict\")\n# output:\n# 123\n\n# 在 normal 模式下，可以将 一二三 进行转化\noutput = cn2an.cn2an(\"一二三\", \"normal\")\n# output:\n# 123\n\n# 在 smart 模式下，可以将混合拼写的 1百23 进行转化\noutput = cn2an.cn2an(\"1百23\", \"smart\")\n# output:\n# 123\n\n# 以上三种模式均支持负数\noutput = cn2an.cn2an(\"负一百二十三\", \"strict\")\n# output:\n# -123\n\n# 以上三种模式均支持小数\noutput = cn2an.cn2an(\"一点二三\", \"strict\")\n# output:\n# 1.23\n```\n\n### 3.2 `阿拉伯数字` =\u003e `中文数字`\n\n\u003e 最大支持到`10**16`，即`千万亿`，最小支持到 `10**-16`。\n\n```python\nimport cn2an\n\n# 在 low 模式（默认）下，数字转化为小写的中文数字\noutput = cn2an.an2cn(\"123\")\n# 或者\noutput = cn2an.an2cn(\"123\", \"low\")\n# output:\n# 一百二十三\n\n# 在 up 模式下，数字转化为大写的中文数字\noutput = cn2an.an2cn(\"123\", \"up\")\n# output:\n# 壹佰贰拾叁\n\n# 在 rmb 模式下，数字转化为人民币专用的描述\noutput = cn2an.an2cn(\"123\", \"rmb\")\n# output:\n# 壹佰贰拾叁元整\n\n# 以上三种模式均支持负数\noutput = cn2an.an2cn(\"-123\", \"low\")\n# output:\n# 负一百二十三\n\n# 以上三种模式均支持小数\noutput = cn2an.an2cn(\"1.23\", \"low\")\n# output:\n# 一点二三\n```\n\n### 3.3 句子转化\n\n\u003e ⚠️：试验性功能，可能会造成不符合期望的转化。\n\n```python\nimport cn2an\n\n# 在 cn2an 方法（默认）下，可以将句子中的中文数字转成阿拉伯数字\noutput = cn2an.transform(\"小王捡了一百块钱\")\n# 或者\noutput = cn2an.transform(\"小王捡了一百块钱\", \"cn2an\")\n# output:\n# 小王捡了100块钱\n\n# 在 an2cn 方法下，可以将句子中的中文数字转成阿拉伯数字\noutput = cn2an.transform(\"小王捡了100块钱\", \"an2cn\")\n# output:\n# 小王捡了一百块钱\n\n\n## 支持日期\noutput = cn2an.transform(\"小王的生日是二零零一年三月四日\", \"cn2an\")\n# output:\n# 小王的生日是2001年3月4日\n\noutput = cn2an.transform(\"小王的生日是2001年3月4日\", \"an2cn\")\n# output:\n# 小王的生日是二零零一年三月四日\n\n\n## 支持分数\noutput = cn2an.transform(\"抛出去的硬币为正面的概率是二分之一\", \"cn2an\")\n# output:\n# 抛出去的硬币为正面的概率是1/2\n\noutput = cn2an.transform(\"抛出去的硬币为正面的概率是1/2\", \"an2cn\")\n# output:\n# 抛出去的硬币为正面的概率是二分之一\n\n## 支持百分比\n## 支持摄氏度\n```\n\n### 3.4 HTTP API\n\n主要为其他语言（Java、Javascript、Go等）用户提供方便，当然 Python 用户也可以使用，点击查看[详细用法](https://github.com/Ailln/cn2an/wiki/API#http-api)。\n\n## 4 版本支持\n\n- 理论上支持 `Windows`、`MacOS`、`Ubuntu` 下的所有 `Python 3.6+` 的版本。\n- 实际上仅在 `ubuntu-latest`、`windows-latest`、`macOS-latest` 的 `Python 3.6, 3.7, 3.8` 上做过完整测试。\n- 欢迎提交其他版本使用情况到 [Issues](https://github.com/Ailln/cn2an/issues) 中，期待你的反馈。\n- 如果你有 `Python 2` 的使用需求，可 Fork 代码自行修改。当然也欢迎提 PR，贡献自己代码给其他人。\n\n## 5 问题反馈\n\n1. 先搜索 [Issues](https://github.com/Ailln/cn2an/issues) 中有没有人已经问过类似的问题；\n2. 如果没有找到解答，请新开一个 issue：\n    1. 首先，在「issue 标题」中填写你遇到的问题的简介；\n    2. 然后，在「issue 详情」中填写你遇到的问题的详情；\n    3. 最后，不要忘记注明你使用的操作系统（比如 Windows 10）和 Python 版本（比如 Python 3.6.3）。\n3. 还可以参考 [Issue Template](https://github.com/Ailln/cn2an/tree/master/.github/ISSUE_TEMPLATE) 。\n\n## 6 开发相关\n\n### 6.1 开发进度\n\n本项目是用看板管理开发进度，请点击 [v0.5](https://github.com/Ailln/cn2an/projects/4) 查看开发进度和计划事项。\n\n### 6.2 代码测试\n\n本地测试使用 [Anaconda](https://www.anaconda.com/) 的虚拟环境，测试方法如下：\n\n```bash\n# 执行测试\nbash scripts/local_test.sh\n```\n\n线上测试使用 [GitHub Actions](https://github.com/Ailln/cn2an/actions) 。\n\n### 6.3 性能测试\n\n- 测试版本：`v0.5.1`\n- 测试设备：`2.3 GHz 双核Intel Core i5 MacBook Pro`\n- 测试代码：[performance.py](https://github.com/Ailln/cn2an/tree/master/cn2an/performance.py)\n- 测试方法：\n\n    ```bash\n    pip install -r requirements_test.txt\n\n    python -m cn2an.performance\n    ```\n\n- 测试结果：\n\n    | 序号 |  功能   | 执行次数  | 执行时间(万次平均) | 性能(次/秒) |\n    |:--:|:-----:|:-----:|:----------:|:-------:|\n    | 1  | an2cn | 10000 |    0.15    | **67k** |\n    | 2  | cn2an | 10000 |    0.35    | **29k** |\n\n测试时，我使用的是最大长度的测试数据！因此，大多数情况下该库的性能会更好～\n\n## 7 许可证\n\n[![](https://award.dovolopor.com?lt=License\u0026rt=MIT\u0026rbc=green)](./LICENSE)\n[![](https://award.dovolopor.com?lt=Ailln's\u0026rt=idea\u0026lbc=lightgray\u0026rbc=red\u0026ltc=red)](https://github.com/Ailln/award)\n\n## 8 交流\n\n欢迎添加微信号：`Ailln_`，备注「cn2an」，邀请你进入 Python 交流群。\n\n## 9 致谢\n\n- [Thunder Bouble](https://github.com/sfyc23): 提出很多有效的反馈，包括一些 bug 和新功能；\n- [Damon Yu](https://github.com/20071313): 增加对全角数字和全角符号的支持；\n- [Beants](https://github.com/Beants): 修复了口语格式的 bug；\n- Ray: 提出修改输出 warn 的方法，以及其他一些建议。\n\n## 10 参考\n\n- [🎈 cn2an 核心代码解析](https://www.v2ai.cn/2020/06/30/python/8-cn2an/)\n- [如何发布自己的包到 pypi](https://www.v2ai.cn/2018/07/30/python/1-pypi/)\n- [Python 中的小陷阱](https://www.v2ai.cn/2019/01/01/python/4-python-trap/)\n- [汉字数字转阿拉伯数字](https://www.zouyesheng.com/han-number-convert.html)\n- [Chinese Text Normalization for Speech Processing](https://github.com/speechio/chinese_text_normalization)\n- [The Best Tool of Chinese Number to Digits](https://github.com/Wall-ee/chinese2digits)\n- [Microsoft Recognizers Text Overview](https://github.com/microsoft/Recognizers-Text)\n- [process: 数据预处理管道](https://github.com/Ailln/proces)\n- [wikipedia: 中文数字](https://zh.wikipedia.org/zh-sg/%E4%B8%AD%E6%96%87%E6%95%B0%E5%AD%97)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failln%2Fcn2an","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Failln%2Fcn2an","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failln%2Fcn2an/lists"}