python 英语分词_Python英文文本分词(无空格)模块wordninja的使用实例
在NLP中,數(shù)據(jù)清洗與分詞往往是很多工作開始的第一步,大多數(shù)工作中只有中文語料數(shù)據(jù)需要進行分詞,現(xiàn)有的分詞工具也已經(jīng)有了很多了,這里就不再多介紹了。英文語料由于其本身存在空格符所以無需跟中文語料同樣處理,如果英文數(shù)據(jù)中沒有了空格,那么應(yīng)該怎么處理呢?
今天介紹一個工具就是專門針對上述這種情況進行處理的,這個工具叫做: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')
結(jié)果如下:
['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']
從簡單的結(jié)果上來看,效果還是不錯的,之后在實際的使用中會繼續(xù)評估。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
總結(jié)
以上是生活随笔為你收集整理的python 英语分词_Python英文文本分词(无空格)模块wordninja的使用实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IEEE 754 浮点数的表示方法
- 下一篇: python不是内部或外部命令的解决方法