# text-tool **Repository Path**: mooremok/text-tool ## Basic Information - **Project Name**: text-tool - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-26 - **Last Updated**: 2025-08-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Text-Tool: 专业的文本处理工具库 [![PyPI version](https://badge.fury.io/py/text-tool.svg)](https://badge.fury.io/py/text-tool) [![Python Version](https://img.shields.io/pypi/pyversions/text-tool.svg)](https://pypi.org/project/text-tool/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Downloads](https://pepy.tech/badge/text-tool)](https://pepy.tech/project/text-tool) 专业的文本处理工具库,提供高精度的字数统计功能,特别优化了中英文混合文本和学术文献的处理。 ## ✨ 特性 - 🌏 **多语言支持**: 支持中英文混合文本 - 🔢 **字数统计**: 接近Micsoft Office文档的字数统计机制 - 🧹 **空格清理**: 智能清理多余空格,优化中英文混排 - 🔧 **符号修复**: 修复中英文混合情况下的标点符号修复以及圆括号修复 - 🧪 **测试覆盖率**: 99%测试覆盖率 ## 📦 安装 ```bash pip install text-tool ``` ## 🚀 快速开始 ### Python API ```python from text_tool import count_words, remove_extra_spaces, fix_symbols # 基础字数统计 count_words("Hello世界") # 返回: 3 # 英文撇号单词 count_words("don't worry") # 返回: 2 # 中英文混合 count_words("我在学习Python编程") # 返回: 6 # Word兼容模式(学术文献) text = "[1]王海燕.诗意表达与历史记忆的交织——从《活着》看当代文学[J].新传奇,2025,(10):10-12." count_words(text, word_compatible=True) # 返回: 34 # 特殊数字格式 count_words("成绩提高了5.2%", word_compatible=True) # 返回: 6 # 清理多余空格 remove_extra_spaces("这是 有 多余 space 的文本") # 返回: "这是有多余空格的文本" remove_extra_spaces("English with extra spaces") # 返回: "English with extra spaces" # 修复符号格式 fix_symbols("这是中文(1)括号") # 返回: "这是中文(1)括号" fix_symbols("English(1)bracket") # 返回: "English(1)bracket" fix_symbols("中文,逗号,测试") # 返回: "中文,逗号,测试" ``` ### 字数统计规则 - **汉字**: 每个算1字 - **英文字母**: 每个算1字 - **特殊数字格式**: 整个算1字 - 小数: `3.14` → 1字 - 百分数: `95.5%` → 1字 - 分数: `1/2` → 1字 - 对比: `3>2` → 1字 - 方括号数字: `[1]` → 1字 - 圆括号数字: `(10)` → 1字 - 数字范围: `10-12` → 1字 - 年份: `2025` → 1字 - **标点符号**: 每个算1字,但排除格式化标点(逗号、句号、冒号) - **成对符号**: 开闭符号算2字(如《》、()) ## 📄 许可证 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。