在NLP中,數(shù)據(jù)清洗與分詞往往是很多工作開始的第一步,大多數(shù)工作中只有中文語料數(shù)據(jù)需要進(jìn)行分詞,現(xiàn)有的分詞工具也已經(jīng)有了很多了,這里就不再多介紹了。英文語料由于其本身存在空格符所以無需跟中文語料同樣處理,如果英文數(shù)據(jù)中沒有了空格,那么應(yīng)該怎么處理呢?
今天介紹一個(gè)工具就是專門針對(duì)上述這種情況進(jìn)行處理的,這個(gè)工具叫做:wordninja,地址在這里。
下面簡單以實(shí)例看一下它的功能:
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é)果上來看,效果還是不錯(cuò)的,之后在實(shí)際的使用中會(huì)繼續(xù)評(píng)估。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)武林站長站的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
新聞熱點(diǎn)
疑難解答
圖片精選