一个用于清理原始文本数据的开源python包

cleantext的Python项目详细描述


纯文本

cleantext是一个用于清理原始文本数据的开源python包。库的源代码可以找到here.

特点

cleantext有两种主要方法

  • clean:清除原始文本并返回清理后的文本
  • clean_words:清除原始文本并返回干净单词列表

cleantext可以应用以下所有清理操作或选定的组合:

  • 删除多余的空白
  • 将整个文本转换为统一的小写
  • 从文本中删除数字
  • 删除文本中的标点符号
  • 删除停止语,然后选择停止语的语言 (停止词通常是无意义语言中最常见的词,如is、am、the、this、are等)
  • 停止说话 (词干分析是将具有相似含义的单词转换成单个单词的过程。例如,单词run,runs,running will result run,run,run)

安装

cleantext需要Python 3NLTK才能执行。在

要使用pip安装,请使用

pip install cleantext

使用

  • 导入库
importcleantext
  • 选择方法:

要以字符串格式返回文本

^{pr2}$

要返回文本中的单词列表

cleantext.clean_words("your_raw_text_here",all=True)

要选择一组特定的清洁操作

cleantext.clean_words("your_raw_text_here",all=False# Execute all cleaning operationsextra_spaces=True,# Remove extra white space stemming=True,# Stem the wordsstopwords=True,# Remove stop wordslowercase=True,# Convert to lowercasenumbers=True,# Remove all digits punct=True,# Remove all punctuationsstp_lang='english'# Language for stop words)

示例

importcleantextcleantext.clean('This is A s$ample !!!! tExt3% to   cleaN566556+2+59*/133',extra_spaces=True,lowercase=True,numbers=True,punct=True)

回报率

'this is a sample text to clean'

importcleantextcleantext.clean_words('This is A s$ample !!!! tExt3% to   cleaN566556+2+59*/133',all=True)

回报率

['sampl','text','clean']

许可证

麻省理工学院

如有任何问题、问题、错误和建议,请访问here

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何创建Restful服务并将其部署到OSGi容器?   java如何获取用户在EditText中输入的时间并从中扣除5小时30分钟?   java用户无法注销firebase 安卓   java Undertow始终将字符集添加到ContentType头,即使它不是文本MIME类型   java LocalBroadcastManager未正确接收消息   foreach在Java中有没有比For循环更好的方法可以灵活地遍历集合?   java如何在安卓上移动球   在OSGi下的Log4j中使所有记录器异步时,java ClassNotFoundException   java未知输入字节长度转换为int   java测试工厂在使用前缀命名时抛出NPE   对象的副本(JAVA)   java SP20310:无法打开文件。sql   java Spring安全性仅为一条路径添加安全性   java在idea中获取菱形运算符的编译错误