zoukankan      html  css  js  c++  java
  • 多版本中文停用词词表 + 多版本英文停用词词表 + 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('
    ')
    
        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')) + '
    ')
            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)
    

    百度云下载所有文件

    下载地址:http://pan.baidu.com/s/1dFjDj3r

  • 相关阅读:
    Easy UI form表单提交 IE浏览器不执行success ,以及 datagrid 展示过慢
    JS批量获取参数构建JSON参数对象
    Easy UI datebox控件无法正常赋值
    EasyUI控件combobox重复请求后台,dialog窗口数据异常
    后台Post/Get 请求接口 方式
    WebForm 页面ajax 请求后台页面 方法
    实现输入框小数多 自动进位展示,编辑时实际值不变
    页面获取Web控件ID不能正常获取,它惹得祸
    线性表的链式存储——单链表
    线性表
  • 原文地址:https://www.cnblogs.com/fonttian/p/9162818.html
Copyright © 2011-2022 走看看