自然语言处理爬过的坑:使用python结巴对中文分词并且进行过滤,建立停用词。常见的中文停用词表大全

本文介绍了在自然语言处理中如何使用Python的结巴分词进行中文分词,并探讨了两种去除停用词的方法。通过建立停用词表,可以有效过滤掉常见标点符号和助词等,提高处理效率。同时,文章提供了中文分词过滤常用的停用词列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原代码:

 def natural_language_processing(self,response):
        #对所抓取的预料进行自然语言处理
        title = response.meta['title']
        #print title
        content = response.meta['content']
        #print content
        raw_documents = []
        raw_documents.append(title)
        raw_documents.append(content)
        #print raw_documents
        print raw_documents[0]
        print raw_documents[1]
        corpora_documents = []
        # 分词处理
        for item_text in raw_documents:
            item_seg = list(jieba.cut(item_text))
            #print item_seg

            '''建立停用词'''
            #stopwords = {}.fromkeys(['。', ':', ',',' ','《','》','、',' ','(',')','“','”',';','\n'])
            buff = []
            with codecs.open('stop.txt') as fp:
                for ln in fp:
                    el = ln[:-2]
                    buff.append(el)
            stopwords = buff
            for word in item_seg:
                if word not in stopwords and len(word)>1:
                    print word
                    corpora_documents.append(word)
            print corpora_documents

去除停用词的常见的两种方法:

一是简单的去除一些不要的标点符号。

优点:简单快捷,代码少

缺点:时间成本高,如果遇到太多不想要的特殊符号就很难受

二是建立停用词表

优点:海纳百川,将所有的特殊字符和一些助词以及其他乱七八糟的词语都过滤了

缺点:代码多,需要注意编码问题。


接下来是中文分词常见的过滤词,可以粘贴保存成文件,要使用时打开文件,将所有的引入就好


!  
"  
#  
$  
%  
&  
'  
(  
)  
*  
+  
,  
-  
--  
.  
..  
...  
......  
...................  
./  
.一  
.数  
.日  
/  
//  
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
:  
://  
::  
;  
<  
=  
>  
>>  
?  
@  
A  
Lex  
[  
\  
]  
^  
_  
`  
exp  
sub  
sup  
|  
}  
~  
~~~~  
·  
×  
×××  
Δ  
Ψ  
γ  
μ  
φ  
φ.  
В  
—  
——  
———  
‘  
’  
’‘  
“  
”  
”,  
…  
……  
…………………………………………………③  
′∈  
′|  
℃  
Ⅲ  
↑  
→  
∈[  
∪φ∈  
≈  
①  
②  
②c  
③  
③]  
④  
⑤  
⑥  
⑦  
⑧  
⑨  
⑩  
──  
■  
▲  
   
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值