Ejemplo n.º 1
0
    def test_entities(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context([{
            "key": "existing_key",
            "type": "existing_key",
            "source": "detection",
            "entity_message_index": 0
        }], "include", 80.0, "new_key", "new_key")

        self.assertEqual([{
            'entity_message_index': 0,
            'key': 'existing_key',
            'source': 'detection',
            'type': 'existing_key'
        }, {
            'confidence': 80.0,
            'entity_message_index': 1,
            'key': 'new_key',
            'source': 'detection',
            'type': 'new_key',
            'type_weighting': 30.0
        }], actual)
    def test_existing_entity(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context(
            [
                {
                    "key": "existing_key",
                    "confidence": 80.0,
                    "type": "existing_key",
                    "source": "detection",
                    "entity_message_index": 0,
                    "type_weighting": 30.0,
                }
            ],
            "include",
            80.0,
            "existing_key",
            "existing_key",
        )

        self.assertEqual(
            [
                {
                    "entity_message_index": 1,
                    "key": "existing_key",
                    "confidence": 80.0,
                    "source": "detection",
                    "type": "existing_key",
                    "type_weighting": 33.0,
                }
            ],
            actual,
        )
    def test_outcome_exclude_entities(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context(
            [{"key": "existing_key", "type": "existing_key", "source": "detection", "entity_message_index": 0}],
            "exclude",
            80.0,
            "new_key",
            "new_type",
        )

        self.assertEqual(
            [
                {"entity_message_index": 0, "key": "existing_key", "source": "detection", "type": "existing_key"},
                {
                    "confidence": 80.0,
                    "entity_message_index": 1,
                    "negation_modifier": -100,
                    "key": "new_type",
                    "source": "detection",
                    "type": "new_key",
                    "type_weighting": 30.0,
                },
            ],
            actual,
        )
    def test_low_confidence_entities(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context(
            [{"key": "existing_key", "type": "existing_key", "source": "detection", "entity_message_index": 0}],
            "include",
            40.0,
            "new_key",
            "new_key",
        )

        self.assertEqual(
            [{"entity_message_index": 0, "key": "existing_key", "source": "detection", "type": "existing_key"}], actual
        )
Ejemplo n.º 5
0
    def test_existing_exclude_entity_now_include(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context([{
            'confidence': 80.0,
            'entity_message_index': 1,
            'negation_modifier': -100,
            'key': 'black',
            'source': 'detection',
            'type': 'color',
            'type_weighting': 90.0
        }], "include", 80.0, "color", "black")

        self.assertEqual([{
            'confidence': 80.0,
            'entity_message_index': 2,
            'key': 'black',
            'source': 'detection',
            'type': 'color',
            'type_weighting': 99.00000000000001
        }], actual)
Ejemplo n.º 6
0
    def test_regular(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        target.add_entity_to_context = MagicMock(
            side_effect=(["context_entities_1"]))

        actual = target.update_entities_with_last_message(
            ["entity_value"], {
                "detection": {
                    "outcomes": [{
                        "intent":
                        "intent_value_1",
                        "entities": [{
                            "confidence": "confidence_value_1_1",
                            "type": "type_value_1_1",
                            "key": "key_value_1_1",
                            "source": "detection"
                        }]
                    }]
                }
            })

        self.assertEqual(1, target.add_entity_to_context.call_count)
        self.assertEqual(['entity_value'],
                         target.add_entity_to_context.call_args_list[0][0][0])
        self.assertEqual('intent_value_1',
                         target.add_entity_to_context.call_args_list[0][0][1])
        self.assertEqual('confidence_value_1_1',
                         target.add_entity_to_context.call_args_list[0][0][2])
        self.assertEqual('type_value_1_1',
                         target.add_entity_to_context.call_args_list[0][0][3])
        self.assertEqual('key_value_1_1',
                         target.add_entity_to_context.call_args_list[0][0][4])

        self.assertEqual("context_entities_1", actual)
    def test_existing_exclude_entity(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        actual = target.add_entity_to_context(
            [
                {
                    "confidence": 80.0,
                    "entity_message_index": 1,
                    "negation_modifier": -100,
                    "key": "black",
                    "source": "detection",
                    "type": "color",
                    "type_weighting": 90.0,
                }
            ],
            "exclude",
            80.0,
            "color",
            "black",
        )

        self.assertEqual(
            [
                {
                    "confidence": 80.0,
                    "entity_message_index": 2,
                    "negation_modifier": -100,
                    "key": "black",
                    "source": "detection",
                    "type": "color",
                    "type_weighting": 99.00000000000001,
                }
            ],
            actual,
        )
    def test_regular(self):
        context_data = MagicMock()
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        target.add_entity_to_context = MagicMock(side_effect=(["context_entities_1"]))

        actual = target.update_entities_with_last_message(
            ["entity_value"],
            {
                "detection": {
                    "outcomes": [
                        {
                            "intent": "intent_value_1",
                            "entities": [
                                {
                                    "confidence": "confidence_value_1_1",
                                    "type": "type_value_1_1",
                                    "key": "key_value_1_1",
                                    "source": "detection",
                                }
                            ],
                        }
                    ]
                }
            },
        )

        self.assertEqual(1, target.add_entity_to_context.call_count)
        self.assertEqual(["entity_value"], target.add_entity_to_context.call_args_list[0][0][0])
        self.assertEqual("intent_value_1", target.add_entity_to_context.call_args_list[0][0][1])
        self.assertEqual("confidence_value_1_1", target.add_entity_to_context.call_args_list[0][0][2])
        self.assertEqual("type_value_1_1", target.add_entity_to_context.call_args_list[0][0][3])
        self.assertEqual("key_value_1_1", target.add_entity_to_context.call_args_list[0][0][4])

        self.assertEqual("context_entities_1", actual)