示例#1
0
    def test_add_that_to_node_pattern_with_set(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)

        base_node = PatternWordNode("THAT_TEST")

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

        end_node = graph.add_that_to_node(that_element, base_node)
        self.assertIsNotNone(end_node)

        self.assertIsNotNone(base_node)
        self.assertIsNotNone(base_node.that)
        self.assertIsInstance(base_node.that, PatternThatNode)

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

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

        self.assertTrue(base_node.that.children[0].children[0].has_children())
        self.assertIsInstance(
            base_node.that.children[0].children[0].children[0],
            PatternWordNode)
        self.assertEqual(
            base_node.that.children[0].children[0].children[0].word, "WORLD")
示例#2
0
    def test_add_that_to_node_word(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)
        pattern = ET.fromstring("""
        <pattern>
            HELLO
        </pattern>""")
        pattern_node = graph.add_pattern_to_node(pattern)

        topic = ET.fromstring("""
        <topic>
            THERE
        </topic>""")
        topic_node = graph.add_that_to_node(topic, pattern_node)

        that = ET.fromstring("""
        <that>
            *
        </that>""")
        that_node = graph.add_that_to_node(that, topic_node)
        self.assertIsNotNone(that_node)
        self.assertIsInstance(that_node, PatternOneOrMoreWildCardNode)
        self.assertEqual(that_node.wildcard, "*")
示例#3
0
    def test_add_template_to_node(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)
        pattern = ET.fromstring("""
        <pattern>
            HELLO
        </pattern>""")
        pattern_node = graph.add_pattern_to_node(pattern)

        topic = ET.fromstring("""
        <topic>
            THERE
        </topic>""")
        topic_node = graph.add_that_to_node(topic, pattern_node)

        that = ET.fromstring("""
        <that>
            *
        </that>""")
        that_node = graph.add_that_to_node(that, topic_node)

        template = TemplateWordNode("TEST")
        template_node = graph.add_template_to_node(template, that_node)
        self.assertIsNotNone(template_node)
        self.assertIsInstance(template_node, PatternTemplateNode)
示例#4
0
    def test_add_that_to_node_star(self):
        graph = PatternGraph(self._client_context.brain.aiml_parser)

        base_node = PatternWordNode("THAT_TEST")

        that_element = ET.fromstring('<that>*</that>')

        end_node = graph.add_that_to_node(that_element, base_node)
        self.assertIsNotNone(end_node)

        self.assertIsNotNone(base_node)
        self.assertIsNotNone(base_node.that)
        self.assertIsInstance(base_node.that, PatternThatNode)

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