Beispiel #1
0
    def test_add_topic_to_node_pattern_with_set(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)

        base_node = PatternWordNode("TOPIC_TEST")

        topic_element = ET.fromstring(
            '<topic>HELLO <set name="test" /> WORLD</topic>')

        end_node = graph.add_topic_to_node(topic_element, base_node)
        self.assertIsNotNone(end_node)

        self.assertIsNotNone(base_node)
        self.assertIsNotNone(base_node.topic)
        self.assertIsInstance(base_node.topic, PatternTopicNode)

        self.assertTrue(base_node.topic.has_children())
        self.assertIsInstance(base_node.topic.children[0], PatternWordNode)
        self.assertEqual(base_node.topic.children[0].word, "HELLO")

        self.assertTrue(base_node.topic.children[0].has_children())
        self.assertIsInstance(base_node.topic.children[0].children[0],
                              PatternSetNode)
        self.assertEqual(base_node.topic.children[0].children[0].set_name,
                         "TEST")

        self.assertTrue(base_node.topic.children[0].children[0].has_children())
        self.assertIsInstance(
            base_node.topic.children[0].children[0].children[0],
            PatternWordNode)
        self.assertEqual(
            base_node.topic.children[0].children[0].children[0].word, "WORLD")
Beispiel #2
0
    def test_add_topic_to_node_star(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)

        base_node = PatternWordNode("TOPIC_TEST")

        topic_element = ET.fromstring('<topic>*</topic>')

        end_node = graph.add_topic_to_node(topic_element, base_node)
        self.assertIsNotNone(end_node)

        self.assertIsNotNone(base_node)
        self.assertIsNotNone(base_node.topic)
        self.assertIsInstance(base_node.topic, PatternTopicNode)

        self.assertFalse(base_node.topic.has_children())
        self.assertTrue(base_node.topic.has_wildcard())
        self.assertIsNotNone(base_node.topic.star)
        self.assertEqual(base_node.topic.star.wildcard, "*")