为什么即使在 english.txt 文件中添加停用词后停用词也没有更新?

Why are the stop words not updating even after adding stop words to the english.txt file?

我在 Python 中使用 stop_words 包。目录路径usr/local/lib/python2.7/dist-packages/stop_words/stop-words中的english.txt文件原来的停用词数是174,我又加了几个停用词列表变成了218.

我使用以下命令获取停用词

from stop_words import get_stop_words

en_stop = get_stop_words('en')

len(en_stop) 仍然显示 174。请告诉我如何使更改反映出来?

要包含stop_words模块中的单词,首先使用命令'python -v'找到这些模块所在的位置。 它将显示像'/usr/local/lib/python2.7/site-packages/stop_words-2015.2.23.1-py2.7.egg/stop_words/stop-words'这样的位置,在这些目录中有许多文件,包括english.txt和other.Add一些你想输入的词在english.txt然后导入模块。 get_stop_words的长度改变了。

您不应向文件中添加停用词。要添加停用词,您应该创建一个要添加的单词列表,然后使用 setunion 函数创建一个新列表。

en_stop = set(get_stop_words('en'))
new_stop = {'newstopword'}
en_stop = en_stop.union(new_stop)