Python自然語言處理 Chapter 1

來源:互聯網
上載者:User

標籤:common   future   similar   python   標示符   div   詞彙   otl   上下   

from __future__ import divisionimport nltknltk.download()from nltk.book import *#搜尋文本text1.concordance("monstrous")#出現在相似上下文中德詞彙text1.similar("monstrous")#兩個或兩個以上的詞共同的上下文text2.common_contexts(["monstrous","very"])import matplotlib#離散圖判斷詞彙在文本中的位置,從文本開頭算起在它前面有多少詞text4.dispersion_plot(["citizens","democracy","freedom","duties","American"])#產生和該文本風格相近的段落text3.generate()#返回所有標識符的個數len(text3)#為每個標示符計數,set表示集合,集合中元素只出現一次sorted(set(text3))len(set(text3))len(text3)/len(set(text3))#計算一個詞在文本中出現次數,佔據的百分比text3.count("smote")100*text4.count("a")/len(text4)

 

fdist1=FreqDist(text1)#計算text1中的詞頻vocabulary=fdist1.keys()#關鍵字資訊fdist1[‘whale‘]#‘whale’詞出現的頻率fdist1.plot(50,cumulative=True)#詞頻前50的詞彙進行繪圖V = set(text1)#text1 輸出詞彙集合中詞長超過15的詞彙long_words=[w for w in V if len(w) > 15]text4.collocations()#搭配頻繁出現的雙連詞[len(w) for w in text1]#text1中每個詞的詞長fdist=FreqDist([len(w) for w in text1])#每個詞長對應出現的頻率fdist#詞長只有20種fdist.max()#出現頻率最高的詞長fdist.freq(3)#給定樣本的頻率,佔全部詞彙的百分比

 

Python自然語言處理 Chapter 1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.