Python英文文本分词(无空格)模块wordninja的使用实例
在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模块restful使用方法实例
- python使用marshal模块序列化实例
- python中使用smtplib和email模块发送邮件实例
- 使用Python的urllib和urllib2模块制作爬虫的实例教程
- Python语言检测模块langid和langdetect的使用实例
- python中的hashlib和base64加密模块使用实例
- Python psutil模块简单使用实例
- python csv模块使用实例
- Python-模块,以及使用文本中的数据
- python.从一个文本文件中选出使用频率最多的若干个单词实例
- Python的加密模块md5、sha、crypt使用实例
- Python CSV模块使用实例
- Python fileinput模块使用实例
- ansible作为python模块库使用的方法实例
- Python使用QRCode模块生成二维码实例详解
- 【实例】python 使用 Stanford-corenlp 分词
- Python 3.x--使用re模块,实现计算器运算实例
- Python随机生成数模块random使用实例
- python WMI模块的使用实例