本文整理汇总了Python中programy.parser.pattern.graph.PatternGraph.add_pattern_to_graph方法的典型用法代码示例。如果您正苦于以下问题:Python PatternGraph.add_pattern_to_graph方法的具体用法?Python PatternGraph.add_pattern_to_graph怎么用?Python PatternGraph.add_pattern_to_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类programy.parser.pattern.graph.PatternGraph
的用法示例。
在下文中一共展示了PatternGraph.add_pattern_to_graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_pattern_with_whitepsace
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_with_whitepsace(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring("<pattern>\nthis\n that\n the other</pattern>")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
root = graph.root
self.assertIsNotNone(root)
self.assertIsNotNone(root.children)
self.assertEqual(len(root.children), 1)
self.assertIsInstance(root.children[0], PatternWordNode)
this = root.children[0]
self.assertIsNotNone(this)
self.assertEqual(this.word, "this")
self.assertEqual(len(this.children), 1)
that = this.children[0]
self.assertIsNotNone(that)
self.assertEqual(that.word, "that")
self.assertEqual(len(that.children), 1)
the = that.children[0]
self.assertIsNotNone(the)
self.assertEqual(the.word, "the")
self.assertEqual(len(the.children), 1)
other = the.children[0]
self.assertIsNotNone(other)
self.assertEqual(other.word, "other")
self.assertEqual(len(other.children), 0)
示例2: test_simple_hash_and_star_at_end
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_simple_hash_and_star_at_end(self):
graph = PatternGraph()
pattern_element = ET.fromstring("<pattern>A # *</pattern>")
topic_element = ET.fromstring("<topic>*</topic>")
that_element = ET.fromstring("<that>*</that>")
template_node = TemplateNode()
graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 1)
word_node = graph.root.children[0]
self.assertIsInstance(word_node, PatternWordNode)
self.assertEqual(word_node.word, "A")
self.assertTrue(word_node.has_zero_or_more())
if word_node.arrow is not None:
wildcard_node = word_node.arrow
elif word_node.hash is not None:
wildcard_node = word_node.hash
self.assertIsNotNone(wildcard_node)
self.assertTrue(wildcard_node.has_one_or_more())
if word_node.star is not None:
wildcard_node = word_node.star
elif word_node.underline is not None:
wildcard_node = word_node.underline
self.assertIsNotNone(wildcard_node)
示例3: test_add_pattern_to_graph_basic
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_basic(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring("<pattern>test1</pattern>")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 1)
self.assertIsInstance(graph.root.children[0], PatternWordNode)
self.assertEqual(graph.root.children[0].word, "test1")
element = ET.fromstring("<pattern>test2</pattern>")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 2)
self.assertIsInstance(graph.root.children[0], PatternWordNode)
self.assertEqual(graph.root.children[0].word, "test2")
self.assertIsInstance(graph.root.children[0], PatternWordNode)
self.assertEqual(graph.root.children[1].word, "test1")
示例4: test_duplicate_bot_and_word_otherwayround
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_duplicate_bot_and_word_otherwayround(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
pattern_element = ET.fromstring("<pattern><bot>A</bot></pattern>")
topic_element = ET.fromstring("<topic>*</topic>")
that_element = ET.fromstring("<that>*</that>")
template_node = TemplateNode()
graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
pattern_element = ET.fromstring("<pattern>A</pattern>")
topic_element = ET.fromstring("<topic>*</topic>")
that_element = ET.fromstring("<that>*</that>")
template_node = TemplateNode()
graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
self.assertIsNotNone(graph.root.children)
self.assertEqual(2, len(graph.root.children))
self.assertIsInstance(graph.root.children[0], PatternWordNode)
self.assertIsInstance(graph.root.children[1], PatternBotNode)
self.assertEqual(1, len(graph.root._bot_properties))
values = graph.root._bot_properties.values()
self.assertIsInstance(list(values)[0][0], PatternBotNode)
示例5: test_add_pattern_to_graph_one_or_more_last
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_one_or_more_last(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring('<pattern>XXX *</pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
示例6: test_add_pattern_to_graph_one_or_more_middle
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_one_or_more_middle(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring('<pattern>XXX * YYY</pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
示例7: test_add_pattern_to_graph_zero_or_more_multiple
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_zero_or_more_multiple(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring('<pattern>XXX # YYY # ZZZ</pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
示例8: test_add_pattern_to_graph_basic_zero_or_more_with_patterns
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_basic_zero_or_more_with_patterns(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
element = ET.fromstring('<pattern># HELLO</pattern>')
template_graph_root = TemplateWordNode("RESPONSE1")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
element = ET.fromstring('<pattern>WELL HI THERE</pattern>')
template_graph_root = TemplateWordNode("RESPONSE2")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
示例9: test_duplicates
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_duplicates(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
pattern1 = "<pattern>IS A</pattern>"
pattern2 = "<pattern>IS * <set>article</set> *</pattern>"
element1 = ET.fromstring(pattern1)
graph.add_pattern_to_graph(element1, topic_element, that_element, template_graph_root)
element2 = ET.fromstring(pattern2)
graph.add_pattern_to_graph(element2, topic_element, that_element, template_graph_root)
示例10: test_add_pattern_to_graph_basic_iset
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_basic_iset(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring('<pattern><iset>word1, word2, word3</iset> A VALUE</pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 1)
self.assertIsInstance(graph.root.children[0], PatternISetNode)
示例11: test_count_word_in_patterns
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_count_word_in_patterns(self):
graph = PatternGraph()
count = graph.count_words_in_patterns()
self.assertEquals(0, count)
graph = PatternGraph()
pattern = ET.fromstring("<pattern>HELLO</pattern>")
topic = ET.fromstring("<topic>HELLO</topic>")
that = ET.fromstring("<that>HELLO</that>")
template = TemplateWordNode("TEST")
graph.add_pattern_to_graph(pattern, topic, that, template)
count = graph.count_words_in_patterns()
self.assertEquals(1, count)
示例12: test_add_pattern_with_diff_topics_to_graph
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_with_diff_topics_to_graph(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
element = ET.fromstring("<pattern>test1</pattern>")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
topic_element = ET.fromstring('<topic>topic1</topic>')
that_element = ET.fromstring('<that>that1</that>')
template_graph_root = None
element = ET.fromstring("<pattern>test1</pattern>")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
示例13: test_add_pattern_to_graph
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph(self):
graph = PatternGraph()
pattern = ET.fromstring("<pattern>HELLO</pattern>")
topic = ET.fromstring("<topic>HELLO</topic>")
that = ET.fromstring("<that>HELLO</that>")
template = TemplateWordNode("TEST")
graph.add_pattern_to_graph(pattern, topic, that, template)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.child(0))
self.assertIsNotNone(graph.root.child(0).topic)
self.assertIsNotNone(graph.root.child(0).topic.child(0))
self.assertIsNotNone(graph.root.child(0).topic.child(0).that)
self.assertIsNotNone(graph.root.child(0).topic.child(0).that.child(0))
self.assertIsNotNone(graph.root.child(0).topic.child(0).that.child(0).template)
示例14: test_add_pattern_to_graph_basic_set_name_attrib
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_basic_set_name_attrib(self):
graph = PatternGraph()
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
self.bot.brain.sets._sets["SET1"] = ["val1", "val2", "val3", "val5"]
element = ET.fromstring('<pattern><set name="set1" /></pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 1)
self.assertIsInstance(graph.root.children[0], PatternSetNode)
self.assertEqual(graph.root.children[0].word, "SET1")
示例15: test_add_pattern_to_graph_basic_bot_text
# 需要导入模块: from programy.parser.pattern.graph import PatternGraph [as 别名]
# 或者: from programy.parser.pattern.graph.PatternGraph import add_pattern_to_graph [as 别名]
def test_add_pattern_to_graph_basic_bot_text(self):
graph = PatternGraph(self._client_context.brain.aiml_parser)
topic_element = ET.fromstring('<topic>*</topic>')
that_element = ET.fromstring('<that>*</that>')
template_graph_root = None
self._client_context.brain.properties.add_property('bot1', 'val1')
element = ET.fromstring('<pattern><bot>bot1</bot></pattern>')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
self.assertIsNotNone(graph.root)
self.assertIsNotNone(graph.root.children)
self.assertEqual(len(graph.root.children), 1)
self.assertIsInstance(graph.root.children[0], PatternBotNode)
self.assertEqual(graph.root.children[0].property, "bot1")