首页 > 编程知识 正文

python如何引入停用词文件,python分词中的停用词是指什么

时间:2023-05-05 21:19:11 阅读:254390 作者:1305

文章目录 文章简介与更新记录停用词python合并中文停用词词表的代码下载所有文件

文章简介与更新记录

如果你只想获取中文停用词此表,请直接到文章结尾下载项目文件,其中包括三个中文停用词词表,一个英文停用词词表和一个合并词表的.py文件

2017/07/04 创建文章,上传文件2017/07/04 更新了合并代码,添加了新的中文停用词表(哈工大扩展版本)和一个新的停用词表,现在最全的中文停用词表为1927,添加了英文和中英文停用词表英文停用词词表为1199 停用词

在进行汉语自然语言处理时候,分词是必不可少的环节,但是在实际的自然语言中,有很多的非实意词语或者其他并没有实际作用的词语,这些词语我们必须在分词环节后进行过滤—这个环节也就是过滤停用词.不过想要获得好的分词效果,必须首先进行比较好的分词处理.这一点也是十分重要的.

python合并中文停用词词表的代码 # - * - coding: utf - 8 -*-## 作者:wxdqb(FontTian)# 创建时间:'2017/7/4'# 邮箱:fonttian@Gmaill.com# CSDN:http://blog.csdn.net/fontthroneimport sysreload(sys)sys.setdefaultencoding('utf-8')# 获取停用词的Listdef GetListOfStopWords(filepath): f_stop = open(filepath) try: f_stop_text = f_stop.read() f_stop_text = unicode(f_stop_text, 'utf-8') finally: f_stop.close() f_stop_seg_list = f_stop_text.split('n') return f_stop_seg_list# 保存Listdef SaveFile(list, filename): f_stop = open(filename, 'w') for item in range(len(list)): if item != len(list): f_stop.writelines((list[item].encode('utf-8')) + 'n') else: f_stop.writelines(list[item].encode('utf-8')) f_stop.close()# 求List并集def GetListUnion(listName): ListUnion = ['!'] for item in listName: # print item ListUnion.extend(GetListOfStopWords(item)) return list(set(ListUnion))def GetStopWords(listOfFileName, FileName='CNstopwords.txt', keynumber=1): stopwords_pathCN = 'CNstopwords.txt' # 默认中文总表 1 stopwords_pathEN = 'ENstopwords.txt' # 默认英文总表 2 stopwords_pathCNEN = 'CNENstopwords.txt' # 默认中英文混合总表 4 if keynumber == 1: listOfFileName.append(stopwords_pathCN) elif keynumber == 2: listOfFileName.append(stopwords_pathEN) elif keynumber == 3: listOfFileName.append(stopwords_pathCN) listOfFileName.append(stopwords_pathEN) elif keynumber == 5: listOfFileName.append(stopwords_pathCN) listOfFileName.append(stopwords_pathCNEN) elif keynumber == 6: listOfFileName.append(stopwords_pathEN) listOfFileName.append(stopwords_pathCNEN) elif keynumber == 7: listOfFileName.append(stopwords_pathCN) listOfFileName.append(stopwords_pathEN) listOfFileName.append(stopwords_pathCNEN) else: listOfFileName.append(stopwords_pathCN) print 'The keynumber is wrong,chage keynumber to 1 ' listOfFileName.append(stopwords_pathCNEN) ListUnion = GetListUnion(listOfFileName) SaveFile(ListUnion, FileName)'''stopwords_pathCN = 'CNstopwords.txt' # 默认中文总表 1stopwords_pathEN = 'CNstopwords.txt' # 默认英文总表 2stopwords_pathCNEN = 'CNstopwords.txt' # 默认中英文混合总表 4'''listOfFileName = []# 需要添加的 中文 停用词词表stopwords_path1 = 'stopwords1893.txt'stopwords_path2 = 'stopwords1229.txt'stopwords_path3 = 'stopwordshagongdakuozhan.txt'stopwords_path4 = 'stop_words_zh.txt'# 需要添加的 英文 停用词词表stopwords_path5 = 'stop_words_eng.txt'stopwords_path6 = 'ENstopwords891.txt'# 需要添加的 中文 停用词词表路径# listOfFileName.append(stopwords_path1)# listOfFileName.append(stopwords_path2)# listOfFileName.append(stopwords_path3)# listOfFileName.append(stopwords_path4)# 需要添加的 英文 停用词词表路径listOfFileName.append(stopwords_path5)listOfFileName.append(stopwords_path6)GetStopWords(listOfFileName, FileName='ENstopwords.txt', keynumber=2) 下载所有文件

百度云:链接:https://pan.baidu.com/s/1s0lVoYQz38Tg2m3CdLflbg
提取码:cps1
复制这段内容后打开百度网盘手机App,操作更方便哦

github:https://github.com/FontTian/NLP_tools/tree/master/%E6%B1%89%E8%AF%AD%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%A4%84%E7%90%86%E5%9F%BA%E6%9C%AC%E7%BB%84%E4%BB%B6

cdhmanager-cdhmanager是什么

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。