查阅了github的一些回答。。
Owner
gunthercox commented on 21 Sep 2018
Hi @ithjz, the JsonFileStorageAdapter class was removed from ChatterBot several versions ago.
I would suggest using the SQLStorageAdapter instead.
回答说已经JsonFileStorageAdapter被移除,我按照回答尝试替换SQLStorageAdapter
但又出现AttributeError: module 'chatterbot.logic' has no attribute 'LowConfidenceAdapter'的问题
根据github的回答
在LowConfidenceAdapter从聊天机器人移除。看一下在示例中如何使用default_response和maximum_similarity_threshold来作为替代:
https://github.com/gunthercox/ChatterBot/blob/master/examples/default_response_example.py
根据网址提供的实例我对代码进行了更改
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
#构建chatbot 指定一个adapter
bot=ChatBot(
'Default Response Example Bot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
{
'import_path':'chatterbot.logic.BestMatch',
'thresold':0.65,
'default_response':'I am sorry but i do not understand'
}
],
)
trainer=ListTrainer(bot)
#手动给定一点语料用于训练
trainer.train([
'How can i help u?',
'I want to create a chat bot',
'Have you read the documentation?',
'No i have not',
'This should help get you started:http://chatterbot.rtfd.org'
])
#给定问题并取回结果
question="How do i make an omelette?"
print(question)
response=bot.get_response(question)
print(response)
print("\n")
question="How to make a chat bot?"
print(question)
response=bot.get_response(question)
print(response)
print("\n")
以下是我的代码结果
List Trainer: [#### ] 20%
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\无色彩虹\AppData\Roaming\nltk_data...
[nltk_data] Package stopwords is already up-to-date!
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] C:\Users\无色彩虹\AppData\Roaming\nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
List Trainer: [####################] 100%
How do i make an omelette?
I am sorry but i do not understand
How to make a chat bot?
Have you read the documentation?
附上我安装时出现的问题解决链接,希望有所帮助
https://blog.csdn.net/zxy13826134783/article/details/103615399
确实有版本的问题,版本不同好像移除了一些东西,但我的库版本为
ChatterBot 1.0.5
chatterbot-corpus 1.2.0
和老师视频中的一样,具体在版本有什么更改我就还需查阅资料。谢谢大家