国外旅游网站模板下载,建筑设计公司账务处理实例,基于.net平台网站内容管理系统研究与实现,在线做带字头像的网站给公众号集成一个智能聊天机器人一、前述ChatterBot是一个基于机器学习的聊天机器人引擎#xff0c;构建在python上#xff0c;主要特点是可以自可以从已有的对话中进行学(jiyi)习(pipei)。二、具体1、安装是的#xff0c;安装超级简单#xff0c;用pip就可以啦pip insta…给公众号集成一个智能聊天机器人一、前述ChatterBot是一个基于机器学习的聊天机器人引擎构建在python上主要特点是可以自可以从已有的对话中进行学(jiyi)习(pipei)。二、具体1、安装是的安装超级简单用pip就可以啦pip install chatterbot2、流程大家已经知道chatterbot的聊天逻辑和输入输出以及存储是由各种adapter来限定的我们先看看流程图一会再一起看点例子看看怎么用。image3、每个部分都设计了不同的“适配器”(Adapter)。机器人应答逻辑 Logic AdaptersClosest Match Adapter 字符串模糊匹配(编辑距离)Closest Meaning Adapter 借助nltk的WordNet近义词评估Time Logic Adapter 处理涉及时间的提问Mathematical Evaluation Adapter 涉及数学运算存储器后端 Storage AdaptersRead Only Mode 只读模式当有输入数据到chatterbot的时候数据库并不会发生改变Json Database Adapter 用以存储对话数据的接口对话数据以Json格式进行存储。Mongo Database Adapter 以MongoDB database方式来存储对话数据输入形式 Input AdaptersVariable input type adapter 允许chatter bot接收不同类型的输入的如strings,dictionaries和StatementsTerminal adapter 使得ChatterBot可以通过终端进行对话HipChat Adapter 使得ChatterBot 可以从HipChat聊天室获取输入语句通过HipChat 和 ChatterBot 进行对话Speech recognition 语音识别输入详见chatterbot-voice输出形式 Output AdaptersOutput format adapter支持textjson和object格式的输出Terminal adapterHipChat AdapterMailgun adapter允许chat bot基于Mailgun API进行邮件的发送Speech synthesisTTS(Text to speech)部分详见chatterbot-voice4、代码计算模式from chatterbot import ChatBotbot ChatBot(Math Time Bot,logic_adapters[chatterbot.logic.MathematicalEvaluation,chatterbot.logic.TimeLogicAdapter],input_adapterchatterbot.input.VariableInputTypeAdapter,output_adapterchatterbot.output.OutputAdapter)# 进行数学计算question What is 4 9?print(question)response bot.get_response(question)print(response)print(\n)# 回答和时间相关的问题question What time is it?print(question)response bot.get_response(question)print(response)image利用已经提供好的小中文语料库from chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerchatbot ChatBot(ChineseChatBot)trainer ChatterBotCorpusTrainer(chatbot)# 使用中文语料库训练它trainer.train(chatterbot.corpus.chinese)def response_text(sentence):res_text chatbot.get_response(sentence)print(sentence , ----, res_text)return res_text#if __name__ __main__:# 开始对话while True:print(chatbot.get_response(input()))# print(response_text(你是谁))image小黄鸡语料更智能(推荐)from chatterbot import ChatBotbot ChatBot(my-chat, database_urisqlite:///db.sqlite3)def response_text(sentence):temp bot.get_response(sentence)return temp.textif __name__ __main__:# bot_response response_text(你几岁了)# print(bot_response)# 开始对话while True:print(response_text(input()))image小黄鸡语料数据库Snip20191204_47.png