Exemple #1
0
def test_loaddirorfile():

    path_to_mockfile = "tests/tests_unit/test_botinterface/mock_brain.rive"  # ".\\tests\\tests_unit\\test_botinterface\mock_brain.rive"
    path_to_mockdir = "tests/tests_unit/test_botinterface/mock_brain_dir"  #".\\tests\\tests_unit\\test_botinterface\mock_brain_dir"
    interpreter = _loadDirOrFile(rivescript.RiveScript(), path_to_mockfile)
    actual_bot_name_from_file = interpreter.get_variable("name")

    interpreter = _loadDirOrFile(rivescript.RiveScript(), path_to_mockdir)
    actual_bot_name_from_dir = interpreter.get_variable("name")

    expected_bot_name = "mocked"
    assert expected_bot_name == actual_bot_name_from_file
    assert expected_bot_name == actual_bot_name_from_dir
Exemple #2
0
def build():
    preprocessor = preprocess.preprocessor_builder.build()
    postprocessor = postprocess.postprocessor_builder.build()
    interpreter = botinterface.rivescript_proxy.RiveScriptProxy(\
                        rivescriptInterpreter=rivescript.RiveScript(debug=False))
    return botinterface.bot_rivescript.BotRivescript(
        preprocessor=preprocessor,
        interpreter=interpreter,
        postprocessor=postprocessor)
Exemple #3
0
    def build(self):
        '''To assemble and return the chatbot instance'''
        if self.interpreter is None:
            productionRiveScript = rivescript.RiveScript(debug=False)
            self.interpreter = botinterface.rivescript_proxy.RiveScriptProxy(
                rivescriptInterpreter=productionRiveScript, brain=self.brain)

        return botinterface.bot_rivescript.BotRivescript(
            preprocessor=self.preprocessor,
            postprocessor=self.postprocessor,
            interpreter=self.interpreter)
def main(args):
    bot = rivescript.RiveScript()
    bot.load_directory("./brain")
    bot.sort_replies()
    # chatloop:
    while True:
        msg = raw_input("You> ")
        if msg == "/q":
            quit()

        reply = bot.reply(USERID, msg)
        print "Bot>", reply
Exemple #5
0
def test_loadbrain():

    logfile_to_verify_sorting = "tests/tests_unit/test_botinterface/rivescriptlog"
    path_to_mockfile = "tests/tests_unit/test_botinterface/mock_brain.rive"  #".\\tests\\tests_unit\\test_botinterface\mock_brain.rive"
    interpreter = loadBrain(
        rivescript.RiveScript(log=logfile_to_verify_sorting), path_to_mockfile)

    with open(logfile_to_verify_sorting, 'r') as f:
        logfile_content = f.read()

    assert "Sorting triggers..." in logfile_content
    clear_logfile_content(logfile_to_verify_sorting)
 def __init__(self, user_id, fb_page_id):
     logger.debug(
         str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
     assert isinstance(user_id, str)
     assert isinstance(fb_page_id, str)
     rsbot = rivescript.RiveScript(utf8=True)
     rsbot.unicode_punctuation = re.compile(
         r'[,!?;:]')  # re.compile(r'[.,!?;:]')
     rsbot.load_directory("./rsBrainFiles")
     rsbot.sort_replies()
     rsbot.set_uservar(user_id, "fb_page_id", fb_page_id)
     self.rsbot = rsbot
Exemple #7
0
    def load(self, name, code):
        """Prepare a JavaScript code object given by the RS interpreter."""

        source = "function RSOBJ_" + name + "(args) {\n" + "\n".join(code) + "}\n"
        self._objects[name] = source

    def call(self, rs, name, user, fields):
        if not name in self._objects:
            return "[Object Not Found]"

        source = "<script>\n" + self._objects[name] \
            + "var fields_" + name + " = new Array()\n"
        i = 0
        for field in fields:
            source += "fields_" + name + "[" + str(i) + "] = " \
                + '"' + str(field).replace('"', r'\"') + "\";\n"
            i += 1
        source += "document.writeln(RSOBJ_" + name + "(fields_" + name + "))" \
            + "</script>"
        return source

bot = rivescript.RiveScript()
bot.set_handler("javascript", JSObject())
bot.load_file("javascript.rive")
bot.sort_replies()
while True:
    msg = raw_input("You> ")
    reply = bot.reply("localuser", msg)
    print "Bot>", reply
 def __init__(self):
     self.normaliser = rivescript.RiveScript(debug=True, utf8=True)
     self.normaliser.load_directory("brain")
     self.normaliser.sort_replies()
Exemple #9
0
cookie[config.session_cookie] = sessid
cookie[config.session_cookie]["path"] = "/"
cookie[config.session_cookie]["expires"] = \
 expiration.strftime("%a, %d-%b-%Y %H:%M:%S PST")

print("Content-Type: application/json")
print(cookie.output())
print()

# Handle their request now.
if not "error" in resp:
    if "message" in q:
        msg = q["message"].value

        # Initialize RiveScript.
        rs = rivescript.RiveScript()
        rs.load_directory(config.brain_path)
        rs.sort_replies()

        # Load their session vars.
        recall_session(sessid, rs)

        # Get a reply for them.
        reply = rs.reply(sessid, msg)

        # Save their session info.
        write_session(sessid, rs)

        resp["status"] = "ok"
        resp["name"] = config.bot_name
        resp["reply"] = reply
Exemple #10
0
 def __init__(self):
     self.k = rivescript.RiveScript()
Exemple #11
0
 def init(self, params):
     self.rs = rivescript.RiveScript()
     self.rs.load_directory(params['replies'])
     self.rs.sort_replies()
 def __init__(self,
              brain="./brain",
              rivescriptInterpreter=rivescript.RiveScript()):
     self._rivescriptInterpreter =\
                 rivescript_loader.loadBrain(rivescriptInterpreter, brain)
Exemple #13
0
               except (ConnectionError,URLError):
                              return s_print(['Unable to Connect'])
               except RuntimeError:
                              return search3(topic)
def search(topic):
               try:
                              p=page(topic)
                              return s_print([p.title,p.summary[:1993-len(p.url)-len(p.title)],"\b...",p.url])
               except PageError:
                              return search2(topic)
               except DisambiguationError:
                              return search2(topic)
               except ConnectionError:
                              return search2(topic)

x=rs.RiveScript(True,depth=1)
#a=App()
code=open('ai2.rive')
x.stream(code.read())
x.sort_replies()
inp=''
s_print(['Hello, Human!'])
def reply(inp): #, up, cqs):
               inp=inp.replace('don\'t','do not').replace('can\'t','cannot').replace('\'ld',' would').replace('\'ll','will').replace('dont','do not').replace('cant','cannot')
               if 'calculate' in inp.lower():
                              if inp.endswith(".."):
                                             return s_print(['Your answer is:- ',eval(inp[inp.index('e')+1:len(inp)].replace('.',''))])
                              else:
                                             return s_print(['Your answer is:- ',eval(inp[inp.index('e')+1:len(inp)])])
               elif 'flip a coin' in inp.lower():
                              ht=['heads','tails']