[英]error about 'list' object has no attribute 'split'
The code below does not run.下面的代码不运行。 The parameter passed to the function is a list of strings.
传递给 function 的参数是一个字符串列表。 AttributeError: 'list' object has no attribute 'split'
AttributeError: 'list' object 没有属性 '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.该错误告诉您迭代中的
words
是列表,因此您不能对它们使用str.split()
方法。 Try:尝试:
for (words, sentiment) in text:
com_Stemming = [str(stemmer.stem(p)) for p in words]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.