丰富停用词表的代码--jimmy

停用词表的代码

def add_stopwords_dict(stopwords_path,target_file_path,startwith_match_list):
“”"
填充丰富停用词表
:param stopwords_path: 需要添加的停用词文档路经文档
:param target_file_path: 已经分好词的目标文件
:param startwith_front: 需要匹配的词的第一个字
:return: 无返回,直接添加到停用词表里面
“”"
raw_into_stopwords = []
with open(target_file_path, ‘r’, encoding=‘utf-8’) as file:
words = [line.strip() for line in file]
for match_word in startwith_match_list:
for word in words:
if word.startswith(str(match_word)):
raw_into_stopwords.append(word)
with open(stopwords_path,‘a’,encoding=‘UTF-8’) as f:
for i in raw_into_stopwords:
f.write(i+’\n’)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值