首页 > 解决方案 > 在 Python NLTK 中从文件中定义自己的语言特定的停用词集

问题描述

有没有办法自定义这个

stopWords = set(stopwords.words('english'))

或任何其他方式,所以我可以在 Python 的 NLTK 中使用我的语言中的停用词的文本文件?

如果我的文本文件是 my_stop_words.txt,我怎么能告诉 NLTK 使用这组单词而不是设置为“英语”?

非常感谢!

标签: pythonnlpnltkstop-words

解决方案


是的,您可以阅读自己的停用词文件,但值得一提的是,NLTK 的停用词支持多种语言。

尝试类似:

with open("stopwords.txt", "r") as f:
    new_stopwords = []
    for line in f.readlines()
        new_stopwords.append(line)

new_stopwords_set = set(new_stopwords)

推荐阅读