python英文(无空格)文本分词模块wordninja使用 您所在的位置:网站首页 第一模块的单词怎么读 python英文(无空格)文本分词模块wordninja使用

python英文(无空格)文本分词模块wordninja使用

2024-07-05 14:18| 来源: 网络整理| 查看: 265

       在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']

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



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有