Ejemplo n.º 1
0
    def test_nluslot_with_index_over(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateNluSlotNode()
        node._slotName = TemplateWordNode("*")
        node._itemName = TemplateWordNode("entity")
        node._index = TemplateWordNode("2")
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())
        nlu_result = '{"intents": [], "slots": [{"slot": "nlu_slot", "entity": "value1"}, {"slot": "nlu_slot", "entity": "value2"}]}'
        conversation.current_question().set_property("__SYSTEM_NLUDATA__",
                                                     nlu_result)

        result = root.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)
Ejemplo n.º 2
0
    def test_nluslot_no_nlu_result(self):
        root = TemplateNode()
        node = TemplateNluSlotNode()
        node._slotName = TemplateWordNode("nlu_slot")
        node._itemName = TemplateWordNode("startOffset")
        root.append(node)

        result = root.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("", result)
Ejemplo n.º 3
0
    def test_to_xml_nluslot(self):
        root = TemplateNode()
        node = TemplateNluSlotNode()
        node._slotName = TemplateWordNode("nlu_slot")
        node._itemName = TemplateWordNode("entity")
        root.append(node)

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual(
            '<template><nluslot><name>nlu_slot</name><item>entity</item></nluslot></template>',
            xml_str)
Ejemplo n.º 4
0
    def test_nluslot_no_item(self):
        root = TemplateNode()
        node = TemplateNluSlotNode()
        node._slotName = TemplateWordNode("nlu_slot")
        node._itemName = TemplateWordNode("startOffset")
        root.append(node)

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        nlu_result = '{"intents": [], "slots": [{"slot": "nlu_slot", "entity": "value"}]}'
        conversation.current_question().set_property("__SYSTEM_NLUDATA__",
                                                     nlu_result)

        result = root.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)