本文整理汇总了Python中chatterbotapi.ChatterBotFactory类的典型用法代码示例。如果您正苦于以下问题:Python ChatterBotFactory类的具体用法?Python ChatterBotFactory怎么用?Python ChatterBotFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChatterBotFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, bot):
if bot.lower() == 'cleverbot':
self.bot = ChatterBotFactory().create(ChatterBotType.CLEVERBOT).create_session()
elif bot.lower() == 'jabberwacky':
self.bot = ChatterBotFactory().create(ChatterBotType.JABBERWACKY).create_session()
else:
self.bot = ChatterBotFactory().create(ChatterBotType.PANDORABOTS, 'f6d4afd83e34564d').create_session()
示例2: main
def main():
factory = ChatterBotFactory()
print 'hi'
bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot2session = bot2.create_session()
api = get_api()
if not api:
return
try:
status = api.received_messages(count=1)
except tweetpony.APIError as err:
print "Oh no! Your tweet could not be sent. Twitter returned error #%i and said: %s" % (err.code, err.description)
else:
message_id=status[0]['id']
user_id=status[0]['sender_screen_name']
status = api.received_messages(since_id=message_id)
while(1):
if status:
message_id=status[0]['id']
user_id=status[0]['sender_screen_name']
s = status[0]['text']
if s=='Take':
s='You can download the image from the link - '+take_image();
else:
s = bot2session.think(s);
api.send_message(screen_name=user_id,text=s)
time.sleep(60)
status=api.received_messages(since_id=message_id)
示例3: do
def do(speech):
factory = ChatterBotFactory()
bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()
bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot2session = bot2.create_session()
while(speech!="bye bye"):
if speech.find("search twitter for")!=-1:
speech=speech.replace("search twitter for",'')
search.main(speech)
elif speech.find("show twitter trend")!=-1:
trending.main()
elif speech.find("tell the weather")!=-1:
weather.main()
elif speech.find('show my e-mail')!=-1:
mailtest.main()
elif speech.find('send email')!=-1:
mailtest2.main()
elif speech.find('search bing for')!=-1:
speech=speech.replace('search bing for','')
bingsearch.main(speech)
else:
s = bot2session.think(speech);
print 'yam> ' + s
talks.main(s)
speech=listen()
speech=speech.lower()
示例4: _setup
def _setup(self):
factory = ChatterBotFactory()
self.bot = factory.create(ChatterBotType.CLEVERBOT)
self.template = spade.Behaviour.ACLTemplate()
self.template.setLanguage('english')
self.t = spade.Behaviour.MessageTemplate(self.template)
self.addBehaviour(self.MessageManager(), self.t)
if self.sendFirst:
self.addBehaviour(self.InitChatBot())
示例5: sms
def sms():
factory = ChatterBotFactory()
bot = factory.create(ChatterBotType.CLEVERBOT)
botSession = bot.create_session()
text = request.form.get('Body', '')
text = botSession.think(text)
response = twiml.Response()
response.sms(text)
return str(response)
示例6: __init__
def __init__(self, name, bottype, lang="en", pandoraid=""):
self.bottypestr=bottype
if bottype=="cleverbot":
self.bottype=ChatterBotType.CLEVERBOT
elif bottype=="jabberwacky":
self.bottype=ChatterBotType.JABBERWACKY
elif bottype=="pandorabots":
self.bottype=ChatterBotType.PANDORABOTS
factory = ChatterBotFactory()
self.pandoraid=pandoraid
self.name=name
self.session=factory.create(self.bottype,self.pandoraid).create_session()
self.lang=lang
示例7: ChatterBot
class ChatterBot(object):
def __init__(self, bot):
if bot.lower() == 'cleverbot':
self.bot = ChatterBotFactory().create(ChatterBotType.CLEVERBOT).create_session()
elif bot.lower() == 'jabberwacky':
self.bot = ChatterBotFactory().create(ChatterBotType.JABBERWACKY).create_session()
else:
self.bot = ChatterBotFactory().create(ChatterBotType.PANDORABOTS, 'f6d4afd83e34564d').create_session()
def respond_to(self, msg):
return self.bot.think(msg)
示例8: ChatterBots
class ChatterBots():
def __init__(self):
self.factory = ChatterBotFactory()
self.jabberwacky = self.factory.create(ChatterBotType.JABBERWACKY)
self.conversations = {}
def respond(self,question, conversation_id):
try:
self.conversations[conversation_id]
except KeyError:
self.conversations[conversation_id] = self.jabberwacky.create_session()
return self.conversations[conversation_id].think(question)
示例9: __init__
def __init__(self, interface):
super
self.interface = interface
mail_usr = '[email protected]'
mail_pw = 'lollerskates'
self.gmail_reader = gmail.GmailReader(mail_usr, mail_pw)
self.cleverbot_sessions = {}
self.cleverbot_factory = ChatterBotFactory()
self.mail_time = 5
self.flirt_time = 1200
示例10: SteamEcho
class SteamEcho(Component):
channel = 'steam'
def __init__(self, username, password):
super(SteamEcho, self).__init__()
self.username = username
self.password = password
def started(self, *args):
self.client = SteamClient().register(self)
self.client.connect()
self.friend_bots = {}
self.factory = ChatterBotFactory()
@handler('friend_message')
def _friend_message(self, steamid, chat_entry_type, message):
if chat_entry_type == EChatEntryType.ChatMsg:
print('[Incoming Friend Message] ' + message)
self.stimulate_chatter_bot(steamid, message)
def stimulate_chatter_bot(self, steamid, message):
if steamid not in self.friend_bots:
bot = self.factory.create(ChatterBotType.CLEVERBOT)
bot_session = bot.create_session()
self.friend_bots[steamid] = bot_session
bot_session = self.friend_bots[steamid]
response = bot_session.think(message)
self.fire(SendFriendMessage(steamid, EChatEntryType.ChatMsg, response))
@handler('send_friend_message')
def _send_friend_message(self, steamid, chat_entry_type, message):
if chat_entry_type == EChatEntryType.ChatMsg:
print('[Outgoing Friend Message] ' + message)
@handler('logged_on')
def _handle_logged_on(self, steamid):
self.fire(SetPersonaState(EPersonaState.Online))
@handler('connected')
def _handle_connected(self):
self.client.login(self.username, self.password)
@handler('friend_request')
def _handle_friend_request(self, steamid):
print('[Friend Request] ' + str(steamid))
示例11: while
while (thinkstart + ((len(msg) + 1) / 15)) > time.time():
time.sleep(1)
print ".",
sys.stdout.flush()
print
if LEARN == True:
LearnAndUpdateTerm(memory, termlst, p)
except (KeyboardInterrupt, SystemExit, EOFError):
print "Saving..."
out.write("END LOG: %s\n" % time.ctime())
out.close()
CloseMemory(memory, botname)
if __name__ == '__main__':
factory = ChatterBotFactory()
if sys.argv[1] == "clever":
botname = "daisy_vs_clever"
f = open(botname + ".log", "a")
bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()
chatbot(botname, bot1session, f)
elif sys.argv[1] == "pandora":
botname = "daisy_vs_pandora"
f = open(botname + ".log", "a")
#bot1 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot1 = factory.create(ChatterBotType.PANDORABOTS, '9fa364f2fe345a10') #mitsuku chatbot from mitsuku.com
bot1session = bot1.create_session()
bot1session.pandorabots_url = 'http://fiddle.pandorabots.com/pandora/talk-xml' #mitsuku doesn't work with the normal url
chatbot(botname, bot1session, f)
else:
示例12: listener
pub.publish(String(s))
def listener():
# In ROS, nodes are uniquely named. If two nodes with the same
# node are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
rospy.init_node('chat_bot', anonymous=True)
rospy.Subscriber("speech", String, callback)
rospy.Publisher('chat_bot/speech', String)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
factory = ChatterBotFactory()
bot = factory.create(ChatterBotType.CLEVERBOT)
session = bot.create_session()
pub = rospy.Publisher('chat_bot/speech', String)
listener()
#bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
#bot2session = bot2.create_session()
示例13: Copyright
# -*- coding: utf-8 -*-
from chatterbotapi import ChatterBotFactory, ChatterBotType
import sys
"""
chatterbotapi
Copyright (C) 2011 [email protected]
"""
factory = ChatterBotFactory()
bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()
bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot2session = bot2.create_session()
s = sys.argv[1]
s = bot2session.think(s);
print s
示例14: ChatterBotFactory
import android, time
from chatterbotapi import ChatterBotFactory,ChatterBotType
droid = android.Android()
factory = ChatterBotFactory()
c=1
if (not c):
print("* PandoraBots selected *")
bot = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
elif(c==1):
print("* JabberWacky selected *")
bot = factory.create(ChatterBotType.JABBERWACKY)
else:
print("* Clerverbot selected *")
bot = factory.create(ChatterBotType.CLEVERBOT)
session = bot.create_session()
readSms = set()
while 1:
time.sleep(10)
msgIDs = droid.smsGetMessageIds(True, 'inbox').result
if msgIDs:
for msgID in msgIDs:
if (msgID not in readSms):
message = droid.smsGetMessageById(msgID, ['address','body']).result
示例15: ChatterBotFactory
import socket
import sys
import aiml
import speech
import marshal
import chatterbotapi
import wolframalpha
wa = wolframalpha.Client("UPV478-9L6XGWQHPA")
informationPods = 3
usingJarvis = True
informationMode = False
from chatterbotapi import ChatterBotFactory, ChatterBotType
factory = ChatterBotFactory()
cbb = factory.create(ChatterBotType.JABBERWACKY)
cb = cbb.create_session()
k = aiml.Kernel()
#k.learn("std-startup.xml")
#k.respond("LOAD AIML B")
k.loadBrain("jarvis.brn")
k.setBotPredicate("name","Jarvis")
sessionFile = file("jarvis.ses", "rb")
session = marshal.load(sessionFile)
sessionFile.close()
for pred,value in session.items():