コード例 #1
0
    def test_generate_utterance(self):
        # Given
        context = {
            "data": [
                {
                    "text": "this is ",
                },
                {
                    "text": "entity 11",
                    "entity": "entity1",
                    "slot_name": "slot1"
                },
                {
                    "text": " right "
                },
                {
                    "text": "entity 2",
                    "entity": "entity2",
                    "slot_name": "slot1"
                }
            ]
        }
        context_iterator = (context for _ in range(1))

        entities_iterators = {
            "entity1": ("entity one" for _ in range(1)),
            "entity2": ("entity two" for _ in range(1)),
        }

        # When
        utterance = generate_utterance(context_iterator, entities_iterators)

        # Then
        expected_utterance = {
            "data": [
                {
                    "text": "this is ",
                },
                {
                    "text": "entity one ",
                    "entity": "entity1",
                    "slot_name": "slot1"
                },
                {
                    "text": "right "
                },
                {
                    "text": "entity two ",
                    "entity": "entity2",
                    "slot_name": "slot1"
                }
            ]
        }
        self.assertEqual(expected_utterance, utterance)
コード例 #2
0
    def test_generate_utterance(self):
        # Given
        context = {
            "data": [{
                "text": "this is ",
            }, {
                "text": "entity 11",
                "entity": "entity1",
                "slot_name": "slot1"
            }, {
                "text": " right "
            }, {
                "text": "entity 2",
                "entity": "entity2",
                "slot_name": "slot1"
            }]
        }
        context_iterator = (context for _ in range(1))

        entities_iterators = {
            "entity1": ("entity one" for _ in range(1)),
            "entity2": ("entity two" for _ in range(1)),
        }

        # When
        utterance = generate_utterance(context_iterator, entities_iterators)

        # Then
        expected_utterance = {
            "data": [{
                "text": "this is ",
            }, {
                "text": "entity one ",
                "entity": "entity1",
                "slot_name": "slot1"
            }, {
                "text": "right "
            }, {
                "text": "entity two ",
                "entity": "entity2",
                "slot_name": "slot1"
            }]
        }
        self.assertEqual(expected_utterance, utterance)