Example #1
0
 def test_equals_match(self):
     equals_match = EqualsMatch(True, 1, "Hello World")
     self.assertIsNotNone(equals_match)
     self.assertTrue(equals_match.matched)
     self.assertEquals(1, equals_match.word_no)
     self.assertEquals("Hello World", equals_match.matched_phrase)
     self.assertEquals("True, 1, Hello World", equals_match.to_string())
Example #2
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)
            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.error(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)
Example #3
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)

        last_index = words.words.index("__TOPIC__")
        sentence = words.words[:last_index]
        if sentence:
            concepts = self._concept_name.split("|")
            this_concept = concepts[
                0]  # this is the main concept we have to compare others to
            other_concepts = concepts[
                1:]  # this is other concepts we have to compare this_concept to

            sentence_text = " ".join(sentence)

            similarity_with_this_concept = client_context.brain.nlp.semantic_similarity.similarity_with_concept(
                sentence_text, this_concept)
            similarity_with_other_concepts = client_context.brain.nlp.semantic_similarity.similarity_with_concepts(
                sentence_text, other_concepts)

            if similarity_with_this_concept > max(
                    similarity_with_other_concepts):
                result = True
            else:
                result = False
            word_no = word_no + len(sentence) - 1
        else:
            result = True

        return EqualsMatch(result, word_no, word)
Example #4
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)
Example #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)

        if self.priority_word == word:
            return EqualsMatch(True, word_no, word)

        return EqualsMatch(False, word_no)
Example #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):
                if DEBUG:
                    YLogger.debug(client_context,
                                  "Found word [%s] as bot property", word)
                return EqualsMatch(True, word_no, word)

        return EqualsMatch(False, word_no)
Example #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)
Example #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[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)
Example #9
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 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)
Example #10
0
 def equals(self, client_context, words, word_no):
     return EqualsMatch(False, word_no)