'Chatbot' is not defined in Chatterbot and few more questions
See original GitHub issueI am making a chatbot through Chatterbot. I am facing the problems as follow:
- when I run the code, it shows error, but the ChatBot is imported from chatterbot at the beginning?
File “…/SquirralBot.py”, line 5, in class SquirralBot: File “…SquirralBot.py”, line 6, in SquirralBot bot = Chatbot(“SquirralBot”, NameError: name ‘Chatbot’ is not defined
-
I want to make the chatbot to distinguish specific texts then to trigger specific corpus, how can I make it? Is the “chatterbot.conversation.Response(text, **kwargs)” class for this purpose? e.g. when the user types “I am leaving”, then it will trigger to call the training set “chatterbot.corpus.chinese.squirral_bye_conversation”?
-
Is it possible if I can store the reply specifically to the database e.g. MongoDB for different users? e.g. when user A replies “I am sick. I got fever and running nose”, then the system store “sick” into “status” and “fever” and “running nose” into “symptoms” in the user A’s data so that inside the database it would be like JSON:
{
"user A",
"gender": "male",
"record":
[
{
"date": "25-12-2018",
"status": "fine",
"symptoms": "",
},
{
"date": "26-12-2018",
"status": "sick",
"symptoms": "fever", "running nose"
}
}
- Is it possible to make the chatbot can text the user in specific time range?
The code for the above mentioned is as following. I am very new in programming so the code may be a bit messy. Please feel free to correct. Many thanks.
import sys
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
class SquirralBot:
chatbot = Chatbot("SquirralBot",
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
],storage_adapter = "chatterbot.storage.JsonFileStorageAdapter",database = "./SquirralBot_DB.json")
def __init__(self):
self.chatbot.set_trainer(ChatterBotCorpusTrainer)
self.chatbot.train("chatterbot.corpus.chinese.squirral_greeting", "chatterbot.corpus.chinese.squirral_bye_conversation", "chatterbot.corpus.chinese.squirral_normal_conversation", "chatterbot.corpus.chinese.squirral_rabbit_bye_conversation", "chatterbot.corpus.chinese.squirral_rabbit_conversation")
def getResponse(self, message=""):
return self.chatbot.get_response(message)
if __name__ == "__main__":
bot = SquirralBot()
print(bot.getResponse(sys.argv[1]))
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@vkosuri I suppose that could possibly prevent confusion to an extent, but I’d prefer to follow the recommended naming conventions for classes in Python.
https://www.python.org/dev/peps/pep-0008/#class-names
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.