Python英文文本分詞(無空格)模塊wordninja的使用實例
在NLP中,數(shù)據清洗與分詞往往是很多工作開始的第一步,大多數(shù)工作中只有中文語料數(shù)據需要進行分詞,現(xiàn)有的分詞工具也已經有了很多了,這里就不再多介紹了。英文語料由于其本身存在空格符所以無需跟中文語料同樣處理,如果英文數(shù)據中沒有了空格,那么應該怎么處理呢?
今天介紹一個工具就是專門針對上述這種情況進行處理的,這個工具叫做: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']
從簡單的結果上來看,效果還是不錯的,之后在實際的使用中會繼續(xù)評估。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
相關文章
python3+PyQt5圖形項的自定義和交互 python3實現(xiàn)page Designer應用程序
這篇文章主要為大家詳細介紹了python3+PyQt5圖形項的自定義和交互,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04python人工智能tensorflow函數(shù)np.random模塊使用
這篇文章主要為大家介紹了python人工智能tensorflow函數(shù)np.random模塊使用方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05python 虛擬環(huán)境調用allure報錯:FileNotFoundError: [WinError
python代碼調用命令行 allure命令報錯,提示找不到allure這個命令,本文就詳細的介紹了具體的解決方法,具有一定的參考價值,感興趣的可以了解一下2023-09-09使用Python中Tkinter模塊的Treeview?組件顯示ini文件操作
這篇文章主要介紹了使用Python中Tkinter模塊的Treeview組件顯示ini文件操作,Treeview組件位于ttk模塊,該模塊自Tk8.5開始引入,主題詳細介紹,需要的朋友可以參考一下2022-09-09python利用re,bs4,requests模塊獲取股票數(shù)據
這篇文章主要介紹了python利用re,bs4,requests模塊獲取股票數(shù)據,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-07-07