【python】NLTK-02-相似度 频率 similar common_contexts count
2017-09-28 16:56
393 查看
#!/user/bin/python # -*- coding:utf-8 -*- # 从 NLTK 的 book模块加载所有的东西 from nltk.book import * ''' Text类介绍 Text(words) 对象构造 concordance(word, width=79, lines=25) 显示word出现的上下文 common_contexts(words) 显示words出现的相同模式 similar(word) 显示word的相似词 collocations(num=20, window_size=2) 显示最常见的二词搭配 count(word) word出现的词数 dispersion_plot(words) 绘制words中文档中出现的位置图 vocab() 返回文章去重的词典 ''' # similar 用法 # text1.similar('monstrous') # 函数common_contexts允许我们研究两个或两个以上的词共同的上下文,如 monstrous 和 very 。我们必须用方括号和圆括号把这些词括起来,中间用逗号分割。 # text2.common_contexts(["monstrous", "very"]) ''' # 输出结果 a_pretty am_glad a_lucky is_pretty be_glad ''' # text1.common_contexts(["monstrous", "very"]) ''' # 输出结果 No common contexts were found ''' # 我们也可以判断词在文本中的位置:从文本开头算起在它前面有多少词。这个位置信息可以用 离散图表示 , 前提是先安装好matplotlib ,pip安装即可 # text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"]) # text3中一共有44764个词 print(len(text3)) # 44764 print(sorted(set(text3))) # ['!', "'", '(', ')', ',', ',)', '.', '.)', ':', ';', ';)', '?', '?)', 'A', 'Abel', 'Abelmizraim', ...] # text3中去掉重复后一共有2789个词 print(len(set(text3))) # 2789 # smote出现的频率 print(text3.count("smote")) # 5
参考书《python自然语言处理》
相关文章推荐
- Python+NLTK自然语言处理学习(二):常用方法(similar、common_contexts、generate)
- 黄聪:Python+NLTK自然语言处理学习(二):常用方法(similar、common_contexts、generate)
- nltk入门函数解释(concordance,similar,common_contexts)
- Finding Similar Items 文本相似度计算的算法——机器学习、词向量空间cosine、NLTK、diff、Levenshtein距离
- 我的python学习之路-02
- Python MySQLdb库的一点说明 02
- python 02
- Python进阶02 文本文件的输入输出
- python数据结构学习笔记-2016-11-12-02-递归的应用
- python核心编程学习笔记-2016-08-21-02-python网络编程TCP
- leetcode:Longest Common Prefix【Python版】
- python-Levenshtein几个计算字串相似度的函数解析
- Python文本处理nltk基础
- Python与自然语言处理_第二期_NLTK入门之NLTK的基本使用
- 比较两张图片的相似度-python
- Python 数据科学入门教程:NLTK
- Python+NLTK自然语言处理学习(一…
- Python学习_02 python安装及工具安装
- Python-02 快速介绍
- Python基础02 基本数据类型