Python实现结巴分词统计高频中文词汇
2021-11-26 15:01
281 查看
代码
# 读取文件 fn = open('youxi.txt', 'rt', encoding='utf-8') # 打开文件 string_data = fn.read() # 读出整个文件 fn.close() # 关闭文件 # 文本预处理 pattern = re.compile(u'\t|\n|\.|-|:|;|\)|\(|\?|"') # 定义正则表达式匹配模式 string_data = re.sub(pattern, '', string_data) # 将符合模式的字符去除 # 文本分词 seg_list_exact = jieba.cut(string_data, cut_all=False) # 精确模式分词 object_list = [] # 分词并去除停用词 remove_words = set() fr = open('stopword.txt', encoding = 'UTF-8') for word in fr: remove_words.add(str(word).strip()) fr.close() for word in seg_list_exact: # 循环读出每个分词 if word not in remove_words: # 如果不在去除词库中 object_list.append(word) # 分词追加到列表 # 词频统计 word_counts = collections.Counter(object_list) # 对分词做词频统计 word_counts_top10 = word_counts.most_common(100) # 获取前100最高频的词 print(word_counts_top10) # 输出检查
需要引入的库
import re # 正则表达式库 import collections # 词频统计库 import numpy as np # numpy数据处理库 import jieba # 结巴分词
文件内容示例
处理结果示例(前100)
相关文章推荐
- 利用结巴分词的Python版本实现分词并统计词频
- python3.6实现中文分词统计-自然语言处理小项目
- 对Python中文分词模块结巴分词算法过程的理解和分析
- 用条件随机场CRF进行字标注中文分词(Python实现)
- Python分词模块推荐:结巴中文分词
- Python结巴中文分词工具使用过程中遇到的问题及解决方法
- 结巴分词 0.14 版发布,Python 中文分词库
- 用最大熵模型进行字标注中文分词(Python实现)
- 对Python中文分词模块结巴分词算法过程的理解和分析
- Python下的中文分词实现
- python中文分词,使用结巴分词对python进行分词(实例讲解)
- 结巴分词 0.27 发布,Python 中文分词组件
- 中文高频词汇统计并绘制词云
- 基于python的中文分词的实现及应用
- 对Python中文分词模块结巴分词算法过程的理解和分析
- 中文分词的python实现-基于FMM算法
- 对Python中文分词模块结巴分词算法过程的理解和分析
- python中文分词工具:结巴分词jieba
- 7. Python 结巴中文分词
- 隐马尔科夫实现中文分词(Python3实现)