4 NLP语料库

文本语料库是一个大型结构化文本的集合

 NLTK包含了许多语料库:

(1)古滕堡语料库

(2)网络和聊天文本

(3)布朗语料库
(4)路透社语料库
(5)就职演讲语料库
(6)标注文本语料库 

词汇列表语料库

 (1)词汇列表:nltk.corpus.words.words()
词汇语料库是Unix 中的/usr/dict/words 文件,被一些拼写检查程序使用。下面这段代码的功能是:过滤文本,留下罕见或拼写错误的词汇,删除在词汇列表中出现过的词汇。
#coding:utf-8
import nltk
def unusual_words(text):
    text_vocab=set(w.lower() for w in text if w.isalpha())
    english_vocab=set(w.lower() for w in nltk.corpus.words.words())
    unusual=text_vocab.difference(english_vocab)    #求差集
    return sorted(unusual)
print(unusual_words(nltk.corpus.gutenberg.words('austen-sense.txt')))
print(unusual_words(nltk.corpus.nps_chat.words()))

(2)停用词语料库:nltk.corpus.stopwords.words()
停用词语料库包含一些高频词,在处理时可以从文档中过滤掉,以便区分文本。下面这段代码实现了计算文本中不包含在停用词语料库中的词所占的比例。
import nltk
def content_fraction(text):
    stopwords=nltk.corpus.stopwords.words('english')
    content=[w for w in text if w.lower() not in stopwords]
    return len(content)*1.0/len(text)
print(content_fraction(nltk.corpus.reuters.words()))

原文地址:https://www.cnblogs.com/nxf-rabbit75/p/9487059.html