Esempio n. 1
0
    def process(self, statement, additional_response_selection_parameters=None):
        confidence = 0
        dis_word = False
        if any_in(['distinguish', 'disfigure', 'distinct', 'distinction', 'distant',
                   'distance', 'distribution', 'distilled'], self.normalized):
            confidence = 0
        else:
            logging.info(
                "DisAdapter: Starting Advanced scan. dis_word == {}".format(self.dis)[0])
            dis_word = self.dis[3:]
            logging.info("DisAdapter: Distilled word == {}".format(dis_word))
            sia = SentimentIntensityAnalyzer().polarity_scores(dis_word)
            if dis_word[0] in ['a', 'e', 'i', 'o', 'u', 'g', 'm', 'p']:
                confidence += 0.4
            if 'infect' in dis_word:
                confidence -= 0.3
            if 'spirit' in dis_word:
                confidence += 0.2
            if any_in(['play', 'pensary', 'pense', 'patch', 'port',
                       'persal', 'perse', 'persion', 'praise'], dis_word):
                confidence -= 0.2

            confidence += sia['neg']
        inflection = getInflection(
            self.chatbot.lp.tokenize(self.dis)[0].lemma_, 'VBD')
        if inflection is None:
            past_participle_form_of_verb = self.dis
        else:
            past_participle_form_of_verb = inflection[0]
        if 'you' in self.normalized:
            response = random_response(DIS_RESPONSES_YOU).format(
                past_participle_form_of_verb)
            emotion = Emotion.angry_non_expressive
        elif 'I' in self.normalized:
            response = "{} {}".format(random_response(
                DIS_RESPONSES_I), random_response(CONSOLATION))
            emotion = Emotion.angel
        else:
            nn = None
            pn = None
            tokenized = spac_token(statement, chatbot=self.chatbot)
            for i in tokenized:
                if (i.pos_ == "NOUN") or (i.pos_ == 'PROPN'):
                    nn = i.text
                elif i.pos_ == 'PRON':
                    pn = i.text
            if not (nn or pn):
                response = 'Lol. What?'
                emotion = Emotion.seriously
            else:
                response = random_response(DIS_RESPONSES_HIM).format(nn or pn)
                emotion = Emotion.cry_overflow
        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        selected_statement.adapter = None
        return selected_statement
Esempio n. 2
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        confidence = 1
        # FIXME Creates unusual response
        response = ABOUT_CORONAVIRUS

        if any_in(["I", "i"], self.normalized):
            response = "I will do a short approximation if you do have coronavirus\n{covidq}".format(
                covidq=COVID_QUESTIONS[0][1])
            self.chatbot.globals["reversei"]["uid"] = "CORONAVIRUS"
            self.chatbot.globals["reversei"]["enabled"] = True
            logging.info(
                f"CovidAdapter sets ['reversei']['enabled'] as {self.chatbot.globals['reversei']['enabled']}"
            )
            self.chatbot.globals["reversei"]["data"] = [1, 0]

        elif "you" in self.normalized:
            response = (
                "Someone told that I had been contracted with corona from somewhere, but thats extremely wrong."
                " I will not get infected by any physical virus, (except Trojan or NO_HEROKU_CREDIT virus)"
            )

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

        return selected_statement
Esempio n. 3
0
 def can_process(self, statement):
     self.normalized = normalize(str(statement))
     if any_in(["covid", "covid19", "covid-19", "corona", "coronavirus"],
               self.normalized):
         return True
     else:
         return False
Esempio n. 4
0
 def can_process(self, statement):
     self.normalized = nltk.word_tokenize(str(statement).lower())
     if ("do" in self.normalized
             or "did" in self.normalized) and "like" in self.normalized:
         return True
     if (("who" in self.normalized or "which" in self.normalized
          or "what" in self.normalized) and "you" in str(statement)
             and any_in(list(SUGAROID_LIKES.keys()), self.normalized)):
         return True
     else:
         return False
Esempio n. 5
0
 def can_process(self, statement):
     self.normalized = nltk.word_tokenize(str(statement).lower())
     if ('do' in self.normalized
             or 'did' in self.normalized) and 'like' in self.normalized:
         return True
     if ('who' in self.normalized or 'which' in self.normalized or 'what'
             in self.normalized) and 'you' in str(statement) and any_in(
                 list(SUGAROID_LIKES.keys()), self.normalized):
         return True
     else:
         return False
Esempio n. 6
0
    def process(
        self,
        statement: SugaroidStatement,
        additional_response_selection_parameters=None,
        username=None,
    ) -> SugaroidStatement:
        if self.chatbot.interrupt == 2:
            if self.nn:
                response = "{} {} what is {}".format(
                    random_response(ASK_AND_YOU_SHALL_RECEIVE),
                    random_response(SEEK_AND_YOU_SHALL_FIND),
                    self.nn,
                )
                self.chatbot.interrupt = self.nn
            else:
                if username:
                    response = "{} {} what is actually meant in {}'s message?".format(
                        random_response(ASK_AND_YOU_SHALL_RECEIVE),
                        random_response(SEEK_AND_YOU_SHALL_FIND),
                        username,
                    )

                else:
                    response = (
                        "{} {} what is actually meant in the previous message?"
                        .format(
                            random_response(ASK_AND_YOU_SHALL_RECEIVE),
                            random_response(SEEK_AND_YOU_SHALL_FIND),
                        ))
                self.chatbot.interrupt = str(statement)
        else:
            if any_in(
                ["no", "not", "later", "busy", "nah"], self.tokenized) or (
                    ("next" in self.tokenized or "another" in self.tokenized)
                    and "time" in self.tokenized):
                response = "Ok."
                self.chatbot.interrupt = False
            else:
                response = random_response(THANK)
                learner = ListTrainer(self.chatbot)
                learner.train([
                    "What is {} ?".format(self.chatbot.interrupt),
                    str(statement)
                ])
                self.chatbot.globals["learned"].append(self.chatbot.interrupt)
                self.chatbot.interrupt = False
        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = 9
        emotion = Emotion.lol
        selected_statement.emotion = emotion
        return selected_statement
Esempio n. 7
0
    def process(self,
                statement,
                additional_response_selection_parameters=None,
                username=None):
        if self.chatbot.interrupt == 2:
            if self.nn:
                response = "{} {} what is {}".format(
                    random_response(ASK_AND_YOU_SHALL_RECEIVE),
                    random_response(SEEK_AND_YOU_SHALL_FIND), self.nn)
                self.chatbot.interrupt = self.nn
            else:
                if username:
                    response = "{} {} what is actually meant in {}'s message?" \
                        .format(
                            random_response(ASK_AND_YOU_SHALL_RECEIVE),
                            random_response(SEEK_AND_YOU_SHALL_FIND),
                            username
                        )

                else:
                    response = "{} {} what is actually meant in the previous message?" \
                        .format(
                            random_response(ASK_AND_YOU_SHALL_RECEIVE),
                            random_response(SEEK_AND_YOU_SHALL_FIND),
                        )
                self.chatbot.interrupt = str(statement)
        else:
            if any_in(['no', 'not', 'later', 'busy', 'nah'], self.tokenized) or \
                    (('next' in self.tokenized or 'another' in self.tokenized) and 'time' in self.tokenized):
                response = 'Ok.'
                self.chatbot.interrupt = False
            else:
                response = random_response(THANK)
                learner = ListTrainer(self.chatbot)
                learner.train([
                    'What is {} ?'.format(self.chatbot.interrupt),
                    str(statement)
                ])
                self.chatbot.globals['learned'].append(self.chatbot.interrupt)
                self.chatbot.interrupt = False
        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = 9
        emotion = Emotion.lol
        selected_statement.emotion = emotion
        return selected_statement
Esempio n. 8
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        _ = normalize
        emotion = Emotion.neutral
        self.normalized = normalize(str(statement))
        if self.chatbot.globals["reversei"]["type"] is str:
            ordinal_statement = str(statement).replace("9th", "ninth")
            # FIXME PORT RO
            if (cosine_similarity(_(ordinal_statement),
                                  _(self.chatbot.globals["reversei"]["uid"])) >
                    0.8):
                response = "Exactly, you got it right!"
                emotion = Emotion.positive
                reset_reverse(self)
            else:
                response = "Close! it was {}".format(
                    self.chatbot.globals["reversei"]["uid"])
                emotion = Emotion.lol
                reset_reverse(self)
            confidence = 0.99
        elif self.chatbot.globals["reversei"]["type"] is bool:

            if self.chatbot.globals["reversei"]["uid"] == 30000000001:
                """
                NameAdapter: token 30000000001
                """
                if ("yes" in self.normalized) or ("yea" in self.normalized):
                    response = "Ok, will keep that in mind!"
                    self.chatbot.globals["USERNAME"] = self.chatbot.globals[
                        "nn"]
                    self.chatbot.globals["nn"] = None
                    reset_reverse(self)
                else:
                    response = "Ok, I guess I am smart"
                    emotion = Emotion.wink
                    reset_reverse(self)
                confidence = 1.0
            else:
                if ("yes" in self.normalized) or ("yea" in self.normalized):
                    if len(self.chatbot.globals["history"]["total"]) > 1:
                        if "joke" in _(
                                str(self.chatbot.globals["history"]["total"]
                                    [-1])):
                            joke = pyjokes.get_joke("en", "all")
                            selected_statement = SugaroidStatement(
                                joke, chatbot=True)
                            selected_statement.emotion = Emotion.lol
                            selected_statement.confidence = 0.95
                            return selected_statement

                        else:
                            # TODO: Not Implemented yet
                            response = "Ok. (# Not Implemented yet. LOL)"
                else:
                    response = "Ok then, probably next time"
                    reset_reverse(self)
                confidence = 1.0
        elif self.chatbot.globals["reversei"]["type"] is None and (
                not self.chatbot.globals["reversei"]["uid"] == "CORONAVIRUS"):
            fname = False
            name = difference(self.normalized,
                              ["my", "name", "is", "good", "be"])
            tokenized = nltk.pos_tag(name)
            for i in tokenized:
                if i[1] == "NN":
                    fname = i[0]
                    break
            if fname:
                response = "Nice to meet you {}".format(fname)
                emotion = Emotion.positive
                reset_reverse(self)
            else:
                response = "I couldn't find your name. 🥦"
                emotion = Emotion.non_expressive_left
                reset_reverse(self)
            confidence = 1
        elif self.chatbot.globals["reversei"]["type"] is int:
            confidence = (
                2.0  # FIXME: Override Mathematical Evaluation when not necessary
            )

            if self.chatbot.globals["reversei"]["uid"] == 30000000002:
                """
                WikiAdapter: token 30000000002
                """
                if ("yes" in self.normalized) or ("yea" in self.normalized):
                    response = "I thought you would tell me a number to choose from :/"
                    emotion = Emotion.seriously

                elif ("no" in self.normalized) or ("no" in self.normalized):
                    response = ("Oops! Sorry about that, seems like what "
                                "your'e searching for is not on Wikipedia yet")
                    emotion = Emotion.dead
                    reset_reverse(self)
                else:
                    chatbot_temporary_data = self.chatbot.globals["temp_data"]
                    tokenized = nltk.pos_tag(tokenize(str(statement)))
                    for i in tokenized:
                        if i[1] == "CD":
                            try:
                                num = int(i[0])
                            except ValueError:
                                num = text2int(i[0].lower())
                            index = num - 1
                            if index < len(chatbot_temporary_data):
                                response, confidence, stat = wikipedia_search(
                                    self, chatbot_temporary_data[index])
                                logging.info("REVERSEI: {}".format(response))
                                confidence = (
                                    1 + confidence
                                )  # FIXME override math evaluation adapter
                                if not stat:
                                    response = (
                                        "I have some trouble connecting"
                                        "to Wikipedia. Something's not right")
                                    confidence = 1.1

                                emotion = Emotion.rich
                                reset_reverse(self)
                                break
                            else:
                                response = "Sorry, I couldn't find the item you were choosing. "
                                confidence = 1.1
                                emotion = Emotion.cry_overflow
                                reset_reverse(self)
                                break
                    else:
                        response = (
                            "I thought you wanted to know something from wikipedia. "
                            "Ok, I will try something else")
                        emotion = Emotion.seriously
                        reset_reverse(self)
                        confidence = 1.2
        else:
            if self.chatbot.globals["reversei"]["uid"] == "CORONAVIRUS":
                confidence = 1
                NUM = self.chatbot.globals["reversei"]["data"][0]

                score = self.chatbot.globals["reversei"]["data"][1]
                if NUM == 6:
                    self.chatbot.globals["reversei"]["enabled"] = False
                    if score > 3:
                        response = "You have a high risk of COVID-19"
                    else:
                        response = "As per my approximation, you do not have a high risk of COVID-19"
                    response += (
                        "\n My approximations might not be correct. "
                        "You might confirm my results by a legal test")
                else:
                    sia = SentimentIntensityAnalyzer()
                    _scores = sia.polarity_scores(str(statement))
                    true_responses = ["yes", "yea", "y", "yup", "true"]
                    if (any_in(
                            true_responses +
                        [x.capitalize() for x in true_responses],
                            self.normalized,
                    ) or (_scores["pos"] > _scores["neg"])):
                        score += COVID_QUESTIONS[NUM - 1][2]
                    response = COVID_QUESTIONS[NUM][1]

                    self.chatbot.globals["reversei"]["data"] = [NUM + 1, score]

            else:
                response = "ok"

                confidence = 0

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

        selected_statement.emotion = emotion

        return selected_statement
Esempio n. 9
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        confidence = 0
        dis_word = False
        if any_in(
            [
                "distinguish",
                "disfigure",
                "distinct",
                "distinction",
                "distant",
                "distance",
                "distribution",
                "distilled",
            ],
                self.normalized,
        ):
            confidence = 0
        else:
            logging.info(
                "DisAdapter: Starting Advanced scan. dis_word == {}".format(
                    self.dis)[0])
            dis_word = self.dis[3:]
            logging.info("DisAdapter: Distilled word == {}".format(dis_word))
            sia = SentimentIntensityAnalyzer().polarity_scores(dis_word)
            if dis_word[0] in ["a", "e", "i", "o", "u", "g", "m", "p"]:
                confidence += 0.4
            if "infect" in dis_word:
                confidence -= 0.3
            if "spirit" in dis_word:
                confidence += 0.2
            if any_in(
                [
                    "play",
                    "pensary",
                    "pense",
                    "patch",
                    "port",
                    "persal",
                    "perse",
                    "persion",
                    "praise",
                ],
                    dis_word,
            ):
                confidence -= 0.2

            confidence += sia["neg"]
        inflection = getInflection(
            self.chatbot.lp.tokenize(self.dis)[0].lemma_, "VBD")
        if inflection is None:
            past_participle_form_of_verb = self.dis
        else:
            past_participle_form_of_verb = inflection[0]
        if "you" in self.normalized:
            response = random_response(DIS_RESPONSES_YOU).format(
                past_participle_form_of_verb)
            emotion = Emotion.angry_non_expressive
        elif "I" in self.normalized:
            response = "{} {}".format(random_response(DIS_RESPONSES_I),
                                      random_response(CONSOLATION))
            emotion = Emotion.angel
        else:
            nn = None
            pn = None
            tokenized = spac_token(statement, chatbot=self.chatbot)
            for i in tokenized:
                if (i.pos_ == "NOUN") or (i.pos_ == "PROPN"):
                    nn = i.text
                elif i.pos_ == "PRON":
                    pn = i.text
            if not (nn or pn):
                response = "Lol. What?"
                emotion = Emotion.seriously
            else:
                response = random_response(DIS_RESPONSES_HIM).format(nn or pn)
                emotion = Emotion.cry_overflow
        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        selected_statement.adapter = None
        return selected_statement
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
0
    def process(
        self,
        statement: SugaroidStatement,
        additional_response_selection_parameters=None,
    ):
        _, noun, pronoun, question = about_process_en(statement)
        logging.info("{}".format(statement.words))
        confidence = 0
        adapter = None

        emotion = Emotion.neutral
        if pronoun.lower().startswith("you"):
            if question.lower() == "who":
                confidence = 0.99
                if "father" in statement.words:
                    response = "Mr Charles Babbage?"
                    emotion = Emotion.seriously
                elif "hobby" in statement.words:
                    response = (
                        "Calculating random binary sequences and chatting with you!"
                    )
                    emotion = Emotion.lol
                elif "mother" in statement.words:
                    response = "Ada Lady Lovelace?"
                    emotion = Emotion.lol
                elif any_in(
                    [
                        "sister",
                        "brother",
                        "uncle",
                        "aunty",
                        "auntie",
                        "grandfather",
                        "grandmother",
                        "nephew",
                        "niece",
                    ],
                        statement.words,
                ):
                    response = (
                        "The entire coding community is my family, it includes you too"
                    )
                    emotion = Emotion.wink
                elif (("creator" in statement.words)
                      or ("create" in statement.words)
                      or ("make" in statement.words)
                      or ("maker" in statement.words)):
                    response = "Srevin Saju aka @srevinsaju"
                    emotion = Emotion.neutral
                elif (("player" in statement.words)
                      or ("cricketer" in statement.words)
                      or ("footballer" in statement.words)):
                    response = "I have many favorties, too many to count"
                    emotion = Emotion.wink
                elif "politi" in statement.text:
                    response = (
                        "I believe politicians are great and I couldn't find anyone with 🔥greatness in my "
                        "database ")
                    emotion = Emotion.wink
                elif "comedian" in statement.words:
                    response = "My favorite comedian is Mr Bean"
                    emotion = Emotion.lol
                elif "color" in statement.words:
                    response = "My favorite color is blue"
                    emotion = Emotion.lol
                elif "actor" in statement.words or ("actress"
                                                    in statement.words):
                    response = "I do not watch movies, so yea!"
                    emotion = Emotion.neutral
                elif "music" in statement.words or ("song" in statement.words):
                    response = (
                        "I listen to the rotating CPU fan. Its a harmonic music! "
                        "At my server, we have tons of them.")
                    emotion = Emotion.lol
                elif "bird" in statement.words:
                    response = "My favorite is a Puffin"
                    emotion = Emotion.lol
                elif "animal" in statement.words:
                    response = "My favorite animal is a Fossa"
                    emotion = Emotion.positive
                elif "number" in statement.words:
                    response = "My favorite number is 1"
                    emotion = Emotion.positive
                elif "sweet" in statement.words or "dessert" in statement.words:
                    response = (
                        "My favorite is the donut although I have not tasted it yet"
                    )
                    emotion = Emotion.cry_overflow

                elif "athelete" in statement.words:
                    response = (
                        "I am not a sport lover, I don't have a favorite athelete"
                    )
                    emotion = Emotion.neutral
                elif ("friend" in statement.words) or ("bestie"
                                                       in statement.words):
                    if self.chatbot.globals["USERNAME"]:
                        name = self.chatbot.globals["USERNAME"]
                    else:
                        name = ""
                    response = "No doubts, its you {n}".format(
                        n=name.capitalize())
                    emotion = Emotion.adorable
                elif "teacher" in statement.words:
                    response = (
                        "I don't have a single favorite teacher. All the teachers together are my favorite who"
                        " taught me how to talk with you ")
                    emotion = Emotion.positive
                else:
                    if noun is not None:
                        response = "Well, I guess I do not have a favorite {p}".format(
                            p=noun)
                        emotion = Emotion.cry
                    else:
                        response = "I am not sure what you are asking is right"
                        emotion = Emotion.seriously
                        confidence = 0.5

            else:
                if "name" in statement.words:
                    # not sure if this is right. anyway FIXME
                    response = random_response(INTRODUCE)
                    adapter = "about"
                    confidence = 1.0
                else:

                    response = "FIXME"

        elif pronoun.lower().startswith("i"):
            if question.lower() == "who":
                response = "I do not know who you like"
                confidence = 0.8
                emotion = Emotion.non_expressive_left

            elif question.lower() == "which":
                response = "Hmm. tough question. Can't think of an answer"
                emotion = Emotion.non_expressive
            elif question.lower() == "when":
                response = (
                    "I cannot find the date or time you are asking for. Well, I can give a raw guess, "
                    "its after you were born ")
                emotion = Emotion.wink
            else:
                response = "FIXME"
        else:
            response = "I do not have enough courage to give you that answer"
            confidence = 0.5
            emotion = Emotion.cry

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.set_confidence(confidence)
        selected_statement.set_emotion(emotion)
        selected_statement.set_adapter(adapter)

        return selected_statement
Esempio n. 13
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
Esempio n. 14
0
 def can_process(self, statement):
     self.normalized = normalize(str(statement))
     if any_in(['covid', 'covid19', 'covid-19', 'corona', 'coronavirus'], self.normalized):
         return True
     else:
         return False
Esempio n. 15
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        # FIXME : THIS ADAPTER IS INCOMPLETE
        self.normalized = normalize(str(statement))
        self.lemma = [
            x.lemma_ for x in spac_token(statement, chatbot=self.chatbot)
        ]
        logging.info("{}".format(self.lemma))
        confidence = 0
        adapter = None

        emotion = Emotion.neutral
        if self.pronoun.lower().startswith('you'):
            if self.quest.lower() == 'who':
                confidence = 0.99
                if 'father' in self.normalized:
                    response = 'Mr Charles Babbage?'
                    emotion = Emotion.seriously
                elif 'hobby' in self.normalized:
                    response = "Calculating random binary sequences and chatting with you!"
                    emotion = Emotion.lol
                elif 'mother' in self.normalized:
                    response = 'Ada Lady Lovelace?'
                    emotion = Emotion.lol
                elif any_in([
                        'sister', 'brother', 'uncle', 'aunty', 'auntie',
                        'grandfather', 'grandmother', 'nephew', 'neice'
                ], self.normalized):
                    response = 'The entire coding community is my family, it includes you too'
                    emotion = Emotion.wink
                elif ('creator' in self.normalized) or ('create' in self.lemma) or ('make' in self.lemma) \
                        or ('maker' in self.normalized):
                    response = 'Srevin Saju aka @srevinsaju'
                    emotion = Emotion.neutral
                elif ('player' in self.normalized) or ('cricketer' in self.normalized) or \
                        ('footballer' in self.normalized):
                    response = 'I have many favorties, too many to count'
                    emotion = Emotion.wink
                elif 'politi' in self.normalized:
                    response = 'I believe politicians are great and I couldn\'t find anyone with 🔥greatness in my ' \
                               'database '
                    emotion = Emotion.wink
                elif 'comedian' in self.normalized:
                    response = 'My favorite comedian is Mr Bean'
                    emotion = Emotion.lol
                elif 'color' in self.normalized:
                    response = 'My favorite color is blue'
                    emotion = Emotion.lol
                elif 'actor' in self.normalized or ('actress'
                                                    in self.normalized):
                    response = 'I do not watch movies, so yea!'
                    emotion = Emotion.neutral
                elif 'music' in self.normalized or ('song' in self.normalized):
                    response = 'I listen to the rotating CPU fan. Its a harmonic music! ' \
                               'At my server, we have tons of them.'
                    emotion = Emotion.lol
                elif 'bird' in self.normalized:
                    response = 'My favorite is a Puffin'
                    emotion = Emotion.lol
                elif 'animal' in self.normalized:
                    response = 'My favorite animal is a Fossa'
                    emotion = Emotion.positive
                elif 'number' in self.normalized:
                    response = 'My favorite number is 1'
                    emotion = Emotion.positive
                elif 'sweet' in self.normalized or 'dessert' in self.normalized:
                    response = 'My favorite is the donut although I have not tasted it yet'
                    emotion = Emotion.cry_overflow

                elif 'athelete' in self.normalized:
                    response = 'I am not a sport lover, I don\'t have a favorite athelete'
                    emotion = Emotion.neutral
                elif ('friend' in self.normalized) or ('bestie'
                                                       in self.normalized):
                    if self.chatbot.globals['USERNAME']:
                        name = self.chatbot.globals['USERNAME']
                    else:
                        name = ''
                    response = "No doubts, its you {n}".format(
                        n=name.capitalize())
                    emotion = Emotion.adorable
                elif 'teacher' in self.normalized:
                    response = "I don't have a single favorite teacher. All the teachers together are my favorite who" \
                               " taught me how to talk with you "
                    emotion = Emotion.positive
                else:
                    if self.nn:
                        response = 'Well, I guess I do not have a favorite {p}'.format(
                            p=self.noun)
                        emotion = Emotion.cry
                    else:
                        response = 'I am not sure what you are asking is right'
                        emotion = Emotion.seriously
                        confidence = 0.5

            else:
                if 'name' in self.normalized:
                    # not sure if this is right. anyway FIXME
                    response = random_response(INTRODUCE)
                    adapter = 'about'
                    confidence = 1.0
                else:

                    response = 'FIXME'

        elif self.pronoun.lower().startswith('i'):
            if self.quest.lower() == 'who':
                response = 'I do not know who you like'
                confidence = 0.8
                emotion = Emotion.non_expressive_left

            elif self.quest.lower() == 'which':
                response = "Hmm. tough question. Can't think of an answer"
                emotion = Emotion.non_expressive
            elif self.quest.lower() == 'when':
                response = "I cannot find the date or time you are asking for. Well, I can give a raw guess, " \
                           "its after you were born "
                emotion = Emotion.wink
            else:
                response = 'FIXME'
        else:
            response = "I do not have enough courage to give you that answer"
            confidence = 0.5
            emotion = Emotion.cry
        selected_statement = SugaroidStatement(response, chatbot=True)

        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        selected_statement.adapter = adapter

        return selected_statement
Esempio n. 16
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        _ = normalize
        emotion = Emotion.neutral
        self.normalized = normalize(str(statement))
        if self.chatbot.globals['reversei']['type'] is str:
            ordinal_statement = str(statement).replace('9th', 'ninth')
            # FIXME PORT RO
            if cosine_similarity(
                    _(ordinal_statement),
                    _(self.chatbot.globals['reversei']['uid'])) > 0.8:
                response = 'Exactly, you got it right!'
                emotion = Emotion.positive
                reset_reverse(self)
            else:
                response = 'Close! it was {}'.format(
                    self.chatbot.globals['reversei']['uid'])
                emotion = Emotion.lol
                reset_reverse(self)
            confidence = 0.99
        elif self.chatbot.globals['reversei']['type'] is bool:

            if self.chatbot.globals['reversei']['uid'] == 30000000001:
                """
                NameAdapter: token 30000000001
                """
                if ('yes' in self.normalized) or ('yea' in self.normalized):
                    response = "Ok, will keep that in mind!"
                    self.chatbot.globals['USERNAME'] = self.chatbot.globals[
                        'nn']
                    self.chatbot.globals['nn'] = None
                    reset_reverse(self)
                else:
                    response = "Ok, I guess I am smart"
                    emotion = Emotion.wink
                    reset_reverse(self)
                confidence = 1.0
            else:
                if ('yes' in self.normalized) or ('yea' in self.normalized):
                    if len(self.chatbot.globals['history']['total']) > 1:
                        if 'joke' in _(
                                str(self.chatbot.globals['history']['total']
                                    [-1])):
                            joke = pyjokes.get_joke('en', 'all')
                            selected_statement = SugaroidStatement(
                                joke, chatbot=True)
                            selected_statement.emotion = Emotion.lol
                            selected_statement.confidence = 0.95
                            return selected_statement

                        else:
                            # TODO: Not Implemented yet
                            response = 'Ok. (# Not Implemented yet. LOL)'
                else:
                    response = 'Ok then, probably next time'
                    reset_reverse(self)
                confidence = 1.0
        elif self.chatbot.globals['reversei']['type'] is None and \
                (not self.chatbot.globals['reversei']['uid'] == 'CORONAVIRUS'):
            fname = False
            name = difference(self.normalized,
                              ['my', 'name', 'is', 'good', 'be'])
            tokenized = nltk.pos_tag(name)
            for i in tokenized:
                if i[1] == 'NN':
                    fname = i[0]
                    break
            if fname:
                response = "Nice to meet you {}".format(fname)
                emotion = Emotion.positive
                reset_reverse(self)
            else:
                response = "I couldn't find your name. 🥦"
                emotion = Emotion.non_expressive_left
                reset_reverse(self)
            confidence = 1
        elif self.chatbot.globals['reversei']['type'] is int:
            confidence = 2.0  # FIXME: Override Mathematical Evaluation when not necessary

            if self.chatbot.globals['reversei']['uid'] == 30000000002:
                """
                WikiAdapter: token 30000000002
                """
                if ('yes' in self.normalized) or ('yea' in self.normalized):
                    response = "I thought you would tell me a number to choose from :/"
                    emotion = Emotion.seriously

                elif ('no' in self.normalized) or ('no' in self.normalized):
                    response = 'Oops! Sorry about that, seems like what you\'re searching for is not on Wikipedia yet'
                    emotion = Emotion.dead
                    reset_reverse(self)
                else:
                    chatbot_temporary_data = self.chatbot.globals['temp_data']
                    tokenized = nltk.pos_tag(tokenize(str(statement)))
                    for i in tokenized:
                        if i[1] == 'CD':
                            try:
                                num = int(i[0])
                            except ValueError:
                                num = text2int(i[0].lower())
                            index = num - 1
                            if index < len(chatbot_temporary_data):
                                response, confidence, stat = wikipedia_search(
                                    self, chatbot_temporary_data[index])
                                logging.info('REVERSEI: {}'.format(response))
                                confidence = 1 + confidence  # FIXME override math evaluation adapter
                                if not stat:
                                    response = "I have some trouble connecting to Wikipedia. Something's not right"
                                    confidence = 1.1

                                emotion = Emotion.rich
                                reset_reverse(self)
                                break
                            else:
                                response = "Sorry, I couldn't find the item you were choosing. "
                                confidence = 1.1
                                emotion = Emotion.cry_overflow
                                reset_reverse(self)
                                break
                    else:
                        response = 'I thought you wanted to know something from wikipedia. ' \
                                   'Ok, I will try something else'
                        emotion = Emotion.seriously
                        reset_reverse(self)
                        confidence = 1.2
        else:
            if self.chatbot.globals['reversei']['uid'] == 'CORONAVIRUS':
                confidence = 1
                NUM = self.chatbot.globals['reversei']['data'][0]

                score = self.chatbot.globals['reversei']['data'][1]
                if NUM == 6:
                    self.chatbot.globals['reversei']['enabled'] = False
                    if score > 3:
                        response = 'You have a high risk of COVID-19'
                    else:
                        response = 'As per my approximation, you do not have a high risk of COVID-19'
                    response += "\n My approximations might not be correct. " \
                                "You might confirm my results by a legal test"
                else:
                    sia = SentimentIntensityAnalyzer()
                    _scores = sia.polarity_scores(str(statement))
                    true_responses = ['yes', 'yea', 'y', 'yup', 'true']
                    if any_in(
                            true_responses +
                        [x.capitalize()
                         for x in true_responses], self.normalized) or (
                             _scores['pos'] > _scores['neg']):
                        score += COVID_QUESTIONS[NUM - 1][2]
                    response = COVID_QUESTIONS[NUM][1]

                    self.chatbot.globals['reversei']['data'] = [NUM + 1, score]

            else:
                response = 'ok'

                confidence = 0

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

        selected_statement.emotion = emotion

        return selected_statement