Exemple #1
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        emotion = Emotion.neutral
        confidence = 0.05
        parsed = str(statement)
        if 'not' in parsed:
            # if you are not, who then is?
            suffix = " either. "
            prefix = ""
            emotion = Emotion.wink
            confidence *= 2
        else:
            interrogation = False
            token = spac_token(statement, chatbot=self.chatbot)
            for i in token:
                # checks if the statement contains any sequence of interrogative type of words
                if i.tag_ == '.' and i.text == '?':
                    interrogation = True
                if str(i.tag_).startswith('W'):
                    interrogation = True

            if interrogation:
                prefix, suffix = '', ''
                confidence *= 2
                parsed = random_response(FUN_ASK_QUESTION).format(
                    ' '.join(reverse(word_tokenize(
                        str(statement)))))  # This seems complex.
                # The tokenized input statement is reversed using the reverse unction
                # Reverse in this sense means switching first person and second person nouns
                # The returned list of tokens are then converted into a string by joining each element
                # to a whitespace making a sentence, which is then converted to lower case
                # for the visibility sake
            else:
                prefix, suffix = random_response(FUN_LET_ME_TRY)
                suffix = "' {}".format(
                    suffix.format(random_response(EMOJI_SMILE)))
                prefix = "{} '".format(prefix)
                emotion = Emotion.wink

        selected_statement = SugaroidStatement("{pre}{main}{fix}".format(
            pre=prefix, main=parsed, fix=suffix),
                                               chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        return selected_statement
Exemple #2
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        # parsed = str(statement).lower().strip()
        raw_statement = str(statement)
        parsed = tokenize(str(statement))
        emotion = Emotion.neutral
        a = self.sia.polarity_scores(raw_statement)
        response = ":)"
        confidence = a['pos'] + a['neg']
        if (('love' in parsed) or
            ('hate' in parsed)) and (('you' in parsed) or
                                     ('myself' in parsed)):
            if a['pos'] > a['neg']:
                response = "I love you too"
                emotion = Emotion.blush
            else:
                response = "But still, I love you"
                emotion = Emotion.lol
        else:
            if a['pos'] > a['neg']:
                if 'you' in parsed:
                    response = GRATIFY[randint(0, len(GRATIFY) - 1)]
                    emotion = Emotion.blush
                else:
                    if 'stop' in parsed:
                        if ('dont' in parsed) or ('do' in parsed and 'not'
                                                  in parsed) or ('don\'t'
                                                                 in parsed):
                            response = 'I am here to continue my adventure forever'
                            emotion = Emotion.positive
                        else:
                            # optimize series of or statement
                            if \
                                    ('fun' in parsed) or \
                                    ('repeat' in parsed) or \
                                    ('imitation' in parsed) or \
                                    ('repetition' in parsed) or \
                                    ('irritate' in parsed) or \
                                    ('irritation' in parsed):
                                response = "Ok! I will switch off my fun mode for sometime"
                                emotion = Emotion.neutral
                                self.chatbot.globals['fun'] = False
                            else:
                                response = "I am depressed. Is there anything which I hurt you? I apologize for that"
                                emotion = Emotion.depressed
                    else:
                        if any_in(APPRECIATION, parsed):
                            response = random_response(GRATIFY)
                            emotion = Emotion.angel
                            confidence = 0.8
                        else:
                            # FIXME : Make it more smart
                            response = random_response(SIT_AND_SMILE)
                            emotion = Emotion.lol
                            if confidence > 0.8:
                                confidence -= 0.2
            else:
                if 'i' in parsed:
                    response = "Its ok,  {}.".format(CONSOLATION[randint(
                        0,
                        len(CONSOLATION) - 1)])
                    emotion = Emotion.positive
                else:
                    # well, I don't want to say ( I don't know )
                    # FIXME : Use a better algorithm to detect sentences
                    reversed = reverse(parsed)
                    response = 'Why do you think {}?'.format(
                        ' '.join(reversed))
                    emotion = Emotion.dead

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        return selected_statement
Exemple #3
0
    def process(
        self,
        statement: SugaroidStatement,
        additional_response_selection_parameters=None,
    ):
        # parsed = str(statement).lower().strip()
        raw_statement = str(statement)

        polarity = self.sia.polarity_scores(statement.text)

        confidence = polarity["pos"] + polarity["neg"]
        if (("love" in statement.words) or
            ("hate" in statement.words)) and (("you" in statement.words) or
                                              ("myself" in statement.words)):
            if polarity["pos"] >= polarity["neg"]:
                response = "I love you too"
                emotion = Emotion.blush
            else:
                response = "But still, I love you"
                emotion = Emotion.lol
        else:
            if polarity["pos"] > polarity["neg"]:
                if "you" in statement.words:
                    if "thank" in statement.words:
                        # this is a positive statement
                        # but we are expecting something like 'You're welcome' here
                        response = random_response(WELCOME)
                    else:
                        response = random_response(GRATIFY)
                    emotion = Emotion.blush
                else:
                    if "stop" in statement.words:
                        if (("dont" in statement.words)
                                or ("do" in statement.words
                                    and "not" in statement.words)
                                or ("don't" in statement.words)):
                            response = "I am here to continue my adventure forever"
                            emotion = Emotion.positive
                        else:
                            # optimize series of or statement
                            if (("fun" in statement.words)
                                    or ("repeat" in statement.words)
                                    or ("imitation" in statement.words)
                                    or ("repetition" in statement.words)
                                    or ("irritate" in statement.words)
                                    or ("irritation" in statement.words)):
                                response = (
                                    "Ok! I will switch off my fun mode for sometime"
                                )
                                emotion = Emotion.neutral
                                self.chatbot.globals["fun"] = False
                            else:
                                response = "I am depressed. Is there anything which I hurt you? I apologize for that"
                                emotion = Emotion.depressed
                    else:
                        if any_in(APPRECIATION, statement.words):
                            response = random_response(GRATIFY)
                            emotion = Emotion.angel
                            confidence = 0.8
                        else:
                            if ("thank" in statement.words
                                    or "thanks" in statement.words):
                                response, emotion = handle_thanks(statement)
                            else:
                                # FIXME : Make it more smart
                                response = random_response(SIT_AND_SMILE)
                                emotion = Emotion.lol
                            if confidence > 0.8:
                                confidence -= 0.2
            else:
                if "i" in statement.words:
                    response, emotion = handle_give_consolation(statement)
                elif "dead" in statement.words:
                    response, emotion = handle_dead_statements(statement)
                else:

                    # well, I don't want to say ( I don't know )
                    # FIXME : Use a better algorithm to detect sentences
                    reversed_response = reverse(statement.words)
                    response = "Why do you think {}?".format(
                        " ".join(reversed_response))
                    emotion = Emotion.dead

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.set_emotion(emotion)
        selected_statement.set_confidence(confidence)
        return selected_statement
Exemple #4
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        # parsed = str(statement).lower().strip()
        raw_statement = str(statement)
        parsed = tokenize(str(statement))
        emotion = Emotion.neutral
        a = self.sia.polarity_scores(raw_statement)
        response = ":)"
        confidence = a["pos"] + a["neg"]
        if (("love" in parsed) or
            ("hate" in parsed)) and (("you" in parsed) or
                                     ("myself" in parsed)):
            if a["pos"] >= a["neg"]:
                response = "I love you too"
                emotion = Emotion.blush
            else:
                response = "But still, I love you"
                emotion = Emotion.lol
        else:
            if a["pos"] > a["neg"]:
                if "you" in parsed:
                    response = GRATIFY[randint(0, len(GRATIFY) - 1)]
                    emotion = Emotion.blush
                else:
                    if "stop" in parsed:
                        if (("dont" in parsed)
                                or ("do" in parsed and "not" in parsed)
                                or ("don't" in parsed)):
                            response = "I am here to continue my adventure forever"
                            emotion = Emotion.positive
                        else:
                            # optimize series of or statement
                            if (("fun" in parsed) or ("repeat" in parsed)
                                    or ("imitation" in parsed)
                                    or ("repetition" in parsed)
                                    or ("irritate" in parsed)
                                    or ("irritation" in parsed)):
                                response = (
                                    "Ok! I will switch off my fun mode for sometime"
                                )
                                emotion = Emotion.neutral
                                self.chatbot.globals["fun"] = False
                            else:
                                response = "I am depressed. Is there anything which I hurt you? I apologize for that"
                                emotion = Emotion.depressed
                    else:
                        if any_in(APPRECIATION, parsed):
                            response = random_response(GRATIFY)
                            emotion = Emotion.angel
                            confidence = 0.8
                        else:
                            # FIXME : Make it more smart
                            response = random_response(SIT_AND_SMILE)
                            emotion = Emotion.lol
                            if confidence > 0.8:
                                confidence -= 0.2
            else:
                if "i" in parsed:
                    response = "Its ok,  {}.".format(CONSOLATION[randint(
                        0,
                        len(CONSOLATION) - 1)])
                    emotion = Emotion.positive
                elif "dead" in parsed:
                    if "everyone" in parsed or "every" in parsed:
                        if ("except" in parsed
                                or "apart" in parsed) and "me" in parsed:
                            response = (
                                "So sad. Its a great feeling that only"
                                " me and you are the only person alive "
                                "on the face of this world.")
                        else:
                            response = "So, am I speaking to you in heaven?"
                        emotion = Emotion.dead
                    else:
                        responses = (
                            "I hope you are not dead too. I am sorry.",
                            "My 💐 for them",
                            "My condolences...",
                            "So sad. I want to cry 😭",
                            "At least you are there for me!",
                        )
                        response = random_response(responses)
                        emotion = Emotion.lol
                else:

                    # well, I don't want to say ( I don't know )
                    # FIXME : Use a better algorithm to detect sentences
                    reversed = reverse(parsed)
                    response = "Why do you think {}?".format(
                        " ".join(reversed))
                    emotion = Emotion.dead

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        return selected_statement