根据字典对文本分词
来源:互联网 发布:淘宝账号已被冻结 编辑:程序博客网 时间:2024/06/05 02:24
有一个文本文件作为字典,另有一个文件夹下的几千文件是母本(待处理)文件,需要对这些文件进行分词操作,并去除字典之外的词,然后将处理好的文本写入新文件中
#coding:utf-8from __future__ import print_function, unicode_literalsimport sysimport jiebaimport jieba.posseg as psegfrom test.test_userdict import UserDictTestfrom distutils.sysconfig import project_basefrom pip._vendor.pyparsing import linefrom jieba import del_wordfrom email import contentmanagerimport osimport os.pathfrom matplotlib.pyplot import title#sys.setdefaultencoding("utf8")sys.path.append("../")lines0 = ''jieba.load_userdict('字典路径')#载入字典lines0 = [line.strip() for line in open('字典路径',encoding='UTF-8')]for dirpath, dirnames, filenames in os.walk('母本路径'): for filename in filenames: if os.path.splitext(filename)[1] == '.txt': filepath = os.path.join(dirpath, filename) #print(str(filename)) newfile = 原文件路径'+filename with open(newfile,newline='',encoding='UTF-8') as project2: parContent = project2.read() words = jieba.cut(parContent) #print(words) content = '' for linnn in words: linnn = linnn.strip() if linnn in lines0: content += linnn content += '\n' title = filename file_name = '{}.txt'.format(title) with open(file_name, 'w', newline='', encoding='utf-8') as f: f.write(content)
阅读全文
0 0
- 根据字典对文本分词
- Java对文本进行分词
- NLPIR(ICTCLAS2016)对文本进行分词
- 使用python对中文文本进行分词
- 根据字典中值的大小,对字典的项排序
- 根据字典中值的大小对字典中的项排序
- 根据字典的值大小对字典进行排序
- 利用word分词来对文本进行词频统计
- 使用 Node.js 对文本内容分词和关键词抽取
- 利用jieba对多个中文txt文本进行分词
- 利用python对一段英文文本进行分词,分句
- 给定字典做分词
- 给定字典做分词
- 给定字典做分词
- 根据文本对输入的字符串进行加密解密操作
- 2-4根据字典中值的大小,对字典中的项排序
- python-2-3-如何根据字典中值的大小,对字典中的项排序?
- 如何根据字典中值的大小,对字典中的项排序
- Windows 1709版本中OneDrive导致绝大多数程序崩溃的解决方案
- Shiro 学习
- 蚊子 (树形期望dp)
- 优化ajax提交数据的用户体验
- 请求转发与重定向
- 根据字典对文本分词
- Apple Tree
- Codeforces 875B (Round 441 D1) Sorting the Coins
- 研究生学术论文常犯问题总结
- jq 文字上下滚动
- 一道好题:机房小测-Tarjan判断必经点
- Android 7.0中ContentProvider实现原理
- python 机器学习之有监督学习(二)
- 数据对象和JSON字符串之间的转换