示例#1
0
    def test_clean_parameter_from_order(self):
        Cortex.temp = {
            "key1": "value1",
            "key2": "value2"
        }

        Cortex.clean_parameter_from_order()
        expected_temp_dict = dict()
        self.assertDictEqual(expected_temp_dict, Cortex.memory)
示例#2
0
    def execute(self, answer=None, is_api_call=False, no_voice=False):
        """
        Process the LIFO list.
        
        The LIFO list contains multiple list of matched synapses.        
        For each list of matched synapse we process synapses inside        
        For each synapses we process neurons.        
        If a neuron add a Synapse list to the lifo, this synapse list is processed before executing the first list 
        in which we were in.
        
        :param answer: String answer to give the the last neuron which was waiting for an answer
        :param is_api_call: Boolean passed to all neuron in order to let them know if the current call comes from API
        :param no_voice: If true, the generated text will not be processed by the TTS engine
        :return: serialized APIResponse object
        """
        # store the answer if present
        self.answer = answer
        self.is_api_call = is_api_call
        self.no_voice = no_voice

        if not self.is_running:
            self.is_running = True

            try:
                # we keep looping over the LIFO til we have synapse list to process in it
                while self.lifo_list:
                    logger.debug(
                        "[LIFOBuffer] number of synapse list to process: %s" %
                        len(self.lifo_list))
                    try:
                        # get the last list of matched synapse in the LIFO
                        last_synapse_fifo_list = self.lifo_list[-1]
                        self._process_synapse_list(last_synapse_fifo_list)
                    except SynapseListAddedToLIFO:
                        continue
                    # remove the synapse list from the LIFO
                    self.lifo_list.remove(last_synapse_fifo_list)
                    # clean the cortex from value loaded from order as all synapses have been processed
                    Cortex.clean_parameter_from_order()
                self.is_running = False
                raise Serialize

            except Serialize:
                return self._return_serialized_api_response()
示例#3
0
    def execute(self, answer=None, is_api_call=False):
        """
        Process the LIFO list.

        The LIFO list contains multiple list of matched synapses.
        For each list of matched synapse we process synapses inside
        For each synapses we process neurons.
        If a neuron add a Synapse list to the lifo, this synapse list is processed before executing the first list
        in which we were in.

        :param answer: String answer to give the the last neuron which was waiting for an answer
        :param is_api_call: Boolean passed to all neuron in order to let them know if the current call comes from API
        :return: serialized APIResponse object
        """
        # store the answer if present
        self.answer = answer
        self.is_api_call = is_api_call

        try:
            if not self.is_running:
                self.is_running = True

                # we keep looping over the LIFO til we have synapse list to process in it
                while self.lifo_list:
                    logger.debug("[LIFOBuffer] number of synapse list to process: %s" % len(self.lifo_list))
                    try:
                        # get the last list of matched synapse in the LIFO
                        last_synapse_fifo_list = self.lifo_list[-1]
                        self._process_synapse_list(last_synapse_fifo_list)
                    except SynapseListAddedToLIFO:
                        continue
                    # remove the synapse list from the LIFO
                    self.lifo_list.remove(last_synapse_fifo_list)
                    # clean the cortex from value loaded from order as all synapses have been processed
                    Cortex.clean_parameter_from_order()
                self.is_running = False
                raise Serialize

        except Serialize:
            return self._return_serialized_api_response()
示例#4
0
    def test_clean_parameter_from_order(self):
        Cortex.temp = {"key1": "value1", "key2": "value2"}

        Cortex.clean_parameter_from_order()
        expected_temp_dict = dict()
        self.assertDictEqual(expected_temp_dict, Cortex.memory)