(1 NLTK學習筆記

2021-10-04 18:31:56 字數 1229 閱讀 1243

nltk學習筆記

1 布朗語料庫

匯入:

import nltk

from nltk.corpus import brown

呼叫語料庫中所有的類別:

print(brown.categories())
在所有的類別中挑選出某幾種類別:

genres=[『』]

whwords=[『』]

使用for迴圈來進行迭代並優化**行數:

for i in range(0,len(genres)):genre=genre[i]

print()

print(「analysing』」+genre+」』wh words」)

genre_text = brown.words(categories=genre)

nltk庫的freqdist函式

fdist = nltk. freqdist(genre_text)    //簡短宣告

for wh in whwords: //得到每個詞的個數

print(wh+』+』,fdist[wh],end=』』)

2 網路和聊天文字

導入庫和webtext語料庫

import nltk

from nltk.corpus import webtext

print(webtext. fields())

計算檔案頻率分布

fileid = 『name.txt』

wbt_words = webtext.words(fileid)

fdist=nltk.freqdist(wbt_words)

最長出現的單詞,和其計數:

print(『max」』,fdist.max(),』」:』),

fdist[fdist.max()])

fdist.n()函式得到頻率分布包中不同單詞的計數。

fdist.most_common()找出語料庫中最常見的n個單詞

mac中多版本python處理方式

python2 -m pip install *** 或 python3 -m pip install ***

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學習筆記

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