我在一个列表中有一堆句子,我想使用 nltk 库来阻止它。我能够一次阻止一个句子,但是我遇到了从列表中提取句子并将它们重新组合在一起的问题。我缺少一个步骤吗?nltk 库很新。谢谢!
import nltk
from nltk.stem import PorterStemmer
ps = PorterStemmer()
# Success: one sentences at a time
data = 'the gamers playing games'
words = word_tokenize(data)
for w in words:
print(ps.stem(w))
# Fails:
data_list = ['the gamers playing games',
'higher scores',
'sports']
words = word_tokenize(data_list)
for w in words:
print(ps.stem(w))
# Error: TypeError: expected string or bytes-like object
# result should be:
['the gamer play game',
'higher score',
'sport']