多版本中文停用词词表 + 多版本英文停用词词表 + python词表合并程序

文章简介与更新记录

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

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

停用词

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

python合并中文停用词词表的代码

# - * - coding: utf - 8 -*-
#
# 作者:田丰(FontTian)
# 创建时间:'2017/7/4'
# 邮箱:fonttian@Gmaill.com
# CSDN:http://blog.csdn.net/fontthrone
import sys

reload(sys)
sys.setdefaultencoding('utf-8')


# 获取停用词的List
def 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


# 保存List
def 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' # 默认中文总表 1
stopwords_pathEN = 'CNstopwords.txt' # 默认英文总表 2
stopwords_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

  • 16
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Font Tian

写的很好,请给我钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值