我正在使用python chatterbot和chatterbot_corpus开发一个聊天机器人,我正在获取语料库。当我运行代码时,我在语料库文件中得到一个错误
parts = dotted_path.split('.')
AttributeError: 'list' object has no attribute 'split'实际上,它应该只运行并访问语料库文件。任何帮助都会很感激,我会把我所有的代码放在下面。
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.trainers import ChatterBotCorpusTrainer
import chatterbot_corpus
bot = ChatBot(
'IKO',
logic_adapters=[
'chatterbot.logic.BestMatch',
'chatterbot.logic.TimeLogicAdapter',
'chatterbot.logic.MathematicalEvaluation'],
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database_uri='sqlite:///database.sqlite3'
)
trainer = ListTrainer(bot)
trainer = ChatterBotCorpusTrainer(bot)
trainer.train([
"chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.ai"
])
trainer.train([
"what is your name",
"my name is IKO",
"is your name IKO",
"yes"
])
trainer.train([
"turn on the light",
"ok turning the light on"
])
name = input("Enter Your Name: ")
print("Welcome to the Bot Service! Let me know how can I help you?")
while True:
request=input(name+':')
if request=='Bye' or request =='bye':
print('Bot: Bye')
break
elif "turn" in request and "on" in request and "light" in request:
sig = "light on"
print(sig)
else:
response=bot.get_response(request)
print('Bot:',response)整个错误是:
runfile('C:/Users/jax02/OneDrive/Desktop/IKO/IKO/AI尝试2.py',wdir='C:/Users/jax02/OneDrive/Desktop/IKO/IKO')回溯(最近一次调用):
文件"",第1行,位于runfile('C:/Users/jax02/OneDrive/Desktop/IKO/IKO/AI尝试2.py',wdir='C:/Users/jax02/OneDrive/Desktop/IKO/IKO')中
运行文件execfile(文件名,命名空间)中的文件"C:\Users\jax02\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",行827
文件名第110行,在execfile exec中( "C:\Users\jax02\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",(f.read(),filename,'exec'),命名空间)
文件"C:/Users/jax02/OneDrive/Desktop/IKO/IKO/AI尝试2.py",第21行,"chatterbot.corpus.english.ai“
文件"C:\Users\jax02\Anaconda3\lib\site-packages\chatterbot\trainers.py",第133行,在列车data_file_paths.extend(list_corpus_files(corpus_path))中
File "C:\Users\jax02\Anaconda3\lib\site-packages\chatterbot\corpus.py",第66行,in list_corpus_files corpus_path = get_file_path(dotted_path,extension=CORPUS_EXTENSION)
文件"C:\Users\jax02\Anaconda3\lib\site-packages\chatterbot\corpus.py",第30行,在get_file_path parts =dotted_path.split(‘.)中。
AttributeError:“list”对象没有属性“”split“”
发布于 2021-01-31 22:19:22
其中一个问题是,您正在覆盖已声明的变量。
❌
trainer = ListTrainer(bot)
trainer = ChatterBotCorpusTrainer(bot)✅
list_trainer = ListTrainer(bot)
corpus_trainer = ChatterBotCorpusTrainer(bot)另一个问题是,当你通过ListTrainer训练时,你必须向它传递一个列表,但当你通过ChatterBotCorpusTrainer训练时,你就不需要了。
ChatterBotCorpusTrainer example
因此,让我们进行一些更改(请记住,现在变量名称已更改)
❌
corpus_trainer.train([
"chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.ai"
])✅
corpus_trainer.train(
"chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.ai"
)如果你还不明白,下面是最终的代码:
list_trainer = ListTrainer(bot)
corpus_trainer = ChatterBotCorpusTrainer(bot)
corpus_trainer.train(
"chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.ai"
)
list_trainer.train([
"what is your name",
"my name is IKO",
"is your name IKO",
"yes"
])
list_trainer.train([
"turn on the light",
"ok turning the light on"
])https://stackoverflow.com/questions/65975426
复制相似问题