python去停用词用nltk_如何从NLTK扩展停用词列表并使用扩展列表删除停用词?

我尝试了两种删除停用词的方法,但都遇到了问题:

方法1:

cachedStopWords = stopwords.words("english")

words_to_remove = """with some your just have from it's /via & that they your there this into providing would can't"""

remove = tu.removal_set(words_to_remove, query)

remove2 = tu.removal_set(cachedStopWords, query)

在这种情况下,只有第一个删除功能起作用. remove2不起作用.

方法2:

lines = tu.lines_cleanup([sentence for sentence in sentence_list], remove=remove)

words = '\n'.join(lines).split()

print words # list of words

输出看起来像这样[“ Hello”,“ Good”,“ day”]

我尝试从单词中删除停用词.这是我的代码:

for word in words:

if word in cachedStopwords:

continue

else:

new_words='\n'.join(word)

print new_words

输出看起来像这样:

H

e

l

l

o

不能弄清楚以上两种方法有什么问题.请指教.

解决方法:

使用它来增加停用词列表:

from nltk.corpus import stopwords

stop_words = stopwords.words('english')

print(len(stop_words))

stop_words.extend(['from', 'subject', 're', 'edu', 'use'])

print(len(stop_words))

输出:

179

184

标签:nlp,nltk,stop-words,python

来源: https://codeday.me/bug/20191120/2044905.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值