def transform_text(text):
text = text.lower()
text = nltk.word_tokenize(text)
y = []
for i in text:
if i.isalnum():
y.append(i)
text = y[:]
y.clear()
for i in text:
if i not in stopwords.words('english') and i not in string.punctuation:
y.append(i)
text = y[:]
y.clear()
for i in text:
y.append(ps.stem(i))
return " ".join(y)
gives
<ipython-input-47-c84ab809613a> in <module>
----> 1 transform_text("I'm gonna be home soon and i don't want to talk about this stuff anymore tonight, k? I've cried enough today.")
<ipython-input-46-fed03b80da62> in transform_text(text)
12
13 for i in text:
---> 14 if i not in stopwords.words('english') and i not in string.punctuation:
15 y.append(i)
16
NameError: name 'stopwords' is not defined