这是我的代码:
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)
但是在运行代码时,我收到此错误:
Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource
如果我下载NLTK Downloader
,则出现以下错误:
[nltk_data] Error loading popular: <urlopen error [WinError 10054] An
[nltk_data] existing connection was forcibly closed by the remote
[nltk_data] host>
谁能告诉我如何摆脱这个错误?
这行得通吗?
import nltk
nltk.download('stopwords')
请阅读以下链接,可以解决:
https://github.com/cuckoosandbox/cuckoo/issues/791 https://www.codeproject.com/Questions/1060070/ConnectionResetError-WinError-An-existing-connecti https://github.com/Esri/arcgis-python-api/issues/193