Python英文文本分词(无空格)模块wordninja的使用实例

yipeiwu_com6年前Python基础

在NLP中,数据清洗与分词往往是很多工作开始的第一步,大多数工作中只有中文语料数据需要进行分词,现有的分词工具也已经有了很多了,这里就不再多介绍了。英文语料由于其本身存在空格符所以无需跟中文语料同样处理,如果英文数据中没有了空格,那么应该怎么处理呢?

今天介绍一个工具就是专门针对上述这种情况进行处理的,这个工具叫做:wordninja,地址在这里

下面简单以实例看一下它的功能:

def wordinjaFunc():
  '''
  https://github.com/yishuihanhan/wordninja
  '''
  import wordninja
  print wordninja.split('derekanderson')
  print wordninja.split('imateapot')
  print wordninja.split('wethepeopleoftheunitedstatesinordertoformamoreperfectunionestablishjusticeinsuredomestictranquilityprovideforthecommondefencepromotethegeneralwelfareandsecuretheblessingsoflibertytoourselvesandourposteritydoordainandestablishthisconstitutionfortheunitedstatesofamerica')
  print wordninja.split('littlelittlestar')

结果如下:

['derek', 'anderson']
['im', 'a', 'teapot']
['we', 'the', 'people', 'of', 'the', 'united', 'states', 'in', 'order', 'to', 'form', 'a', 'more', 'perfect', 'union', 'establish', 'justice', 'in', 'sure', 'domestic', 'tranquility', 'provide', 'for', 'the', 'common', 'defence', 'promote', 'the', 'general', 'welfare', 'and', 'secure', 'the', 'blessings', 'of', 'liberty', 'to', 'ourselves', 'and', 'our', 'posterity', 'do', 'ordain', 'and', 'establish', 'this', 'constitution', 'for', 'the', 'united', 'states', 'of', 'america']
['little', 'little', 'star']

从简单的结果上来看,效果还是不错的,之后在实际的使用中会继续评估。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对【听图阁-专注于Python设计】的支持。如果你想了解更多相关内容请查看下面相关链接

相关文章

Python遍历文件夹 处理json文件的方法

有两种做法:os.walk()、pathlib库,个人感觉pathlib库的path.glob用来匹配文件比较简单。 下面是第二种做法的实例(第一种做法百度有很多文章): from...

python 开发的三种运行模式详细介绍

python 开发的三种运行模式详细介绍

Python 三种运行模式   Python作为一门脚本语言,使用的范围很广。有的同学用来算法开发,有的用来验证逻辑,还有的作为胶水语言,用它来粘合整个系统的流程。不管怎么说,...

安装python时MySQLdb报错的问题描述及解决方法

问题描述: windows安装python mysqldb时报错python version 2.7 required,which was not found in the regist...

Python3指定路径寻找符合匹配模式文件

本文实例讲述了Python3指定路径寻找符合匹配模式文件。分享给大家供大家参考。具体实现方法如下: 这里给定一个搜索路径,需要在此目录中找出所有符合匹配模式的文件 import g...

对Python 两大环境管理神器 pyenv 和 virtualenv详解

简介 pyenv 是一个开源的 Python 版本管理工具,可以轻松地给系统安装任意 Python 版本,想玩哪个版本,瞬间就可以切换。有了 pyenv,我们不需要再为系统多版本 Pyt...