布朗語料庫中使用條件機率分佈函數ConditionalFreqDist,能夠查看每一個單詞在各新聞語料中出現的次數。這在微博情感分析中很是有用,好比判斷feature vector中表明positive or negative or neutral的各feature在每條tweet中出現的次數高低來判斷該tweet的情感極性。函數
from nltk.corpus import brownspa
cfd=nltk.ConditionalFreqDist(
(genre,word)
for genre in brown.categories()
for word in brown.words(categories=genre)
)
genres=['news','religion','hobbies','science_fiction','romance','humor']
modals=['can','could','may','might','must','will']
print cfd.tabulate(conditions=genres,samples=modals)ci
輸出結果:it
can could may might must will
news 93 86 66 38 50 389
religion 82 59 78 12 54 71
hobbies 268 58 131 22 83 264
science_fiction 16 49 4 12 8 16
romance 74 193 11 51 45 43
humor 16 30 8 8 9 13
能夠看出news分類中will一詞出現最多,humor分類中could出現次數最多。io