The code below does not run. The parameter passed to the function is a list of strings. AttributeError: 'list' object has no attribute 'split'
base_train = [
('este trabalho e agradável','alegria'),
('gosto de ficar no seu aconchego','alegria'),
('fiz a adesão ao curso hoje porque eu gostei','alegria'),
('eu sou admirada por muitos','alegria'),
('adoro como você e','alegria'),
('adoro seu cabelo macio','alegria')
def apply_Stemmer(text):
stemmer = nltk.stem.RSLPStemmer()
sentence_no_Stemming = []
for (words, sentiment) in text:
com_Stemming = [str(stemmer.stem(p)) for p in words.split()]
sentence_no_Stemming.append((with_Stemming, sentiment))
return sentence_no_Stemming
sentence_with_Stem_train = apply_Stemmer(base_train)
You have:
for (words, sentiment) in text:
com_Stemming = [str(stemmer.stem(p)) for p in words.split()]
The error tells you that words
in the iterations is are lists, so you can't use the str.split()
method on them. Try:
for (words, sentiment) in text:
com_Stemming = [str(stemmer.stem(p)) for p in words]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.