自然语言处理python进阶(一)
生活随笔
收集整理的這篇文章主要介紹了
自然语言处理python进阶(一)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
from nltk.corpus import reuters #加載路透語料庫
files = reuters.fileids()
print(len(files)) # 10788
words16097 = reuters.words(['test/16097'])
print(words16097)
什么是語料
就是一個個txt,一個txt就是一個列表
categories種類
reutersGenres = reuters.categories() print(reutersGenres) # 90加載語料特定的種類的句子
# 加載語料特定的種類 for w in reuters.words(categories=['bop','cocoa']):print(w +' ',end='')if(w is '.'): # 一個句子就換行print()實際生活中要自己下載語料來搞
讀取下載的語料
from nltk.corpus import CategorizedPlaintextCorpusReader# 語料將分成不同的種類的txt,所以采用正則的方法來讀取txt reader = CategorizedPlaintextCorpusReader(r'/Volumes/Data/NLP-CookBook/Reviews/txt_sentoken', r'.*\.txt', cat_pattern=r'(\w+)/*') print(reader.categories())總結(jié)
以上是生活随笔為你收集整理的自然语言处理python进阶(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 西安网红珠宝店有哪些?
- 下一篇: 亚马逊美国站陶瓷加热灯UL482测试标准