【问题标题】:error about 'list' object has no attribute 'split'关于“列表”对象的错误没有属性“拆分”
【发布时间】:2020-11-14 21:49:14
【问题描述】:

下面的代码没有运行。传递给函数的参数是一个字符串列表。 AttributeError: 'list' 对象没有属性 '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)

【问题讨论】:

  • 我在这里没有看到问题。请确保您在此处执行和粘贴的代码相同。

标签: python list split nltk stemming


【解决方案1】:

你有:

for (words, sentiment) in text:
    com_Stemming = [str(stemmer.stem(p)) for p in words.split()]

错误告诉你迭代中的words 是列表,所以你不能 对它们使用str.split() 方法。试试:

for (words, sentiment) in text:
    com_Stemming = [str(stemmer.stem(p)) for p in words]

【讨论】:

    猜你喜欢
    • 2015-07-14
    • 2015-01-12
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 2022-01-20
    相关资源
    最近更新 更多