# coding=utf-8
import os
import jieba
import sys
import re
import time
import jieba.posseg as pseg
sys.path.append("../")
jieba.load_userdict("../Python27/fenci/dict.txt") # 加载自定义分词词典
'''
title:利用结巴分词进行文本语料处理:单文本处理器、批量文件处理器
1 首先对文本进行遍历查找
2 创建原始文本的保存结构
3 对原文本进行结巴分词和停用词处理
4 对预处理结果进行标准化格式,并保存原文件结构路径
author:白宁超
myblog:http://www.cnblogs.com/baiboy/
time:2017年4月28日10:03:09
'''
'''
分词.词性标注以及去停用词
stopwordspath: 停用词路径
dealpath:中文数据预处理文件的路径
savepath:中文数据预处理结果的保存路径
'''
"""
def cutTxtWord(dealpath, savepath, stopwordspath):
stopwords = {}.fromkeys([line.rstrip() for line in open(stopwordspath, "r", encoding='utf-8')]) # 停用词表
with open(dealpath, "r", encoding='utf-8') as f:
txtlist = f.read() # 读取待处理的文本
words = pseg.cut(txtlist) # 带词性标注的分词结果
cutresult = "" # 获取去除停用词后的分词结果
for word, flag in words:
if word not in stopwords:
cutresult += word + "/" + flag + " " # 去停用词
getFlag(cutre
win10上用Python2.7处理文本,出错IOError: [Errno 2] No such file or directory:如何解决???
最新推荐文章于 2025-06-20 14:05:13 发布