分词、去停用词

分词、去停用词

#https://github.com/xgli/jieba

import os
import jieba

# 未分词语料库路径
corpus_path =r' '
# 分词后语料库路径
seg_path = r' '
# 停用词路径
stop_list_Path = r' '

def stopwordsList(stop_list_Path):
    f = open(stop_list_Path,'r',encoding='utf-8')
    stopwords = [line.strip() for line in f.readlines()]
    return stopwords

def readfile(filepath):
    f = open(filepath,'r',encoding='gb2312',errors='ignore')
    content = f.read()
    # read()返回的是字符串,读全文本的内容。readline()返回一行,是字符串类型。readlines()读取所有行,保存在列表中
    f.close()
    return content
    # 这里返回整个文本,以便后续进行分词
    
def savefile(seg_path,content):
    f = open(seg_path,'w',encoding='utf-8')
    f.write(content)
    f.close()

def tikenizer_and_removeStoplist(corpus_path,stop_list_Path):
    cate_dir = os.listdir(corpus_path) # 获取子类别目录
    for cate in cate_dir:
   
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值