Ejemplo n.º 1
0
    def test_entities_iterators(self, _):
        # Given
        intent_entities = {
            "entity1": {
                "utterances": {
                    "entity 1": "entity 1",
                    "entity 11": "entity 11",
                    "entity 111": "entity 111",
                }
            },
            "entity2": {
                "utterances": {
                    "entity 2": "entity 2",
                    "entity 22": "entity 22",
                    "entity 222": "entity 222",
                }
            }
        }
        random_state = np.random.RandomState(1)

        # Then
        it_dict = get_entities_iterators(intent_entities, random_state)

        # When
        self.assertIn("entity1", it_dict)
        expected_seq = ["entity 1", "entity 11", "entity 111"]
        seq = [next(it_dict["entity1"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))

        self.assertIn("entity2", it_dict)
        expected_seq = ["entity 2", "entity 22", "entity 222"]
        seq = [next(it_dict["entity2"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))
Ejemplo n.º 2
0
    def test_entities_iterators(self, _):
        # Given
        intent_entities = {
            "entity1": {
                "utterances": {
                    "entity 1": "entity 1",
                    "entity 11": "entity 11",
                    "entity 111": "entity 111",
                }
            },
            "entity2": {
                "utterances": {
                    "entity 2": "entity 2",
                    "entity 22": "entity 22",
                    "entity 222": "entity 222",
                }
            }
        }
        random_state = np.random.RandomState(1)

        # Then
        it_dict = get_entities_iterators(intent_entities, random_state)

        # When
        self.assertIn("entity1", it_dict)
        expected_seq = ["entity 1", "entity 11", "entity 111"]
        seq = [next(it_dict["entity1"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))

        self.assertIn("entity2", it_dict)
        expected_seq = ["entity 2", "entity 22", "entity 222"]
        seq = [next(it_dict["entity2"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))
    def test_entities_iterators_with_builtin_examples(self, _,
                                                      mocked_builtin_entity_examples):
        # Given
        language = "en"

        def mock_builtin_entity_examples(builtin_entity_kind, language):
            if builtin_entity_kind == "snips/number":
                return ["2007", "two hundreds and six"]
            else:
                return []

        mocked_builtin_entity_examples.side_effect = \
            mock_builtin_entity_examples

        intent_entities = {
            "entity1": {
                "utterances": {
                    "entity 1": "entity 1",
                    "entity 11": "entity 11",
                    "entity 111": "entity 111",
                }
            },
            "snips/number": {
                "utterances": {"9", "seventy"}
            }
        }
        random_state = np.random.RandomState(1)

        # Then
        add_builtin_entities_examples = True
        it_dict = get_entities_iterators(intent_entities, language,
                                         add_builtin_entities_examples,
                                         random_state)

        # When
        self.assertIn("entity1", it_dict)
        expected_seq = ["entity 1", "entity 11", "entity 111"]
        seq = [next(it_dict["entity1"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))

        self.assertIn("snips/number", it_dict)
        # Check that entity examples are at the beginning of the iterator
        expected_seq_start = ["2007", "two hundreds and six"]
        seq_start = [next(it_dict["snips/number"]) for _ in range(2)]
        self.assertListEqual(expected_seq_start, seq_start)

        expected_seq_end = ["9", "seventy"]
        seq_end = [next(it_dict["snips/number"]) for _ in range(2)]
        self.assertListEqual(expected_seq_end, sorted(seq_end))
Ejemplo n.º 4
0
    def test_entities_iterators_with_builtin_examples(
            self, _, mocked_builtin_entity_examples):
        # Given
        language = "en"

        def mock_builtin_entity_examples(builtin_entity_kind, language):
            if builtin_entity_kind == "snips/number":
                return ["2007", "two hundreds and six"]
            else:
                return []

        mocked_builtin_entity_examples.side_effect = \
            mock_builtin_entity_examples

        intent_entities = {
            "entity1": {
                "utterances": {
                    "entity 1": "entity 1",
                    "entity 11": "entity 11",
                    "entity 111": "entity 111",
                }
            },
            "snips/number": {
                "utterances": {"9", "seventy"}
            }
        }
        random_state = np.random.RandomState(1)

        # Then
        add_builtin_entities_examples = True
        it_dict = get_entities_iterators(intent_entities, language,
                                         add_builtin_entities_examples,
                                         random_state)

        # When
        self.assertIn("entity1", it_dict)
        expected_seq = ["entity 1", "entity 11", "entity 111"]
        seq = [next(it_dict["entity1"]) for _ in range(len(expected_seq))]
        self.assertListEqual(expected_seq, sorted(seq))

        self.assertIn("snips/number", it_dict)
        # Check that entity examples are at the beginning of the iterator
        expected_seq_start = ["2007", "two hundreds and six"]
        seq_start = [next(it_dict["snips/number"]) for _ in range(2)]
        self.assertListEqual(expected_seq_start, seq_start)

        expected_seq_end = ["9", "seventy"]
        seq_end = [next(it_dict["snips/number"]) for _ in range(2)]
        self.assertListEqual(expected_seq_end, sorted(seq_end))