Example #1
0
    def parse_learn_expression(self, expression, branch):

        for child in expression:
            if child.tag == 'category':
                learn_node = TemplateLearnNode()

                parsed = self._aiml_parser.parse_category(child, add_to_graph=False)
                learn_node.pattern = parsed[0]
                learn_node.topic = parsed[1]
                learn_node.that = parsed[2]
                learn_node.template = parsed[3]

                branch.children.append(learn_node)
Example #2
0
    def test_to_xml(self):
        root = TemplateNode()
        learn = TemplateLearnNode()
        learn_cat = LearnCategory(ET.fromstring("<pattern>HELLO LEARN</pattern>"),
                                  ET.fromstring("<topic>*</topic>"),
                                  ET.fromstring("<that>*</that>"),
                                  TemplateWordNode("LEARN"))
        learn.append(learn_cat)
        root.append(learn)

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual("<template><learn><category><pattern>HELLO LEARN</pattern><topic>*</topic><that>*</that><template>LEARN</template></category></learn></template>", xml_str)
Example #3
0
    def test_to_xml(self):
        root = TemplateNode()
        learn = TemplateLearnNode()
        learn_cat = LearnCategory(ET.fromstring("<pattern>HELLO LEARN</pattern>"),
                                  ET.fromstring("<topic>*</topic>"),
                                  ET.fromstring("<that>*</that>"),
                                  TemplateWordNode("LEARN"))
        learn.append(learn_cat)
        root.append(learn)

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual("<template><learn><category><pattern>HELLO LEARN</pattern><topic>*</topic><that>*</that><template>LEARN</template></category></learn></template>", xml_str)
Example #4
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        learn = TemplateLearnNode()
        self.assertIsNotNone(learn)

        learn_cat = LearnCategory(ET.fromstring("<pattern>HELLO LEARN</pattern>"),
                                  ET.fromstring("<topic>*</topic>"),
                                  ET.fromstring("<that>*</that>"),
                                  TemplateWordNode("LEARN"))
        learn.append(learn_cat)

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

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertEqual("", resolved)
Example #5
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        learn = TemplateLearnNode()
        self.assertIsNotNone(learn)

        learn_cat = LearnCategory(
            ET.fromstring("<pattern>HELLO LEARN</pattern>"),
            ET.fromstring("<topic>*</topic>"), ET.fromstring("<that>*</that>"),
            TemplateWordNode("LEARN"))
        learn.append(learn_cat)

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

        resolved = root.resolve(self.bot, self.clientid)
        self.assertIsNotNone(resolved)
        self.assertEqual("", resolved)
Example #6
0
    def test_to_xml(self):
        root = TemplateNode()
        learn = TemplateLearnNode()
        learn._pattern = ET.fromstring("<pattern>HELLO LEARN</pattern>")
        learn._topic = ET.fromstring("<topic>*</topic>")
        learn._that = ET.fromstring("<that>*</that>")
        learn._template = TemplateWordNode("LEARN")
        root.append(learn)

        xml = root.xml_tree(self.bot, self.clientid)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual(
            "<template><learn><pattern>HELLO LEARN</pattern><topic>*</topic><that>*</that><template>LEARN</template></learn></template>",
            xml_str)
Example #7
0
 def __init__(self):
     TemplateLearnNode.__init__(self)
Example #8
0
 def __init__(self):
     TemplateLearnNode.__init__(self)