Exemplo n.º 1
0
    def test_find_all_matching_brackets(self):
        """
        Test the Utils find all matching brackets
        """
        sentence = "This is the {{bracket}}"
        expected_result = ["{{bracket}}"]
        self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence),
                         expected_result, "Fail to match one bracket")

        sentence = "This is the {{bracket}} {{second}}"
        expected_result = ["{{bracket}}", "{{second}}"]
        self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence),
                         expected_result, "Fail to match two brackets")
Exemplo n.º 2
0
    def test_find_all_matching_brackets(self):
        """
        Test the Utils find all matching brackets
        """
        sentence = "This is the {{bracket}}"
        expected_result = ["{{bracket}}"]
        self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence),
                         expected_result,
                         "Fail to match one bracket")

        sentence = "This is the {{bracket}} {{second}}"
        expected_result = ["{{bracket}}", "{{second}}"]
        self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence),
                         expected_result,
                         "Fail to match two brackets")
Exemplo n.º 3
0
 def _neuron_parameters_are_available_in_loaded_parameters(
         string_parameters, loaded_parameters):
     """
     Check that all parameters in brackets are available in the loaded_parameters dict
     
     E.g:
     string_parameters = "this is a {{ parameter1 }}"
     
     Will return true if the loaded_parameters looks like the following
     loaded_parameters { "parameter1": "a value"}        
     
     :param string_parameters: The string that contains one or more parameters in brace brackets
     :param loaded_parameters: Dict of parameter
     :return: True if all parameters in brackets have an existing key in loaded_parameters dict
     """
     list_parameters_with_brackets = Utils.find_all_matching_brackets(
         string_parameters)
     # remove brackets to keep only the parameter name
     for parameter_with_brackets in list_parameters_with_brackets:
         parameter = Utils.remove_spaces_in_brackets(
             parameter_with_brackets)
         parameter = parameter.replace("{{", "").replace("}}", "")
         if loaded_parameters is None or parameter not in loaded_parameters:
             Utils.print_danger(
                 "The parameter %s is not available in the order" %
                 str(parameter))
             return False
     return True
Exemplo n.º 4
0
    def _get_split_order_without_bracket(order):
        """
        Get an order with bracket inside like: "hello my name is {{ name }}.
        return a list of string without bracket like ["hello", "my", "name", "is"]
        :param order: sentence to split
        :return: list of string without bracket
        """

        matches = Utils.find_all_matching_brackets(order)
        for match in matches:
            order = order.replace(match, "")
        # then split
        split_order = order.split()
        return split_order
Exemplo n.º 5
0
    def _get_split_order_without_bracket(order):
        """
        Get an order with bracket inside like: "hello my name is {{ name }}.
        return a list of string without bracket like ["hello", "my", "name", "is"]
        :param order: sentence to split
        :return: list of string without bracket
        """

        matches = Utils.find_all_matching_brackets(order)
        for match in matches:
            order = order.replace(match, "")
        # then split
        split_order = order.split()
        return split_order
Exemplo n.º 6
0
 def _neuron_parameters_are_available_in_loaded_parameters(string_parameters, loaded_parameters):
     """
     Check that all parameters in brackets are available in the loaded_parameters dict
     
     E.g:
     string_parameters = "this is a {{ parameter1 }}"
     
     Will return true if the loaded_parameters looks like the following
     loaded_parameters { "parameter1": "a value"}        
     
     :param string_parameters: The string that contains one or more parameters in brace brackets
     :param loaded_parameters: Dict of parameter
     :return: True if all parameters in brackets have an existing key in loaded_parameters dict
     """
     list_parameters_with_brackets = Utils.find_all_matching_brackets(string_parameters)
     # remove brackets to keep only the parameter name
     for parameter_with_brackets in list_parameters_with_brackets:
         parameter = Utils.remove_spaces_in_brackets(parameter_with_brackets)
         parameter = parameter.replace("{{", "").replace("}}", "")
         if loaded_parameters is None or parameter not in loaded_parameters:
             Utils.print_danger("The parameter %s is not available in the order" % str(parameter))
             return False
     return True