Пример #1
0
    def add_pattern_to_graph(self, pattern_element, topic_element, that_element, template_graph_root, learn=False, userid="*"):

        pattern_node = self.add_pattern_to_node(pattern_element, userid=userid)

        topic_node = self.add_topic_to_node(topic_element, pattern_node, userid=userid)

        that_node = self.add_that_to_node(that_element, topic_node, userid=userid)

        if that_node.has_template() is True:
            if learn is False:
                if type(pattern_node) is PatternNluNode:
                    excep_msg = "Duplicate grammar tree found [intent=%s, %s=%s]" % (pattern_node.intent, pattern_node.scoreName(), pattern_node.score)
                elif pattern_element.text is not None:
                    excep_msg = "Duplicate grammar tree found [%s]" % (pattern_element.text.strip())
                else:
                    excep_msg = "Duplicate grammar tree found for [TAG defined]"
                duplicate_excep = DuplicateGrammarException(excep_msg)
                duplicate_excep.xml_element = pattern_element
                raise duplicate_excep
            else:
                if pattern_element.text is not None:
                    YLogger.warning(self, "Duplicate grammar tree found [%s] in learn, replacing existing",
                                    pattern_element.text.strip())
                else:
                    YLogger.warning(self, "Duplicate grammar tree found for bot/set in learn, replacing existing")

                pattern_template_node = self.add_template_to_node(template_graph_root, that_node)
        else:
            pattern_template_node = self.add_template_to_node(template_graph_root, that_node)

        return pattern_template_node
Пример #2
0
 def test_duplicate_grammar_exception_via_sets(self):
     element = ET.fromstring("<template />")
     xml_exception = ET.ParseError()
     xml_exception.position = []
     xml_exception.position.append(1)
     xml_exception.position.append(2)
     exception = DuplicateGrammarException("message", filename="test.xml")
     exception.xml_exception = xml_exception
     self.assertEqual(xml_exception, exception.xml_exception)
     exception.xml_element = element
     self.assertEqual(element, exception.xml_element)
     self.assertEqual("message", exception.message)
     self.assertEqual("test.xml", exception.filename)
     self.assertEqual(xml_exception, exception.xml_exception)
     self.assertEqual(element, exception._xml_element)
     self.assertEqual("message in [test.xml] at [line(1), column(2)]", exception.format_message())