Exemple #1
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        confidence = 0.95
        # FIXME Creates unusual response

        if "do you know" in str(statement).lower():
            if self.normalized[0] == "do":
                self.normalized.pop(0)
                if self.normalized[0] == "you":
                    self.normalized.pop(0)
                    if self.normalized[0] == "know":
                        self.normalized.pop(0)

        if "i" in self.normalized:
            response = random_response(WHO_AM_I)
        elif "you" in self.normalized:
            if "to" in self.normalized:
                confidence = 0.5
                response = "You!"
            else:

                v = VERSION
                response = "\n{} \n{}. \nBuild: {}".format(
                    SUGAROID[0], random_response(WHO_ARE_YOU), v)
        else:
            response = "check the wiki"
            confidence = 0

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

        return selected_statement
Exemple #2
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        confidence = 1
        # FIXME Creates unusual response

        if 'do you know' in str(statement).lower():
            if self.normalized[0] == 'do':
                self.normalized.pop(0)
                if self.normalized[0] == 'you':
                    self.normalized.pop(0)
                    if self.normalized[0] == 'know':
                        self.normalized.pop(0)

        if 'i' in self.normalized:
            response = random_response(WHO_AM_I)
        elif 'you' in self.normalized:
            if 'to' in self.normalized:
                confidence = 0.5
                response = 'You!'
            else:
                v = VERSION
                response = "\n{} \n{}. \nBuild: {}".format(
                    SUGAROID[0], random_response(WHO_ARE_YOU), v.get_commit())
        else:
            response = 'check the wiki'
            confidence = 0

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

        return selected_statement
Exemple #3
0
    def process(self, statement, additional_response_selection_parameters=None):
        confidence = 0.9
        # FIXME Creates unusual response
        nn = False
        it = False
        token = spac_token(statement, chatbot=self.chatbot)
        for i in token:
            if (i.tag_ == 'NNP') or (i.tag_ == 'NN'):
                nn = True
            if i.lower_ == 'it':
                it = True

        if nn and not it:
            response = random_response(HOW_DO_HE_FEEL)
            emotion = Emotion.seriously
        elif it:
            response = "Ask it!"
            emotion = Emotion.o
        elif 'I' in self.normalized:
            emotion = Emotion.depressed
            response = random_response(HOW_DO_I_FEEL)
        else:
            emotion = Emotion.blush
            response = random_response(HOW_DO_YOU_FEEL)

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

        return selected_statement
Exemple #4
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        emotion = Emotion.seriously
        confidence = 0.81
        response = random_response(ONE_WORD)
        short = str(statement).lower()

        if ("name" in short) and ("my" in short):
            if self.chatbot.globals["USERNAME"]:
                response = "You are {}".format(
                    self.chatbot.globals["USERNAME"])
            else:
                response = random_response(WHO_AM_I)

        elif ("name" in short) and ("your" in short):
            v = VERSION
            response = "\n{} \n{}. \nBuild: {}".format(
                SUGAROID[0], random_response(WHO_ARE_YOU), v.get_commit())

        else:
            confidence = 0.2

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        selected_statement.adapter = None
        return selected_statement
Exemple #5
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
Exemple #6
0
 def game_over(self):
     """
     Congratulation message as response at the end of the game
     :return:
     """
     self.chatbot.globals['hangman']['enabled'] = False
     results = self.get_results()
     if results:
         response = random_response(HANGMAN_WIN)
     else:
         response = "{}. The word was {}".format(
             random_response(HANGMAN_LOS), self.word)
     return response
Exemple #7
0
 def game_over(self):
     """
     Congratulation message as response at the end of the game
     :return:
     """
     self.chatbot.globals["hangman"]["enabled"] = False
     results = self.get_results()
     if results:
         response = "You guessed it right! 🎉 '{}'\n {}.".format(
             str(self.word).upper(), random_response(HANGMAN_WIN))
     else:
         response = "{}. The word was {}".format(
             random_response(HANGMAN_LOS), self.word)
     return response
Exemple #8
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):

        cos = max([
            self.chatbot.lp.similarity(str(statement), "Tell me something"),
            self.chatbot.lp.similarity(str(statement), "Ask me something"),
            self.chatbot.lp.similarity(str(statement), "Ask me a question"),
            self.chatbot.lp.similarity(str(statement), "What can you do?"),
        ])
        if self.chatbot.lp.similarity(str(statement),
                                      "What can you do?") > 0.9:
            response = (
                "I can say a joke, answer some questions, play a game of Akinator too."
            )
        else:
            response_raw = random_response(RNDQUESTIONS)
            response = response_raw[0]
            self.chatbot.globals["reversei"]["enabled"] = True
            self.chatbot.globals["reversei"]["uid"] = response_raw[1]
            self.chatbot.globals["reversei"]["type"] = response_raw[2]

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

        return selected_statement
Exemple #9
0
    def process(self, statement, additional_response_selection_parameters=None):
        confidence = 1
        # FIXME Creates unusual response

        nl = spac_token(statement, chatbot=self.chatbot)

        for i in nl:
            if (i.lower_ == "my") or (i.lemma_ == "be") or (i.lower_ == "name"):
                continue
            logging.info("{} {}".format(i, i.pos_))
            if (i.pos_ == "NOUN") or (i.pos_ == "PROPN"):
                response = random_response(GREET).format(str(i.text).capitalize())
                selected_statement = SugaroidStatement(response, chatbot=True)
                selected_statement.confidence = confidence
                emotion = Emotion.positive
                selected_statement.emotion = emotion
                self.chatbot.globals["USERNAME"] = i.text
                return selected_statement
        else:
            response = ":)"
            confidence = 0
            selected_statement = SugaroidStatement(response, chatbot=True)
            selected_statement.confidence = confidence
            emotion = Emotion.neutral
            selected_statement.emotion = emotion

            return selected_statement
Exemple #10
0
def handle_dead_statements(statement: SugaroidStatement) -> Tuple[str, int]:
    """
    Handles those statements which contains words like dead
    some people dead, everyone dead.

    >>> statement = SugaroidStatement("Everyone is dead. Sed indeed")
    >>> response, _ = handle_dead_statements(statement)
    >>> print(response)
    Very sed

    :param statement: the statement to process
    :type statement: SugaroidStatement
    """

    if "everyone" in statement.words or "every" in statement.words:
        if ("except" in statement.words
                or "apart" in statement.words) and "me" in statement.words:
            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
    return response, emotion
Exemple #11
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        response = None
        confidence = 2.0  # FIXME: Override all other answers
        emotion = Emotion.genie

        if "stop" in self.normalized:
            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.confidence = confidence
        selected_statement.emotion = emotion
        return selected_statement
Exemple #12
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        response = None
        confidence = 2.0  # FIXME: Override all other answers
        emotion = Emotion.genie
        if 'stop' in self.normalized:
            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)
                response = "[ {dashes} ] Life: {heart}" \
                    .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())
            else:
                response = self.chatbot.globals['hangman']['class'].process(
                    str(statement))

        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = confidence
        selected_statement.emotion = emotion
        return selected_statement
Exemple #13
0
def process_what_ami_doing(statement: SugaroidStatement):
    response = None
    for i in statement.doc:
        if i.lower_ in WHAT_I_AM_GOING_TO_DO.keys():
            _answers_subset = WHAT_I_AM_GOING_TO_DO[i.lower_]
            if isinstance(_answers_subset, str):
                response = str(_answers_subset)
            elif isinstance(_answers_subset, list) or isinstance(
                _answers_subset, tuple
            ):
                response = random_response(_answers_subset)
            else:
                # FIXME: Needs more testing
                response = _answers_subset
            break
    if response:
        st = SugaroidStatement(
            response, confidence=0.5, chatbot=True, emotion=Emotion.cry_overflow
        )
        st.confidence = 0.5
        return st
    else:
        return SugaroidStatement(
            "Ok", confidence=0, chatbot=True, emotion=Emotion.cry_overflow
        )
Exemple #14
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 #15
0
    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
Exemple #16
0
 def __init__(self, chatbot: SugaroidBot, is_marvel=False, is_hp=False):
     """
     Initiate the hangman game.
     :param chatbot: a chatterbot.chatbot instance
     """
     if is_marvel:
         self.word = random_response(
             get_hangman_words("marvel", chatbot.session))
     elif is_hp:
         self.word = random_response(
             get_hangman_words("harrypotter-filtered", chatbot.session))
     else:
         self.word = random_response(
             get_hangman_words("general", chatbot.session))
     self.dashes = self.gen_dash()
     self.chatbot = chatbot
     self.chatbot.globals["hangman"]["enabled"] = True
     self.life = 7
Exemple #17
0
 def from_list_random(cls, statements: list):
     """
     Select a random statement from a list of statements
     :param statements:
     :type statements:
     :return:
     :rtype: SugaroidStatement
     """
     statement = random_response(statements)
     return cls(statement)
Exemple #18
0
 def process(self, statement, additional_response_selection_parameters=None):
     confidence = 0.7
     ls = ['😀', '😁', '😂',
           '😏', '😝']
     selected_statement = SugaroidStatement(
         "ok ok {}".format(random_response(ls)), chatbot=True)
     selected_statement.confidence = confidence
     emotion = Emotion.wink
     selected_statement.emotion = emotion
     return selected_statement
Exemple #19
0
    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
Exemple #20
0
 def __init__(self, chatbot):
     """
     Initiate the hangman game.
     :param chatbot: a chatterbot.chatbot instance
     """
     self.word = random_response(HANGMAN_WORDS)
     self.dashes = self.gen_dash()
     self.chatbot = chatbot
     self.chatbot.globals['hangman']['enabled'] = True
     self.life = 7
Exemple #21
0
 def process(self, statement, additional_response_selection_parameters=None):
     emotion = Emotion.neutral
     confidence = 1
     selected_statement = SugaroidStatement(
         random_response(BYE_RESPONSE), chatbot=True
     )
     selected_statement.confidence = confidence
     selected_statement.emotion = emotion
     selected_statement.adapter = None
     return selected_statement
Exemple #22
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        response = random_response(LET_THIS_HAPPEN)
        selected_statement = SugaroidStatement(response, chatbot=True)
        selected_statement.confidence = 1

        selected_statement.emotion = Emotion.blush

        return selected_statement
Exemple #23
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        response = "What?"
        confidence = 0

        sia = SentimentIntensityAnalyzer()
        ps = sia.polarity_scores(str(statement))
        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.confidence = confidence
        selected_statement.emotion = Emotion.angel
        return selected_statement
Exemple #24
0
def handle_give_consolation(_: SugaroidStatement) -> Tuple[str, int]:
    """
    Give consolation to the user when the user is depressed
    :param _:
    :type _:
    :return:
    :rtype:
    """
    response = "Its ok,  {}.".format(random_response(CONSOLATION))
    emotion = Emotion.positive
    return response, emotion
Exemple #25
0
def handle_thanks(_: SugaroidStatement) -> Tuple[str, int]:
    """
    Say welcome when the user says thank you!
    :param _:
    :type _:
    :return:
    :rtype:
    """
    response = random_response(WELCOME)
    emotion = Emotion.positive
    return response, emotion
Exemple #26
0
 def process(
     self,
     statement: SugaroidStatement,
     additional_response_selection_parameters=None,
 ) -> SugaroidStatement:
     emotion = Emotion.seriously
     confidence = 0.40
     response = random_response(ONE_WORD)
     selected_statement = SugaroidStatement(response, chatbot=True)
     selected_statement.confidence = confidence
     selected_statement.emotion = emotion
     selected_statement.adapter = None
     return selected_statement
Exemple #27
0
    def process(self,
                statement,
                additional_response_selection_parameters=None):
        emotion = Emotion.positive
        hour, minutes = current_time()
        alert = False
        if hour <= 0:
            alert = True
            time = ''
        elif hour <= 11:
            time = 'morning'
        elif hour <= 15:
            time = 'afternoon'
        elif hour <= 19:
            time = 'evening'
        elif hour <= 20:
            time = 'night'
        else:
            alert = True
            time = ''
        if not alert:
            if (time in self.intersect) or ('time' in self.intersect):
                response = 'Good {}'.format(time)
            else:
                response = 'Good {}. {}'.format(
                    time,
                    random_response(TIME_RESPONSE).format(
                        list(self.intersect)[0]))
        else:
            if self.chatbot.lp.similarity('good night', str(statement)) > 0.9:
                response = 'Sweet Dreams'
                emotion = Emotion.sleep
            else:
                response = "You are staying up late, you should sleep right now."
                emotion = Emotion.seriously
        if "what" in str(statement).lower():
            # the user might be asking the time
            # so we have to inform it instead of wishing
            # the person good morning
            response = "The current time is {:02d}:{:02d}".format(
                hour, minutes)
            emotion = Emotion.adorable
        selected_statement = SugaroidStatement("{}".format(response),
                                               chatbot=True)
        selected_statement.confidence = 1

        selected_statement.emotion = emotion

        return selected_statement
Exemple #28
0
 def check_ans(self, statement):
     statement = str(statement)
     if ('yes' in statement.lower()) or ('yea' in statement.lower()) or ('exactly' in statement.lower()) or \
             ('obviously' in statement.lower()) or ('correct' in statement.lower()) or \
             ('right' in statement.lower()) or ('you' in statement.lower() and 'won' in statement.lower()) or \
             statement.lower() == "yes" or statement.lower() == "y" or statement.lower() == "yea":
         response = "Yay! I won the game! 👊🎃🎁🎉 "
     else:
         response = "Oh. I failed the same. Seems like you are smarter than me. 😩🙀"
     response = response + \
         "\n{}\n I am back to my business".format(
             random_response(HOPE_GAME_WAS_GOOD))
     self.chatbot.globals['akinator']['enabled'] = False
     self.chatbot.globals['akinator']['class'] = None
     return response
Exemple #29
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
Exemple #30
0
    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