NLTK學習筆記

2021-08-01 04:54:32 字數 1114 閱讀 5416

學習參考書:

nltk.set_proxy("**.com:80")

nltk.download()

2. 使用sents(fileid)函式時候出現:resource 'tokenizers/punkt/english.pickle' not found.  please use the nltk ********** to obtain the resource:

import nltk

nltk.download()

3. 語料corpus元素獲取函式

from nltk.corpus import webtext

webtext.fileids()      #得到語料中所有檔案的id集合

webtext.raw(fileid)  #給定檔案的所有字元集合

webtext.words(fileid) #所有單詞集合

webtext.sents(fileid)  #所有句子集合

4. 文字處理的一些常用函式

假若text是單詞集合的列表

len(text)  #單詞個數

set(text)  #去重

sorted(text) #排序

text.count('a') #數給定的單詞的個數

text.index('a') #給定單詞首次出現的位置

freqdist(text) #單詞及頻率,keys()為單詞,*[key]得到值

freqdist(text).plot(50,cumulative=true) #畫累積圖

bigrams(text) #所有的相鄰二元組

text.collocations() #找文字中頻繁相鄰二元組

text.concordance("word") #找給定單詞出現的位置及上下文

text.similar("word") #找和給定單詞語境相似的所有單詞

text.common_context("a「,"b") #找兩個單詞相似的上下文語境

text.dispersion_plot(['a','b','c',...]) #單詞在文字中的位置分布比較圖

text.generate() #隨機產生一段文字

to be c on tinued

NLTK學習筆記

學習參考書 nltk.set proxy com 80 nltk.download 2.使用sents fileid 函式時候出現 resource tokenizers punkt english.pickle not found.please use the nltk to obtain the...

NLTK學習筆記

學習參考書 nltk.set proxy com 80 nltk.download 2.使用sents fileid 函式時候出現 resource tokenizers punkt english.pickle not found.please use the nltk to obtain the...

NLTK 學習筆記(2)

pos速查表 標記含義 例子adj 形容詞new,good,high,special,big,local adv副詞 really,already,still,early,now cnj連詞 and,or,but,if,while,although det限定詞 the,a,some,most,ev...