浏览代码

[Feature] manage lower/upper cases in order and user sentence

monf 8 年之前
父节点
当前提交
4f909f65e1
共有 3 个文件被更改,包括 70 次插入3 次删除
  1. 43 0
      Tests/test_order_analyser.py
  2. 0 2
      kalliope/brain.yml
  3. 27 1
      kalliope/core/OrderAnalyser.py

+ 43 - 0
Tests/test_order_analyser.py

@@ -218,6 +218,49 @@ class TestOrderAnalyser(unittest.TestCase):
         self.assertFalse(OrderAnalyser.spelt_order_match_brain_order_via_table(order_to_test, sentence_to_test),
                          "Fail to ensure the expected sentence is not matching the order")
 
+        # Upper/lower cases
+        sentence_to_test = "THIS is THE order"
+        self.assertTrue(OrderAnalyser.spelt_order_match_brain_order_via_table(order_to_test, sentence_to_test),
+                        "Fail matching Upper/lower cases")
+
+    def test_format_sentences_to_analyse(self):
+
+        # First capital in sentence
+        order_to_test = "this is the order"
+        sentence_to_test = "This is the order"
+        expected_result = "this is the order", "this is the order"
+        self.assertEqual(OrderAnalyser._format_sentences_to_analyse(order_to_analyse=order_to_test,
+                                                                    user_said=sentence_to_test),
+                         expected_result,
+                         "Fails formatting the sentences with first capital in sentence")
+
+        # random uppercase in sentence
+        order_to_test = "this is the order"
+        sentence_to_test = "This IS the ordeR"
+        expected_result = "this is the order", "this is the order"
+        self.assertEqual(OrderAnalyser._format_sentences_to_analyse(order_to_analyse=order_to_test,
+                                                                    user_said=sentence_to_test),
+                         expected_result,
+                         "Fails formatting the sentences with random in sentence")
+
+        # random uppercase in order
+        order_to_test = "thiS is THE orDer"
+        sentence_to_test = "this is the order"
+        expected_result = "this is the order", "this is the order"
+        self.assertEqual(OrderAnalyser._format_sentences_to_analyse(order_to_analyse=order_to_test,
+                                                                    user_said=sentence_to_test),
+                         expected_result,
+                         "Fails formatting the sentences with random in order")
+
+        # random uppercase in both order and sentence
+        order_to_test = "thiS is THE orDer"
+        sentence_to_test = "THIS is the Order"
+        expected_result = "this is the order", "this is the order"
+        self.assertEqual(OrderAnalyser._format_sentences_to_analyse(order_to_analyse=order_to_test,
+                                                                    user_said=sentence_to_test),
+                         expected_result,
+                         "Fails formatting the sentences with random in both order and sentence")
+
     def test_get_split_order_without_bracket(self):
 
         # Success

+ 0 - 2
kalliope/brain.yml

@@ -1,7 +1,6 @@
 ---
   - name: "say-hello-fr"
     signals:
-      - order: "bonjour"
       - order: "Bonjour"
     neurons:
       - say:
@@ -10,7 +9,6 @@
 
   - name: "say-hello-en"
     signals:
-      - order: "hello"
       - order: "Hello"
     neurons:
       - say:

+ 27 - 1
kalliope/core/OrderAnalyser.py

@@ -260,17 +260,43 @@ class OrderAnalyser:
     @classmethod
     def spelt_order_match_brain_order_via_table(cls, order_to_analyse, user_said):
         """
-        return true if all string that are in the sentence are present in the order to test
+        return true if all formatted(_format_sentences_to_analyse(order_to_analyse, user_said)) strings
+                that are in the sentence are present in the order to test.
         :param order_to_analyse: String order to test
         :param user_said: String to compare to the order
         :return: True if all string are present in the order
         """
+        logger.debug("[spelt_order_match_brain_order_via_table] before formatting, "
+                     "order to analyse: %s, "
+                     "user sentence: %s"
+                     % (order_to_analyse, user_said))
+        order_to_analyse, user_said = cls._format_sentences_to_analyse(order_to_analyse=order_to_analyse,
+                                                                       user_said=user_said)
         list_word_user_said = user_said.split()
         split_order_without_bracket = cls._get_split_order_without_bracket(order_to_analyse)
 
         # if all words in the list of what the user said in in the list of word in the order
         return cls._counter_subset(split_order_without_bracket, list_word_user_said)
 
+    @staticmethod
+    def _format_sentences_to_analyse(order_to_analyse, user_said):
+        """
+        return formatted tuple of the order_to_analyse, user_said
+        :param order_to_analyse: String order to test
+        :param user_said: String to compare to the order
+        :return: tuple of the order_to_analyse, user_said
+        """
+        # Lowercase all incoming
+        order_to_analyse = order_to_analyse.lower()
+        user_said = user_said.lower()
+
+        logger.debug("[_format_sentences_to_analyse] formatted, "
+                     "order to analyse: %s, "
+                     "user sentence: %s"
+                     % (order_to_analyse, user_said))
+
+        return order_to_analyse, user_said
+
     @staticmethod
     def _get_split_order_without_bracket(order):
         """