本文整理汇总了Python中programy.parser.pattern.graph.PatternGraph.add_that_to_node方法的典型用法代码示例。如果您正苦于以下问题:Python PatternGraph.add_that_to_node方法的具体用法?Python PatternGraph.add_that_to_node怎么用?Python PatternGraph.add_that_to_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类programy.parser.pattern.graph.PatternGraph
的用法示例。
在下文中一共展示了PatternGraph.add_that_to_node方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_that_to_node_pattern_with_set
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_that_to_node_pattern_with_set(self):
graph = PatternGraph()
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].word, "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: test_add_that_to_node_word
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_that_to_node_word(self):
graph = PatternGraph()
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: test_add_that_to_node_word
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
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>
HERE
</that>""")
that_node = graph.add_that_to_node(that, topic_node)
self.assertIsNotNone(that_node)
self.assertIsInstance(that_node, PatternWordNode)
self.assertEqual(that_node.word, "HERE")
示例4: test_add_template_to_node
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_template_to_node(self):
graph = PatternGraph()
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)
示例5: test_add_topic_to_node_word
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_topic_to_node_word(self):
graph = PatternGraph()
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)
self.assertIsNotNone(topic_node)
self.assertIsInstance(topic_node, PatternWordNode)
self.assertEqual(topic_node.word, "THERE")
示例6: test_add_topic_to_node_wildcard
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_topic_to_node_wildcard(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>
*
</topic>""")
topic_node = graph.add_that_to_node(topic, pattern_node)
self.assertIsNotNone(topic_node)
self.assertIsInstance(topic_node, PatternOneOrMoreWildCardNode)
self.assertEqual(topic_node.wildcard, "*")
示例7: test_add_that_to_node_star
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_that_to_node_star(self):
graph = PatternGraph()
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, "*")
示例8: test_add_that_to_node_pattern
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_that_to_node [as 别名]
def test_add_that_to_node_pattern(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
base_node = PatternWordNode("THAT_TEST")
that_element = ET.fromstring('<that>HELLO 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], PatternWordNode)
self.assertEqual(base_node.that.children[0].children[0].word, "WORLD")