|
@@ -65,7 +65,8 @@ class OrderAnalyser:
|
|
|
|
|
|
# Start a neuron list with params
|
|
# Start a neuron list with params
|
|
self._start_list_neurons(list_neurons=tuple.synapse.neurons,
|
|
self._start_list_neurons(list_neurons=tuple.synapse.neurons,
|
|
- params=params)
|
|
|
|
|
|
+ params=params,
|
|
|
|
+ settings=self.settings)
|
|
synapses_launched.append(tuple.synapse)
|
|
synapses_launched.append(tuple.synapse)
|
|
|
|
|
|
# return the list of launched synapse
|
|
# return the list of launched synapse
|
|
@@ -139,17 +140,37 @@ class OrderAnalyser:
|
|
:return: the dict key/value
|
|
:return: the dict key/value
|
|
"""
|
|
"""
|
|
params = dict()
|
|
params = dict()
|
|
- if cls._is_containing_bracket(string_order):
|
|
|
|
|
|
+ if Utils.is_containing_bracket(string_order):
|
|
params = cls._associate_order_params_to_values(order_to_check, string_order)
|
|
params = cls._associate_order_params_to_values(order_to_check, string_order)
|
|
logger.debug("Parameters for order: %s" % params)
|
|
logger.debug("Parameters for order: %s" % params)
|
|
return params
|
|
return params
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
- def _start_list_neurons(cls, list_neurons, params):
|
|
|
|
|
|
+ def _start_list_neurons(cls, list_neurons, params, settings):
|
|
# start neurons
|
|
# start neurons
|
|
for neuron in list_neurons:
|
|
for neuron in list_neurons:
|
|
|
|
+ cls._replace_global_variables(neuron, settings)
|
|
cls._start_neuron(neuron, params)
|
|
cls._start_neuron(neuron, params)
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _replace_global_variables(neuron, settings):
|
|
|
|
+ """
|
|
|
|
+ Replace all the parameters with variables with the variable value.
|
|
|
|
+ :param neuron: the neuron
|
|
|
|
+ :param settings: the settings
|
|
|
|
+ """
|
|
|
|
+ for param in neuron.parameters:
|
|
|
|
+ if Utils.is_containing_bracket(neuron.parameters[param]):
|
|
|
|
+ sentence_no_spaces = Utils.remove_spaces_in_brackets(sentence=neuron.parameters[param])
|
|
|
|
+ list_of_bracket_params = Utils.find_all_matching_brackets(sentence=sentence_no_spaces)
|
|
|
|
+ for param_with_bracket in list_of_bracket_params:
|
|
|
|
+ param_no_brackets = param_with_bracket.replace("{{", "").replace("}}", "")
|
|
|
|
+ if param_no_brackets in settings.variables:
|
|
|
|
+ logger.debug("Replacing variable %s with %s" % (param_with_bracket,
|
|
|
|
+ settings.variables[param_no_brackets]))
|
|
|
|
+ neuron.parameters[param] = sentence_no_spaces.replace(param_with_bracket,
|
|
|
|
+ str(settings.variables[param_no_brackets]))
|
|
|
|
+
|
|
@staticmethod
|
|
@staticmethod
|
|
def _start_neuron(neuron, params):
|
|
def _start_neuron(neuron, params):
|
|
"""
|
|
"""
|
|
@@ -190,8 +211,8 @@ class OrderAnalyser:
|
|
else:
|
|
else:
|
|
Utils.print_danger("A problem has been found in the Synapse.")
|
|
Utils.print_danger("A problem has been found in the Synapse.")
|
|
|
|
|
|
- @classmethod
|
|
|
|
- def _associate_order_params_to_values(cls, order, order_to_check):
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _associate_order_params_to_values(order, order_to_check):
|
|
"""
|
|
"""
|
|
Associate the variables from the order to the incoming user order
|
|
Associate the variables from the order to the incoming user order
|
|
:param order_to_check: the order to check incoming from the brain
|
|
:param order_to_check: the order to check incoming from the brain
|
|
@@ -203,9 +224,7 @@ class OrderAnalyser:
|
|
logger.debug("[OrderAnalyser._associate_order_params_to_values] user order: %s, "
|
|
logger.debug("[OrderAnalyser._associate_order_params_to_values] user order: %s, "
|
|
"order to check: %s" % (order, order_to_check))
|
|
"order to check: %s" % (order, order_to_check))
|
|
|
|
|
|
- pattern = '\s+(?=[^\{\{\}\}]*\}\})'
|
|
|
|
- # Remove white spaces (if any) between the variable and the double brace then split
|
|
|
|
- list_word_in_order = re.sub(pattern, '', order_to_check).split()
|
|
|
|
|
|
+ list_word_in_order = Utils.remove_spaces_in_brackets(order_to_check).split()
|
|
|
|
|
|
# get the order, defined by the first words before {{
|
|
# get the order, defined by the first words before {{
|
|
# /!\ Could be empty if order starts with double brace
|
|
# /!\ Could be empty if order starts with double brace
|
|
@@ -218,10 +237,10 @@ class OrderAnalyser:
|
|
# make dict var:value
|
|
# make dict var:value
|
|
dict_var = dict()
|
|
dict_var = dict()
|
|
for idx, ow in enumerate(list_word_in_order):
|
|
for idx, ow in enumerate(list_word_in_order):
|
|
- if cls._is_containing_bracket(ow):
|
|
|
|
|
|
+ if Utils.is_containing_bracket(ow):
|
|
# remove bracket and grab the next value / stop value
|
|
# remove bracket and grab the next value / stop value
|
|
var_name = ow.replace("{{", "").replace("}}", "")
|
|
var_name = ow.replace("{{", "").replace("}}", "")
|
|
- stop_value = cls._get_next_value_list(list_word_in_order[idx:])
|
|
|
|
|
|
+ stop_value = Utils._get_next_value_list(list_word_in_order[idx:])
|
|
if stop_value is None:
|
|
if stop_value is None:
|
|
dict_var[var_name] = " ".join(truncate_list_word_said)
|
|
dict_var[var_name] = " ".join(truncate_list_word_said)
|
|
break
|
|
break
|
|
@@ -236,26 +255,6 @@ class OrderAnalyser:
|
|
truncate_list_word_said = truncate_list_word_said[1:]
|
|
truncate_list_word_said = truncate_list_word_said[1:]
|
|
return dict_var
|
|
return dict_var
|
|
|
|
|
|
- @staticmethod
|
|
|
|
- def _is_containing_bracket(sentence):
|
|
|
|
- """
|
|
|
|
- Return True if the text in <sentence> contains brackets
|
|
|
|
- :param sentence:
|
|
|
|
- :return:
|
|
|
|
- """
|
|
|
|
- # print "sentence to test %s" % sentence
|
|
|
|
- pattern = r"{{|}}"
|
|
|
|
- # prog = re.compile(pattern)
|
|
|
|
- check_bool = re.search(pattern, sentence)
|
|
|
|
- if check_bool is not None:
|
|
|
|
- return True
|
|
|
|
- return False
|
|
|
|
-
|
|
|
|
- @staticmethod
|
|
|
|
- def _get_next_value_list(list_to_check):
|
|
|
|
- ite = list_to_check.__iter__()
|
|
|
|
- next(ite, None)
|
|
|
|
- return next(ite, None)
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def spelt_order_match_brain_order_via_table(cls, order_to_analyse, user_said):
|
|
def spelt_order_match_brain_order_via_table(cls, order_to_analyse, user_said):
|
|
@@ -305,9 +304,8 @@ class OrderAnalyser:
|
|
:param order: sentence to split
|
|
:param order: sentence to split
|
|
:return: list of string without bracket
|
|
:return: list of string without bracket
|
|
"""
|
|
"""
|
|
- pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
|
|
|
|
- # find everything like {{ word }}
|
|
|
|
- matches = re.findall(pattern, order)
|
|
|
|
|
|
+
|
|
|
|
+ matches = Utils.find_all_matching_brackets(order)
|
|
for match in matches:
|
|
for match in matches:
|
|
order = order.replace(match, "")
|
|
order = order.replace(match, "")
|
|
# then split
|
|
# then split
|