Example #1
0
    def process(self, query):
        """ Process the input query by calling rivescript brain
            @param query : the text query
        """
        reply = ""
        try:
            self.log.debug(u"Before transforming query : {0}".format(query))
            self.brain.raw_query = query

            query = clean_input(query)

            self.log.debug(u"After transforming query : {0}".format(query))
            self.brain.query = query

            # process the query
            self.log.debug(
                u"Before calling Rivescript brain for processing : {0} (type={1})"
                .format(query, type(query)))
            reply = self.brain.reply(self.user_name, query)
            self.log.debug(
                u"Processing finished. The reply is : {0}".format(reply))
            return reply
        except:
            self.log.error(
                u"Error while processing query '{0}'. Error is : {1}".format(
                    query, traceback.format_exc()))
            return "Error"
Example #2
0
    def process(self, query):
        """ Process the input query by calling rivescript brain
            @param query : the text query
        """
        reply = ""
        try:
            self.log.debug(u"Before transforming query : {0}".format(query))
            self.brain.raw_query = query

            query = clean_input(query)

            self.log.debug(u"After transforming query : {0}".format(query))
            self.brain.query = query

            # process the query
            self.log.debug(u"Before calling Rivescript brain for processing : {0} (type={1})".format(query, type(query)))
            reply = self.brain.reply(self.user_name, query)
            self.log.debug(u"Processing finished. The reply is : {0}".format(reply))
            return reply
        except:
            self.log.error(u"Error while processing query '{0}'. Error is : {1}".format(query, traceback.format_exc()))
            return "Error"
Example #3
0
    def __init__(self):

        ### Option parser
        parser = ArgumentParser()
        parser.add_argument("-i",
                          action="store_true",
                          dest="interactive",
                          default=False, \
                          help="Butler interactive mode (must be used WITH -f).")

        Plugin.__init__(self, name='butler', parser=parser, log_prefix='core_')

        ### MQ
        # MQ publisher
        #self._mq_name = "interface-{0}.{1}".format(self._name, self.get_sanitized_hostname())
        self._mq_name = "butler"
        #self.zmq = zmq.Context()
        self.pub = MQPub(self.zmq, self._mq_name)

        # subscribe the MQ for interfaces inputs
        self.add_mq_sub('interface.input')
        # devices updates
        self.add_mq_sub('device.update')

        ### Configuration elements
        try:
            cfg = Loader('butler')
            config = cfg.load()
            conf = dict(config[1])

            self.lang = conf['lang']
            self.butler_name = conf['name']
            self.log.debug(u"The butler configured name is '{0}'".format(
                self.butler_name))
            self.butler_name_cleaned = clean_input(conf['name'])
            self.log.debug(u"The butler cleaned name is '{0}'".format(
                self.butler_name_cleaned))
            self.butler_sex = conf['sex']
            self.butler_mood = None
            if self.butler_sex not in SEX_ALLOWED:
                self.log.error(
                    u"Exiting : the butler sex configured is not valid : '{0}'. Expecting : {1}"
                    .format(self.butler_sex, SEX_ALLOWED))
                self.force_leave()
                return

        except:
            self.log.error(
                u"Exiting : error while reading the configuration file '{0}' : {1}"
                .format(CONFIG_FILE, traceback.format_exc()))
            self.force_leave()
            return
        # user name (default is 'localuser')
        # this is not used for now on Domogik side
        self.user_name = "localuser"

        ### Prepare the brain
        # - validate packages

        # Start the brain :)
        self.brain = RiveScript(utf8=True)

        # set rivescript variables

        # Configure bot variables
        # all must be lower case....
        self.log.info(u"Configuring name and sex : {0}, {1}".format(
            self.butler_name_cleaned.lower(), self.butler_sex.lower()))
        self.brain.set_variable(u"name", self.butler_name_cleaned.lower())
        self.brain.set_variable(u"fullname", self.butler_name.lower())
        self.brain.set_variable(u"sex", self.butler_sex.lower())

        # set the PYTHONPATH
        sys.path.append(self.get_libraries_directory())

        # load the brain
        self.brain_content = None
        self.learn_content = None
        self.not_understood_content = None
        self.load_all_brain()

        # shortcut to allow the core brain package to reload the brain for learning
        self.brain.reload_butler = self.reload

        # shortcut to allow the core brain package to do logging and access the devices in memory
        self.brain.log = self.log
        self.brain.devices = []  # will be loaded in self.reload_devices()

        # history
        self.history = []

        # load all known devices
        self.reload_devices()

        self.log.info(
            u"*** Welcome in {0} world, your digital assistant! ***".format(
                self.butler_name))

        # for chat more only
        #self.log.info(u"You may type /quit to let {0} have a break".format(self.butler_name))

        ### Interactive mode
        if self.options.interactive:
            self.log.info(u"Launched in interactive mode : running the chat!")
            # TODO : run as a thread
            #self.run_chat()
            thr_run_chat = Thread(None, self.run_chat, "run_chat", (), {})
            thr_run_chat.start()
        else:
            self.log.info(u"Not launched in interactive mode")

        ### TODO
        #self.add_stop_cb(self.shutdown)

        self.log.info(u"Butler initialized")
        self.ready()
Example #4
0
    def __init__(self):

        ### Option parser
        parser = ArgumentParser()
        parser.add_argument("-i", 
                          action="store_true", 
                          dest="interactive", 
                          default=False, \
                          help="Butler interactive mode (must be used WITH -f).")

        Plugin.__init__(self, name = 'butler', parser = parser, log_prefix='core_')

        ### MQ
        # MQ publisher
        #self._mq_name = "interface-{0}.{1}".format(self._name, self.get_sanitized_hostname())
        self._mq_name = "butler"
        #self.zmq = zmq.Context()
        self.pub = MQPub(self.zmq, self._mq_name)

        # subscribe the MQ for interfaces inputs
        self.add_mq_sub('interface.input')
        # devices updates
        self.add_mq_sub('device.update')


        ### Configuration elements
        try:
            cfg = Loader('butler')
            config = cfg.load()
            conf = dict(config[1])

            self.lang = conf['lang']
            self.butler_name = conf['name']
            self.log.debug(u"The butler configured name is '{0}'".format(self.butler_name))
            self.butler_name_cleaned = clean_input(conf['name'])
            self.log.debug(u"The butler cleaned name is '{0}'".format(self.butler_name_cleaned))
            self.butler_sex = conf['sex']
            self.butler_mood = None
            if self.butler_sex not in SEX_ALLOWED:
                self.log.error(u"Exiting : the butler sex configured is not valid : '{0}'. Expecting : {1}".format(self.butler_sex, SEX_ALLOWED))
                self.force_leave()
                return
       
        except:
            self.log.error(u"Exiting : error while reading the configuration file '{0}' : {1}".format(CONFIG_FILE, traceback.format_exc()))
            self.force_leave()
            return
        # user name (default is 'localuser')
        # this is not used for now on Domogik side
        self.user_name = "localuser"

        ### Prepare the brain
        # - validate packages

        # Start the brain :)
        self.brain = RiveScript(utf8=True)

        # set rivescript variables

        # Configure bot variables
        # all must be lower case....
        self.log.info(u"Configuring name and sex : {0}, {1}".format(self.butler_name_cleaned.lower(), self.butler_sex.lower()))
        self.brain.set_variable(u"name", self.butler_name_cleaned.lower())
        self.brain.set_variable(u"fullname", self.butler_name.lower())
        self.brain.set_variable(u"sex", self.butler_sex.lower())

        # set the PYTHONPATH
        sys.path.append(self.get_libraries_directory())

        # load the brain
        self.brain_content = None
        self.learn_content = None
        self.not_understood_content = None
        self.load_all_brain()

        # shortcut to allow the core brain package to reload the brain for learning
        self.brain.reload_butler = self.reload

        # shortcut to allow the core brain package to do logging and access the devices in memory
        self.brain.log = self.log
        self.brain.devices = [] # will be loaded in self.reload_devices()


        # history
        self.history = []
 
        # load all known devices
        self.reload_devices()

        self.log.info(u"*** Welcome in {0} world, your digital assistant! ***".format(self.butler_name))

        # for chat more only
        #self.log.info(u"You may type /quit to let {0} have a break".format(self.butler_name))


        ### Interactive mode
        if self.options.interactive:
            self.log.info(u"Launched in interactive mode : running the chat!")
            # TODO : run as a thread
            #self.run_chat()
            thr_run_chat = Thread(None,
                                  self.run_chat,
                                  "run_chat",
                                  (),
                                  {})
            thr_run_chat.start()
        else:
            self.log.info(u"Not launched in interactive mode")
        

        ### TODO
        #self.add_stop_cb(self.shutdown)

        self.log.info(u"Butler initialized")
        self.ready()