日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NLTK自带的词干提取器

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NLTK自带的词干提取器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼來自《Python自然語言處理》P116

(python2.7) appleyuchi@ubuntu:~/.virtualenvs/python2.7/bin$ python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> raw="""DENNIS:Listen,strange women lying in ponds distributing swords is... is no basis for a system of goverment. Supreme executive power derives from... a mandate from the masses, not from some farcical aquatic ceremony.""" >>> import nltk >>> tokens=nltk.word_tokenize(raw) >>> porter = nltk.PorterStemmer() >>> lancaster=nltk.LancasterStemmer() >>> [porter.stem(t) for t in tokens] [u'denni', ':', 'listen', ',', u'strang', 'women', u'lie', 'in', u'pond', u'distribut', u'sword', 'is', '...', 'is', 'no', u'basi', 'for', 'a', 'system', 'of', u'gover', '.', u'suprem', u'execut', 'power', u'deriv', 'from', '...', 'a', u'mandat', 'from', 'the', u'mass', ',', 'not', 'from', 'some', u'farcic', u'aquat', u'ceremoni', '.'] >>> [lancaster.stem(t) for t in tokens] ['den', ':', 'list', ',', 'strange', 'wom', 'lying', 'in', 'pond', 'distribut', 'sword', 'is', '...', 'is', 'no', 'bas', 'for', 'a', 'system', 'of', 'gov', '.', 'suprem', 'execut', 'pow', 'der', 'from', '...', 'a', 'mand', 'from', 'the', 'mass', ',', 'not', 'from', 'som', 'farc', 'aqu', 'ceremony', '.']
上述代碼中,raw是原始余料,最后幾行是詞干提取結果。

以上代碼總共使用了兩種詞干提取器,分別是Porter和Lancaster

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的NLTK自带的词干提取器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。