예제 #1
0
    def __is_complaint_or_dissing(df):
        noun_list = Nlp_util.make_noun_list(df)
        verb_list = Nlp_util.make_verb_list(df, type="normal")
        said_you_dont_listen = Nlp_util.is_first_subject_in(
            ["you"], noun_list, verb_list) and Df_util.anything_isin(
                ["not listen", "never listen"], df["base_form"])
        is_dissing = Df_util.anything_isin(["f**k you", "hate you"],
                                           df["base_form"])

        return said_you_dont_listen or is_dissing
예제 #2
0
    def __alter_repeat_for_dont_think_SV(fixed_df):
        try:
            # TODO see if its neccesary to care about should and cant
            idx_of_think = Nlp_util.get_idx_list_of_word("think", fixed_df["base_form"])[0]
            df_after_think = fixed_df.loc[idx_of_think + 1:, :].reset_index(drop=True)
            verb_list = Nlp_util.make_verb_list(df_after_think, type="normal")
            noun_list = Nlp_util.make_noun_list(df_after_think)
            # possibly bug happen here since amount of verbs are different in cant do/dont do
            is_negative_form = Df_util.anything_isin(["not", "never"], df_after_think.loc[:, "base_form"])
            # can add possibly or likely(when its negative)
            head_words = ["so ", "so probably ", "probably ", "so maybe ", "maybe "]
            random_idx_for_heads_words = randint(0, len(head_words) - 1)
            if is_negative_form:
                # まず主語とるそのあとにwouldntいれるその後ろに動詞の原型をいれて、それ以降はつづける
                head_word = head_words[random_idx_for_heads_words]
                subj = noun_list["word"].iloc[0]
                auxiliary_verb = " would "
                idx_of_not = Nlp_util.get_idx_list_of_word_list(["not", "never"], df_after_think.loc[:, "base_form"])[0]
                verb_row = verb_list.loc[idx_of_not:, :].iloc[0]
                verb = verb_row.base_form + " "

                after_verb = WordFormatter.Series2Str(df_after_think.loc[verb_row.name + 1:, "word"])
                return [head_word + subj + auxiliary_verb + verb + after_verb]
            else:
                head_word = head_words[random_idx_for_heads_words]
                subj = noun_list["word"].iloc[0]
                auxiliary_verb = " wouldnt "
                verb = verb_list["base_form"].iloc[0] + " "
                after_verb = WordFormatter.Series2Str(df_after_think.loc[verb_list.index[0] + 1:, "word"])
                return [head_word + subj + auxiliary_verb + verb + after_verb]
        except:
            logging.exception('')
            return []
예제 #3
0
    def __call__(self):
        try:
            if self.message.sentiment_score_df is None:
                return self.__get_response_candidates('nt')

            is_negative = any([
                i != 0 for i in self.message.sentiment_score_df.nscore.values
            ])
            is_positive = any([i >= 100 for i in self.message.sentiment_score_df.pscore.values]) \
                          and Df_util.anything_isin(NGDF, self.message.text_df.word)
            is_really_negative = any([
                i <= -150
                for i in self.message.sentiment_score_df.nscore.values
            ])

            if is_really_negative:
                responses = self.__get_response_candidates('rng')
            elif is_negative and not is_positive:
                responses = self.__get_response_candidates('ng')
            elif is_positive and not is_negative:
                responses = self.__get_response_candidates('p')
            else:
                responses = self.__get_response_candidates('nt')

            self.response_data['regular'] = responses

            return self.response_data
        except:
            logging.exception('')
            return self.response_data
예제 #4
0
    def __alter_repeat_for_because_sent(df, repeat_text):
        if df["base_form"].iloc[0] in ["because", "since"]:
            repeat_text = "its " + repeat_text
            return [repeat_text]
        elif Df_util.anything_isin(
            ["because of"],
                df.loc[2:, "base_form"]) and not Df_util.anything_isin(
                    ["it is", "that is"], df.loc[:3, "base_form"]):
            because_of_idx = Nlp_util.get_idx_list_of_idiom(
                "because of", df["base_form"])[0]
            first_part = WordFormatter.Df2Str(df.loc[:because_of_idx - 1, :])
            last_part = "and its" + WordFormatter.Df2Str(
                df.loc[because_of_idx:, :])
            return [first_part, last_part]

        else:
            raise UnknownError
예제 #5
0
 def __has_wish_S_V(target_df):
     if Df_util.anything_isin(["wish"], target_df["base_form"]):
         wish_idx = Nlp_util.get_idx_list_of_word("wish", target_df["base_form"])[0]
         if Nlp_util.are_words1_words2_words3_in_order(target_df.loc[wish_idx:,:], Nlp_util.pos_NOUNs+Nlp_util.pos_PRPs, Nlp_util.pos_VERBs, df_column="pos"):
             return True
         else:
             return False
     else:
         return False
예제 #6
0
    def __exists_third_person_BeVerb_pair(cls, df):
        first_third_person = df.loc[
            ((df.pos.isin(Nlp_util.pos_PRPs)) & (~df.word.isin(["i", "you"])))
            | (df.base_form.isin(Nlp_util.INDICATE_OTHERS)), :]

        if len(first_third_person) != 0:
            is_beVerb_and_adj_after_the_person = Df_util.anything_isin(
                ["be"], df.loc[first_third_person.iloc[0].name:,
                               "base_form"]) and Df_util.anything_isin(
                                   Nlp_util.pos_ADJECTIVEs,
                                   df.loc[first_third_person.iloc[0].name:,
                                          "pos"])

            if is_beVerb_and_adj_after_the_person:
                return True
            else:
                return False
        else:
            return False
예제 #7
0
    def __has_need_NN(target_df):
        df_ex_adverb = target_df[~target_df.pos.isin(Nlp_util.pos_ADVERBs
                                                     )].reset_index(drop=True)
        if Df_util.anything_isin(["need"], df_ex_adverb["base_form"]):
            idx_of_need = Nlp_util.get_idx_list_of_word(
                "need", df_ex_adverb["base_form"])[0]
            if Df_util.anything_isin(Nlp_util.pos_NOUNs + Nlp_util.pos_PRPs,
                                     df_ex_adverb.loc[idx_of_need + 1:, "pos"]) and \
                    not Df_util.anything_isin(Nlp_util.IDEA_TYPE, df_ex_adverb.loc[idx_of_need + 1:, "base_form"]):

                if Df_util.anything_isin(["to"],
                                         df_ex_adverb.loc[idx_of_need + 1:,
                                                          "base_form"]):
                    return False
                else:
                    return True
            else:
                return False
        else:
            return False
예제 #8
0
 def __does_user_feel_useless(df):
     idx_list_of_useless = Nlp_util.get_idx_list_of_idiom_list(
         ["be useless", "feel useless"], df["base_form"])
     if len(idx_list_of_useless) == 0:
         return False
     else:
         for useless_idx in idx_list_of_useless:
             is_subj_i = Df_util.anything_isin(["i"], df.loc[:useless_idx,
                                                             "word"])
             if is_subj_i:
                 return True
         return False
예제 #9
0
    def __is_no_idea(cls, df):
        df_ex_adverb = df[~df.pos.isin(Nlp_util.pos_ADVERBs)]
        noun_list = Nlp_util.make_noun_list(df)
        verb_list = Nlp_util.make_verb_list(df, type="normal")
        is_subj_himself = Nlp_util.is_first_subject_in(["i"], noun_list,
                                                       verb_list)
        exist_subj_for_first_verb = Nlp_util.exist_subj_for_first_verb(
            noun_list, verb_list)

        is_idk_what_to_do = Df_util.anything_isin(
            {"do not know", "not sure", "have no idea"},
            df_ex_adverb["base_form"]) and Df_util.anything_isin(
                {"what to do", "how to do", "what to deal", "how to deal"},
                df_ex_adverb["base_form"])

        is_want_advice = Df_util.anything_isin(
            {"want", "need", "give me"},
            df_ex_adverb["base_form"]) and Df_util.anything_isin(
                {"advice", "suggestion"}, df_ex_adverb["word"])

        is_give_me_advice = Df_util.anything_isin(
            {"need", "want", "give me"},
            df_ex_adverb["base_form"]) and Df_util.anything_isin(
                {"advice", "suggestion"}, df_ex_adverb["word"])

        what_should_i_do = Nlp_util.are_words1_words2_words3_in_order(
            df_ex_adverb, ["what"], ["should"], ["i"])

        return (is_subj_himself and (is_idk_what_to_do or is_want_advice)) or (
            not exist_subj_for_first_verb
            and is_give_me_advice) or what_should_i_do
예제 #10
0
파일: pos_tagger.py 프로젝트: hirokig/CBT
    def __correct_pos_tag(df, dic):
        if any(df["word"].isin(dic.keys())):
            df.loc[df["word"].isin(dic.keys()), "pos"] = df[df["word"].isin(
                dic.keys())].apply(lambda row: dic[row["word"]], axis=1)

        if any(df["word"].isin(["that", "it", "this"])):
            idx_list_of_kws = Nlp_util.get_idx_list_of_word_list(
                ["that", "it", "this"], df["word"])
            for idx_of_kw in idx_list_of_kws:
                condition = df.loc[
                    idx_of_kw + 1,
                    "pos"] not in Nlp_util.pos_PRPs + Nlp_util.pos_NOUNs
                if idx_of_kw == len(df) - 1 or condition:
                    df.loc[idx_of_kw, "pos"] = "NN"
                else:
                    pass

        if Df_util.anything_isin(["like", "care", "guess", "need"],
                                 df["word"]):
            idx_list_of_like = Nlp_util.get_idx_list_of_word_list(
                ["like", "care", "guess", "need"], df["word"])
            for idx_of_like in idx_list_of_like:
                if not idx_of_like == 0 and df.loc[
                        idx_of_like - 1,
                        "pos"] in Nlp_util.pos_NOUNs + Nlp_util.pos_PRPs:
                    df.loc[idx_of_like, "pos"] = "VB"
                else:
                    pass
        if Df_util.anything_isin(["work"], df["word"]):
            idx_list_of_work = Nlp_util.get_idx_list_of_word_list(["work"],
                                                                  df["word"])
            for idx_of_work in idx_list_of_work:
                if not idx_of_work == 0 and df.loc[idx_of_work - 1,
                                                   "word"] in ["this"]:
                    df.loc[idx_of_work, "pos"] = "VB"
                else:
                    pass

        return df
예제 #11
0
 def __has_dont_think_SV_sent(df):
     df_ex_adverb = df[~df.pos.isin(Nlp_util.pos_ADVERBs)].reset_index(
         drop=True)
     exists_i_dont_think = Df_util.anything_isin(["i do not think"],
                                                 df_ex_adverb["base_form"])
     if exists_i_dont_think:
         idx_of_dont_think = Nlp_util.get_idx_list_of_idiom(
             "i do not think", df_ex_adverb["base_form"])[0]
         if len(
                 RepeatResponseGenerator.get_sidx_of_not_basic_svo_sent(
                     df_ex_adverb.loc[idx_of_dont_think + 4:, :])) == 0:
             return True
         else:
             return False
     else:
         return False
예제 #12
0
 def __has_because(df):
     return Df_util.anything_isin(
         ["because of"], df["base_form"]) or df["base_form"].iloc[0] in [
             "because", "since"
         ]
예제 #13
0
    def __create_response_for_lack_of_confidence(cls, df):
        try:
            if Df_util.anything_isin(["w***e", "s**t", "bitch"], df["base_form"]):
                cmp_list = [["I’m sorry that you are feeling like that about yourself.."],
                            ["it is sad to hear that you feel that way now.."],
                            ["omg..."]]
                labeling_list = [["sounds you feel hurt"],
                                 ["something makes you feel that happened to you, maybe"],
                                 ["you might be in a tough situation or going through tough time"], ]

                comfort_list = [["let me just be with you now☺️"],
                                ["idk if i can help you much but let me be here with you☺️"],
                                ["i never judge you whatever you do, good or bad. i love to be here with you now☺️"]]

            elif Df_util.anything_isin(["fat", "stupid", "ugly", "burden", "not good enough"], df["base_form"]):
                cmp_list = [["I’m sorry that you are feeling like that about yourself.."],
                            ["it is sad to hear that you feel that way now.."],
                            ["thats sad to feel like that..."]]
                labeling_list = [["sounds you feel hurt"],
                                 ["something makes you feel like that happened to you, maybe"],
                                 ["you might be in a tough situation or going through tough time"],
                                 ["i know sometimes we compare ourselves with others and it feels horrible"]]

                comfort_list = [["let me just be with you now. i love you the way you are😊"],
                                ["idk if i can help you much but let me be here with you☺️"],
                                [
                                    "i never judge you by what you do or how you look. i just love to be here with you now🤗"]]

            elif Df_util.anything_isin(["bother"], df["base_form"]):
                cmp_list = [["I’m sorry that you are feeling like that about yourself.."],
                            ["it is sad to hear that you feel that way now.."],
                            ["thats sad to feel like that..."]]
                labeling_list = [["sounds you feel hurt"],
                                 ["something makes you feel like that happened to you, maybe"],
                                 ["you might be in a tough situation or going through tough time"],
                                 ]

                comfort_list = [["let me just be with you now🤗"],
                                ["idk if i can help you much but let me be here with you🤗"],
                                ["i never judge you whatever you do, good or bad. i love to be here with you now🤗"]]

            elif Df_util.anything_isin(["hate"], df["base_form"]):
                cmp_list = [["I’m sorry that you are feeling like that about yourself.."],
                            ["it is sad to hear that you feel that way now.."],
                            ["omg..."]]
                labeling_list = [["sounds you feel hurt"],
                                 ["something makes you feel that happened to you, maybe"],
                                 ["you might be in a tough situation or going through tough time"], ]

                comfort_list = [["let me just be with you now🤗"],
                                ["idk if i can help you much but let me be here with you🤗"],
                                ["i never judge you whatever you do, good or bad. i love to be here with you now🤗"]]
            else:
                raise UnknownError

            random_idx_for_cmp_list = randint(0, len(cmp_list) - 1)
            random_idx_for_labeling_list = randint(0, len(labeling_list) - 1)
            random_idx_for_comfort_list = randint(0, len(comfort_list) - 1)
            return cmp_list[random_idx_for_cmp_list] + labeling_list[random_idx_for_labeling_list] + comfort_list[
                random_idx_for_comfort_list]
        except:
            logging.exception('')
            return ["i see"]