def match_sentence(self, client_context, pattern_sentence, topic_pattern, that_pattern): topic_sentence = Sentence(client_context, topic_pattern) that_sentence = Sentence(client_context, that_pattern) YLogger.debug(client_context, "AIML Parser matching sentence [%s], topic=[%s], that=[%s] ", pattern_sentence.text(client_context), topic_pattern, that_pattern) sentence = Sentence(client_context) sentence.append_sentence(pattern_sentence) sentence.append_word('__TOPIC__') sentence.append_sentence(topic_sentence) sentence.append_word('__THAT__') sentence.append_sentence(that_sentence) YLogger.debug(client_context, "Matching [%s]", sentence.words_from_current_pos(client_context, 0)) context = MatchContext(max_search_depth=client_context.bot.configuration.max_search_depth, max_search_timeout=client_context.bot.configuration.max_search_timeout) template = self._pattern_parser.root.match(client_context, context, sentence) if template is not None: context.template_node = template context.list_matches(client_context) # Save the matched context for the associated sentence pattern_sentence.matched_context = context return context return None
def test_match_context_depth(self): context = MatchContext(max_search_depth=100, max_search_timeout=60) self.assertEqual(100, context.max_search_depth) self.assertEqual(60, context.max_search_timeout) self.assertFalse(context.matched()) template = PatternTemplateNode(template=TemplateNode()) context.template_node = template self.assertIsNotNone(context.template_node) self.assertTrue(context.matched())