Python英文文本分詞(無空格)模塊wordninja的使用實例
在NLP中,數(shù)據(jù)清洗與分詞往往是很多工作開始的第一步,大多數(shù)工作中只有中文語料數(shù)據(jù)需要進行分詞,現(xiàn)有的分詞工具也已經(jīng)有了很多了,這里就不再多介紹了。英文語料由于其本身存在空格符所以無需跟中文語料同樣處理,如果英文數(shù)據(jù)中沒有了空格,那么應該怎么處理呢?
今天介紹一個工具就是專門針對上述這種情況進行處理的,這個工具叫做: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)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
- Python實現(xiàn)多進程的四種方式
- Python多進程fork()函數(shù)詳解
- Python爬蟲之UserAgent的使用實例
- Python快速轉(zhuǎn)換numpy數(shù)組中Nan和Inf的方法實例說明
- Python基于滑動平均思想實現(xiàn)缺失數(shù)據(jù)填充的方法
- 利用Python對文件夾下圖片數(shù)據(jù)進行批量改名的代碼實例
- Python基于opencv調(diào)用攝像頭獲取個人圖片的實現(xiàn)方法
- 啥是佩奇?使用Python自動繪畫小豬佩奇的代碼實例
- Python實戰(zhàn)購物車項目的實現(xiàn)參考
- Python3.6.x中內(nèi)置函數(shù)總結(jié)及講解
相關(guān)文章
Python實現(xiàn)爬蟲從網(wǎng)絡上下載文檔的實例代碼
小編最近在研究python,接觸到了爬蟲,本文給大家?guī)砹薖ython實現(xiàn)爬蟲從網(wǎng)絡上下載文檔的知識。下面小編把具體實例代碼分享到腳本之家平臺,感興趣的朋友參考下吧2018-06-06python3+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)境調(diào)用allure報錯:FileNotFoundError: [WinError
python代碼調(diào)用命令行 allure命令報錯,提示找不到allure這個命令,本文就詳細的介紹了具體的解決方法,具有一定的參考價值,感興趣的可以了解一下2023-09-09使用Python中Tkinter模塊的Treeview?組件顯示ini文件操作
這篇文章主要介紹了使用Python中Tkinter模塊的Treeview組件顯示ini文件操作,Treeview組件位于ttk模塊,該模塊自Tk8.5開始引入,主題詳細介紹,需要的朋友可以參考一下2022-09-09python利用re,bs4,requests模塊獲取股票數(shù)據(jù)
這篇文章主要介紹了python利用re,bs4,requests模塊獲取股票數(shù)據(jù),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-07-07