NLP:1-使用NLTK了解语料
本章要点: 使用NLTK了解语料 导入语料 NLTK库 0,本地语料转Text类 1,搜索文本 文章搜索:concordance() 相似词搜索:similar() 上下文搜索:common_contexts() 可视化词频:dispersion_plot() 2,词汇计数 长度:len() 去重:set() 排序:sorted(set(text)) 一个词的个数:count() 3,词频分布 FreqDist() 词频分布类中定义的函数 4,词语搭配和双联词 安装nltk库及语料 1,安装nltk库 2,安装nltk语料库 使用NLTK了解语料 导入语料 with open ( "./text.txt" ) as f : text = f . read ( ) print ( type ( text ) ) print ( text [ : 200 ] ) <class 'str'> [ Moby Dick by Herman Melville 1851 ] ETYMOLOGY . ( Supplied by a Late Consumptive Usher to a Grammar School ) The pale Usher -- threadbare in coat , heart , body , and brain ; I see him now . He was