停用词表的代码
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’)