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