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中调用Ping命令,批量IP的方法

如下所示: #!/usr/bin/env python #coding:UTF-8 ''''''' Author: jefferchen@163.com 可在命令行直接带目的IP...

python实现彩票系统

本文为大家分享了python实现彩票系统的具体代码,供大家参考,具体内容如下 功能:1、注册  2、登录  3、充钱   4、提现  5...

Django中间件实现拦截器的方法

Django中间件实现拦截器的方法

1.前言 JavaWeb Struts2的拦截器我们都能很熟悉,在请求交给Action处理之前,先在拦截器中处理,处理完之后再交给Action。 在Django中如何实现相同的效果...

PyCharm导入python项目并配置虚拟环境的教程详解

PyCharm导入python项目并配置虚拟环境的教程详解

进入PyCharm后,点击File→Open,然后在弹窗中选择需要导入项目的文件夹; 打开了python项目后,需要配置该项目对应的python才可以正常运行; 配置步骤:File→...

对python dataframe逻辑取值的方法详解

我遇到的一个小需求,就是希望通过判断pandas dataframe中一列的值在两个条件范围(比如下面代码中所描述的逻辑,取小于u-3ε和大于u+3ε的值),然后取出dataframe中...