gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:09 25 4
gpt4 key购买 nike

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

方法一:

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 不起作用。

方法二:

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

关于python - 如何从 NLTK 扩展停用词列表并使用扩展列表删除停用词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29275063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com