def test_nluintent_with_index_over(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateNluIntentNode() node._intentName = TemplateWordNode("*") node._itemName = TemplateWordNode("score") 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": [{"intent": "nlu_intent", "score": 0.9}, {"intent": "nlu_intent", "score": 0.75}], "slots": []}' conversation.current_question().set_property("__SYSTEM_NLUDATA__", nlu_result) result = root.resolve(self._client_context) self.assertIsNotNone(result) self.assertEqual("unknown", result)
def test_nluintent_no_nlu_result(self): root = TemplateNode() node = TemplateNluIntentNode() node._intentName = TemplateWordNode("*") node._itemName = TemplateWordNode("score") root.append(node) result = root.resolve(self._client_context) self.assertIsNotNone(result) self.assertEqual("", result)
def test_to_xml_nluintent(self): root = TemplateNode() node = TemplateNluIntentNode() node._intentName = TemplateWordNode("nlu_intent") node._itemName = TemplateWordNode("score") 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><nluintent><name>nlu_intent</name><item>score</item></nluintent></template>', xml_str)
def test_nluintent_no_item(self): root = TemplateNode() node = TemplateNluIntentNode() node._intentName = TemplateWordNode("nlu_intent") node._itemName = TemplateWordNode("score") 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": [{"intent": "nlu_intent"}], "slots": []}' conversation.current_question().set_property("__SYSTEM_NLUDATA__", nlu_result) result = root.resolve(self._client_context) self.assertIsNotNone(result) self.assertEqual("unknown", result)
def __init__(self): TemplateNluIntentNode.__init__(self)