这是我的代码:
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
example_sent = "This is a sample sentence, showing off the stop words filtration."
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
if w not in stop_words:
filtered_sentence.append(w)
print(word_tokens)
print(filtered_sentence)
Run Code Online (Sandbox Code Playgroud)
但是在运行代码时,我收到此错误:
Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource
Run Code Online (Sandbox Code Playgroud)
如果我下载NLTK Downloader,我会收到以下错误:
[nltk_data] Error loading popular: <urlopen error [WinError …Run Code Online (Sandbox Code Playgroud) python-3.x ×1