我们首先来加载我们自己的文本文件,并统计出排名前20的字符频率 if __name__=="__main__": corpus_root='/home/zhf/word' wordlists=PlaintextCorpusReader(corpus_root,'.*') for w in wordlists.words(): print(w) fdist=FreqDist(wordlists.words()) fdist.plot(20,cumulative=True) 文本内容如下:…
NLTK 这是一个处理文本的python库,我们知道文字性的知识可是拥有非常庞大的数据量,故而这属于大数据系列. 本文只是浅尝辄止,目前本人并未涉及这块知识,只是偶尔好奇,才写本文. 从NLTK中的book模块中,载入所有条目 book 模块包含所有数据 from nltk.book import * *** Introductory Examples for the NLTK Book *** Loading text1, ..., text9 and sent1, ..., sent9 Ty…
在一段句子中是由各种词汇组成的.有名词,动词,形容词和副词.要理解这些句子,首先就需要将这些词类识别出来.将词汇按它们的词性(parts-of-speech,POS)分类并相应地对它们进行标注.这个过程叫做词性标注. 要进行词性标注,就需要用到词性标注器(part-of-speech tagger).代码如下 text=nltk.word_tokenize("customer found there are abnormal issue") print(nltk.pos_tag(tex…
前面介绍了很多NLTK中携带的词典资源,这些词典资源对于我们处理文本是有大的作用的,比如实现这样一个功能,寻找由egivronl几个字母组成的单词.且组成的单词每个字母的次数不得超过egivronl中字母出现的次数,每个单词的长度要大于6. 要实现这样的一个功能,首先我们要调用FreqDist功能.来得到样本字母中各个字母出现的次数 puzzle_letters=nltk.FreqDist('egivrvonl') for k in puzzle_letters: print(k,puzzle_…