コード例 #1
0
    def test_list_matches_no_template(self):
        global total_str

        topic = PatternOneOrMoreWildCardNode("*")
        word1 = PatternWordNode("Hi")
        word2 = PatternWordNode("There")
        context = MatchContext(max_search_depth=100,
                               max_search_timeout=60,
                               template_node=PatternTemplateNode(
                                   TemplateWordNode("Hello")),
                               sentence="HELLO",
                               response="Hi there")
        context.add_match(Match(Match.TOPIC, topic, None))
        context.add_match(Match(Match.WORD, word1, "Hi"))
        context.add_match(Match(Match.WORD, word2, "There"))

        total_str = ""
        context.list_matches(self._client_context,
                             output_func=collector,
                             include_template=False)
        self.assertEquals(
            "\tMatches...	Asked: HELLO		1: Match=(Topic) Node=(ONEORMORE [*]) Matched=()		"
            "2: Match=(Word) Node=(WORD [Hi]) Matched=(Hi)		"
            "3: Match=(Word) Node=(WORD [There]) Matched=(There)	"
            "Match score 100.00", total_str)
コード例 #2
0
    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
コード例 #3
0
    def test_list_matches_empty(self):
        global total_str

        context = MatchContext(max_search_depth=100,
                               max_search_timeout=60,
                               matched_nodes=[])

        total_str = ""
        context.list_matches(self._client_context, output_func=collector)
        self.assertEquals("\tMatches...\tMatch score 0.00\t\tResponse: None",
                          total_str)