Esempio n. 1
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)

        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        if client_context.brain.dynamics.is_dynamic_set(
                self._set_name) is True:
            result = client_context.brain.dynamics.dynamic_set(
                client_context, self._set_name, word, self._additional)
            return EqualsMatch(result, word_no, word)

        else:
            if self.set_is_known(client_context):
                match = self.words_in_set(client_context, words, word_no)
                if match.matched is True:
                    YLogger.debug(client_context,
                                  "Found word [%s] in set [%s]", word,
                                  self.set_name)
                    return match

                else:
                    YLogger.debug(client_context,
                                  "No word [%s] found in set [%s]", word,
                                  self.set_name)
                    return EqualsMatch(False, word_no)

            else:
                YLogger.error(client_context,
                              "No set named [%s] in sets collection",
                              self.set_name)
                return EqualsMatch(False, word_no)
Esempio n. 2
0
    def words_in_set(self, client_context, words, word_no):

        word = words.word(word_no).upper()
        set_words = client_context.brain.sets.set(self.set_name)
        if not set_words:
            YLogger.error(self, "No set with name [%s]", self.set_name)

        elif word in set_words:
            phrases = set_words[word]
            phrases = sorted(phrases, key=len, reverse=True)
            for phrase in phrases:
                phrase_word_no = 0
                words_word_no = word_no
                while phrase_word_no < len(
                        phrase) and words_word_no < words.num_words():
                    phrase_word = phrase[phrase_word_no].upper()
                    word = words.word(words_word_no).upper()
                    if phrase_word == word:
                        if phrase_word_no + 1 == len(phrase):
                            return EqualsMatch(True, words_word_no,
                                               " ".join(phrase))
                    phrase_word_no += 1
                    words_word_no += 1

        return EqualsMatch(False, word_no)
Esempio n. 3
0
 def test_equals_match(self):
     equals_match = EqualsMatch(True, 1, "Hello World")
     self.assertIsNotNone(equals_match)
     self.assertTrue(equals_match.matched)
     self.assertEqual(1, equals_match.word_no)
     self.assertEqual("Hello World", equals_match.matched_phrase)
     self.assertEqual("True, 1, Hello World", equals_match.to_string())
Esempio n. 4
0
 def test_equals_match_no_match_phrase(self):
     equals_match = EqualsMatch(False, 3)
     self.assertIsNotNone(equals_match)
     self.assertFalse(equals_match.matched)
     self.assertEqual(3, equals_match.word_no)
     self.assertEqual(None, equals_match.matched_phrase)
     self.assertEqual("False, 3, ''", equals_match.to_string())
Esempio n. 5
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)
        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        return EqualsMatch(self.equals_ignore_case(self._word, word), word_no,
                           word)
Esempio n. 6
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)

        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        if client_context.brain.properties.has_property(self.property):
            if word == client_context.brain.properties.property(self.property):
                YLogger.debug(client_context,
                              "Found word [%s] as bot property", word)
                return EqualsMatch(True, word_no, word)

        return EqualsMatch(False, word_no)
Esempio n. 7
0
    def equals(self, client_context, words, word_no):
        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        word = words.word(word_no)
        if word is not None:
            word = word.upper()
            for set_word in self._words:
                if word == set_word:
                    YLogger.debug(client_context, "Found word [%s] in iset",
                                  word)
                    return EqualsMatch(True, word_no, word)

        YLogger.error(client_context, "No word [%s] found in iset", word)
        return EqualsMatch(False, word_no)
Esempio n. 8
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)

        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        if self._pattern_template is not None:
            template = client_context.brain.regex_templates.regex(
                self._pattern_template)
            if template is not None:
                result = template.match(word)
                if result is not None:
                    YLogger.debug(client_context, "Match word [%s] regex",
                                  word)
                    return EqualsMatch(True, word_no, word)
                else:
                    YLogger.error(client_context, "No word [%s] matched regex",
                                  word)
                    return EqualsMatch(False, word_no)
            else:
                return EqualsMatch(False, word_no)
        else:
            result = self.pattern.match(word)
            if result is not None:
                YLogger.debug(client_context, "Match word [%s] regex", word)
                return EqualsMatch(True, word_no, word)
            else:
                YLogger.error(client_context, "No word [%s] matched regex",
                              word)
                return EqualsMatch(False, word_no)
Esempio n. 9
0
 def equals(self, client_context, words, word_no):
     return EqualsMatch(False, word_no)