Natural Language Toolkit(粵語口語可以叫:自然語言工具箱),簡稱 NLTK,係 Python 一個專用嚟幫手做英文自然語言處理(NLP)嘅函式庫。NLTK 包含咗多種 NLP 成日要用嘅功能,例如係畀用家齋靠一句陳述式就產生到一樖分析樹,分析樹可以攞嚟分析句子嘅文法結構。
喺廿一世紀初,NLTK 廣受 NLP 相關領域嘅工作者採用:語言學、認知科學、人工智能同埋資訊科學等領域嘅工作,都成日要教電腦處理文字數據;而經驗表明 NLTK 好方便好好使,於是就成為咗 NLP 上嘅一隻標準架生,呢啲咁多唔同領域嘅工作者都會用到 NLTK 寫程式。
import nltk.corpus # 引入 NLTK 嘅語料庫 emma = nltk.corpus.gutenberg.words('austen-emma.txt') # 將 emma 設做 nltk.corpus 入面嘅... print(emma) # output 出 emma。
... moby = Text(nltk.corpus.gutenberg.words('melville-moby_dick.txt')) # 將 moby 設做一嚿 Text 物件,入面啲字嚟自 nltk.corpus 嘅 'melville-moby_dick.txt'... print(moby.concordance("monstrous")) # Output 畀出所有 "monstrous" 呢隻字出現嘅 context。 print(moby.similar("monstrous")) # Output 畀出所有 context 上同 "monstrous" 相近嘅字。
... moby.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"]) # 出幅圖顯示 "citizen", "democracy", "freedom", "duties", "America" 呢幾隻字喺 moby 唔同部份入面出現嘅頻率。
from nltk.corpus import wordnet as wn print(wn.synsets('word')) wn.synset('word.n.01').path_similarity(wn.synset('whale.n.01')) # Output 畀出 "word" 呢隻字嘅同義字。
word_tokenize(my_string)
噉。FreqDist(my_text)
同 ConditionalFreqDist(my_text_cond)
):Ch. 2。re.search('ed$', w)
(搵 w
當中 -ed 尾嘅字)、re.search(^..j..t..$', w)
(搵 w
當中 ..j..t.. 噉嘅字,當中 . 係乜字母都得)同 re.findall(r'[aeiou]', w)
(由 w
當中搵出嗮所有 aeiou
)... 呀噉。... 呀噉。
This article uses material from the Wikipedia 粵語 article 自然語言工具箱, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply (view authors). 呢度嘅所有文字係根據 CC BY-SA 4.0 牌照嘅條款發佈;可能會有附加嘅條款。 Images, videos and audio are available under their respective licenses.
®Wikipedia is a registered trademark of the Wiki Foundation, Inc. Wiki 粵語 (DUHOCTRUNGQUOC.VN) is an independent company and has no affiliation with Wiki Foundation.