def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): response = None confidence = 2.0 # FIXME: Override all other answers emotion = Emotion.genie if "stop" in statement.words: self.chatbot.globals["akinator"]["enabled"] = False response = "I am sorry. You quit the game abrubtly. {}".format( random_response(HOPE_GAME_WAS_GOOD)) elif not self.chatbot.globals["akinator"]["enabled"]: self.chatbot.globals["akinator"]["class"] = SugaroidAkinator( self.chatbot) response = self.chatbot.globals["akinator"]["class"].start_game() else: if not self.chatbot.globals["akinator"]["class"].game_over(): response = self.chatbot.globals["akinator"][ "class"].progression(statement) if not response: response = self.chatbot.globals["akinator"]["class"].win() else: if self.chatbot.globals["akinator"]["class"].start_check(): response = self.chatbot.globals["akinator"][ "class"].check_ans(statement) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(emotion) return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): confidence = 0 polarity_scores = self.sia.polarity_scores(statement.text) if ("bot" in statement.words or "machine" in statement.words or "computer" in statement.words): # the question is something like # are you a bot? response = random_response(ARE_YOU_A_BOT) confidence = 0.75 elif "sugaroid" in statement.words: # this person asked # are you sugaroid? # FIXME: use a better constants response = random_response(INTRODUCE) confidence = 0.75 elif ("human" in statement.words or "man" in statement.words or "woman" in statement.words or "sapien" in statement.words): # this person asked the bot if its a human # are you a human? response = random_response(ARE_YOU_A_HUMAN) confidence = 0.75 elif "boy" in statement.words or "girl" in statement.words: response = "I will leave it to your imagination. 😌" confidence = 0.75 elif "python" in statement.words: # this person asked something like # are you written in python response = ("I am written in python. Specifically, on v%s" % sys.version.replace("\n", " ")) confidence = 1 elif ("newborn" in statement.words or "infant" in statement.words or "child" in statement.words): response = "I am a newbie bots. I am trying to learn from my uncle and aunty bots and learning from them." elif ("dumb" in statement.words or "foolish" in statement.words or "mad" in statement.words or "weird" in statement.words or "awkward" in statement.words or polarity_scores["pos"] > polarity_scores["neg"]): response = random_response(BOT_DECLINE) elif ("alive" in statement.words or "online" in statement.words or "living" in statement.words): response = random_response(BOT_AGREE) else: response = random_response(BOT_NEUTRAL) confidence = 0.5 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(Emotion.neutral) return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): ps = self.sia.polarity_scores(statement.text) if ps["neu"] == 1 or (ps["pos"] > ps["neg"]): response = random_response(SUGAROID_CAN_AGREE) confidence = 0.81 else: response = random_response(SUGAROID_CAN_DISAGREE) confidence = 0.3 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(Emotion.angel) return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): confidence = 1 if "break" in statement.words: response = "Sure." elif ( "chocolate" in statement.words or "sweet" in statement.words or "kitkat" in statement.words ): response = "🍫" elif ( "food" in statement.words or "lunch" in statement.words or "brunch" in statement.words or "dinner" in statement.words or "lunner" in statement.words or "breakfast" in statement.words ): response = random_response( "🍏🍎🍐🍊🍋🍌🍇🍓🍈🍒🍑🥭🍍🥬🥦🥑🍆🍅🥝🥥🥒🌶🌽🥕🧄🧅🥔🧀🥨🥖🍞🥯🥐🍠🥚🍳🧈🥞🧇🥓🥩🍕🍟🍔🌭🦴🍖🍗🥪🥙🧆" "🌮🌯🥗🥘🍱🍣🍛🍲🍜🍝🥫🥟🦪🍤🍙🍚🍘🍥🍦🍨🍧🍡🍢🥮🥠🥧🧁🍰🎂🍮🍭🍬🍯🥜🌰🍪🍩🍿🍫🥛🍼☕️🍵🧃🥤🍶🍺🍻🥂🍷🥃" "🍸🍹🥣" ) else: ps = self.sia.polarity_scores(statement.text) if ps["neu"] == 1: response = "👀" * randint(1, 10) + ".." elif ps["pos"] > ps["neg"]: response = random_response(BOT_POSITIVE) confidence = 0.7 else: response = random_response(BOT_NEGATIVE) confidence = 0.7 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(Emotion.angel) return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ) -> SugaroidStatement: response = None confidence = 2.0 # FIXME: Override all other answers emotion = Emotion.genie if "stop" in statement.words: self.chatbot.globals["hangman"]["enabled"] = False response = "I am sorry. You quit the game abrubtly. {}".format( random_response(HOPE_GAME_WAS_GOOD)) else: if not self.chatbot.globals["hangman"]["enabled"]: self.chatbot.globals["hangman"]["class"] = Hangman( self.chatbot, is_marvel="marvel" in statement.words, is_hp="potter" in statement.words or "hp" in statement.words, ) response = ( "[ {dashes} ] Life: {heart}" "\n<pre><code>{figure}</code></pre>".format( dashes=" ".join(self.chatbot.globals["hangman"] ["class"].gen_dash()), heart=HANGMAN_EMOJI[self.chatbot.globals["hangman"] ["class"].get_remaining_life() - 1] * self.chatbot.globals["hangman"] ["class"].get_remaining_life(), figure=HANGMAN_STICKFIGURE[0], )) else: response = self.chatbot.globals["hangman"]["class"].process( statement.text) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(emotion) return selected_statement
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
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
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): # add emotion output adj = None verb = None confidence = 0.90 last_response = self.chatbot.globals["history"]["total"][-1] emotion = Emotion.neutral if last_response: tagged_last = pos_tag(last_response) tagged_now = pos_tag(statement) sm = SequenceMatcher(None, tagged_last, tagged_now) for i in statement.doc: if i.tag_ == "JJ": adj = i.lemma_ elif i.tag_ == "VB" and (not i.lemma_ == "be"): verb = i.lemma_ if sm.ratio() > 0.5: if adj: response = "Well, Its not a good reason for me to be {}".format( adj) else: response = "Well, its not a good reason you have told me ðŸ˜" else: if verb: if verb in [ "think", "breath", "eat", "hear", "feel", "taste" ]: response = "Robots are computer devices. I cannot {}".format( verb.replace("ing", "")) emotion = Emotion.cry else: response = ( "I may not be able to {}. " "This might not be my builtin quality".format( verb.replace("ing", ""))) emotion = Emotion.cry_overflow else: if adj: sia_scores = self.sia.polarity_scores(str(statement)) if sia_scores["neu"] == 1: response = "Ok! Thanks for your feedback" emotion = Emotion.positive elif sia_scores["pos"] > sia_scores["neg"]: response = "I will try to be more {} in future".format( adj) emotion = Emotion.adorable else: response = "I will never try to be {}.".format(adj) emotion = Emotion.angry else: response = random_response(BOT_REASONS) emotion = Emotion.non_expressive_left else: response = "Well, I cannot think of saying something. Your conversation began with reason. 🤯" emotion = Emotion.angry selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.set_confidence(confidence) selected_statement.set_emotion(emotion) return selected_statement