我正在使用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。你能告诉我如何让这些变化反映出来吗?
发布于 2017-07-11 18:57:58
您不应该在文件中添加停用词。要添加停用词,您应该创建一个要添加的词的列表,然后使用set的union函数创建一个新列表。
en_stop = set(get_stop_words('en'))
new_stop = {'newstopword'}
en_stop = en_stop.union(new_stop)发布于 2017-07-11 17:30:37
要在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的长度已更改。
https://stackoverflow.com/questions/45029564
复制相似问题