In the previous article we have built the MONGODB environment, this is a simple example.
Not much nonsense to say the first code and then start to explain;
!!! Don't forget to open your mongdb service!!!, if there is no MongoDB please look at the article how to install MongoDB;
#-*-coding:utf-8-*- fromChatterbot Import Chatbot fromchatterbot.trainers Import Listtrainer fromchatterbot.trainers Import Chatterbotcorpustrainerimport logging# Uncomment the following line to enable verbose Logg Ing#logging.basicconfig ( level=logging.info) # Create aNewchatbot Instancechatbot=Chatbot ('Norman', Storage_adapter='Chatterbot.storage.MongoDatabaseAdapter', Logic_adapters=[ 'Chatterbot.logic.BestMatch', 'chatterbot.logic.MathematicalEvaluation', 'Chatterbot.logic.TimeLogicAdapter'], Filters=[ 'Chatterbot.filters.RepetitiveResponseFilter'], Input_adapter="Chatterbot.input.TerminalAdapter", Output_adapter="Chatterbot.output.TerminalAdapter", trainer='Chatterbot.trainers.ListTrainer', Database="chatterbot-1w", Database_uri="mongodb://192.168.2.128:27017/", Read_Only=True) Print ('Type something to begin ...') whileTrue:Try: Bot_input=Chatbot.get_response (None) # Press CTRL-C or Ctrl-D on the keyboard to exit except (Keyboardinterrupt, Eoferror, systemexit): Break;
1.Filters Conditions Repetitiveresponsefilter, This is a filter, its role is to filter out the repeated answers;
2.database="chatterbot-1w", then your database name, if not, for the first time he will automatically create;
3.database_uri="mongodb://192.168.2.128:27017/", which is the address port number where you set your database ;
4.read_only=True
Chatterbot is the one that learns each input statement. If you want to make the bot you have already trained no longer continue to learn the input statements, you can set the READ_ONLY to true at initialization time by using the following method.
As for how to train, please listen to tell;
Use of Chatterbot MongoDB 03