Преглед изворни кода

order analyser now return a list of MatchedSynapse object

nico пре 8 година
родитељ
комит
76267149cd
2 измењених фајлова са 20 додато и 19 уклоњено
  1. 11 1
      kalliope/core/OrderAnalyser.py
  2. 9 18
      kalliope/core/SynapseLauncher.py

+ 11 - 1
kalliope/core/OrderAnalyser.py

@@ -2,6 +2,7 @@
 import collections
 from collections import Counter
 
+from kalliope.core.Models.MatchedSynapse import MatchedSynapse
 from kalliope.core.Utils.Utils import Utils
 from kalliope.core.ConfigurationManager import SettingLoader
 from kalliope.core.Models import Order
@@ -53,7 +54,16 @@ class OrderAnalyser:
                         logger.debug("Order found! Run synapse name: %s" % synapse.name)
                         Utils.print_success("Order matched in the brain. Running synapse \"%s\"" % synapse.name)
                         list_match_synapse.append(synapse_order_tuple(synapse=synapse, order=signal.sentence))
-        return list_match_synapse
+
+        # create a list of MatchedSynapse from the tuple list
+        list_synapse_to_process = list()
+        for tuple_el in list_match_synapse:
+            new_matching_synapse = MatchedSynapse(matched_synapse=tuple_el.synapse,
+                                                  matched_order=tuple_el.order,
+                                                  user_order=order)
+            list_synapse_to_process.append(new_matching_synapse)
+
+        return list_synapse_to_process
 
     @classmethod
     def spelt_order_match_brain_order_via_table(cls, order_to_analyse, user_said):

+ 9 - 18
kalliope/core/SynapseLauncher.py

@@ -65,7 +65,7 @@ class SynapseLauncher(object):
         :return: list of matched synapse
         """
 
-        # get our single ton LIFO
+        # get our singleton LIFO
         lifo_buffer = LIFOBuffer()
 
         # if the LIFO is not empty, so, the current order is passed to the current processing synapse as an answer
@@ -73,23 +73,12 @@ class SynapseLauncher(object):
             # the LIFO is not empty, this is an answer to a previous call
             return lifo_buffer.execute(answer=order_to_process, is_api_call=is_api_call)
 
-        else:
-            # the LIFO is empty, this is a new call
-
-            # get a tuple of (synapse, order) that match in the brain
-            synapses_to_launch_tuple = OrderAnalyser.get_matching_synapse(order=order_to_process, brain=brain)
+        else:  # the LIFO is empty, this is a new call
+            # get a list of matched synapse from the order
+            list_synapse_to_process = OrderAnalyser.get_matching_synapse(order=order_to_process, brain=brain)
 
-            # we transform the tuple in a MatchedSynapse list
-            list_synapse_to_process = list()
-
-            if synapses_to_launch_tuple:  # the order analyser returned us a list
-                for tuple_el in synapses_to_launch_tuple:
-                    new_matching_synapse = MatchedSynapse(matched_synapse=tuple_el.synapse,
-                                                          matched_order=tuple_el.order,
-                                                          user_order=order_to_process)
-                    list_synapse_to_process.append(new_matching_synapse)
-            else:
-                # execute the default synapse if exist
+            if not list_synapse_to_process:  # the order analyser returned us an empty list
+                # add the default synapse if exist into the lifo
                 if settings.default_synapse:
                     logger.debug("[SynapseLauncher] No matching Synapse-> running default synapse ")
                     # get the default synapse
@@ -99,8 +88,10 @@ class SynapseLauncher(object):
                                                           matched_order=None,
                                                           user_order=order_to_process)
                     list_synapse_to_process.append(new_matching_synapse)
+                else:
+                    logger.debug("[SynapseLauncher] No matching Synapse and no default synapse ")
 
             lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process)
-
             lifo_buffer.api_response.user_order = order_to_process
+
             return lifo_buffer.execute(is_api_call=is_api_call)