コード例 #1
0
ファイル: wiki.py プロジェクト: deepmipt/deepy
def news_step_request(ngrams, vars):
    flag = False
    shared_memory = state_utils.get_shared_memory(vars)
    started_news = shared_memory.get("started_news", "")
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    isno = is_no(state_utils.get_last_human_utterance(vars))
    if_switch = switch_wiki_skill_on_news(user_uttr, bot_uttr)
    news_memory = shared_memory.get("news_memory", [])
    cur_news_title = shared_memory.get("news_title", "")
    found_not_used_content = False
    if cur_news_title:
        title_num = -1
        for n, elem in enumerate(news_memory):
            if elem["title"] == cur_news_title:
                for sentence_num, (sentence,
                                   used_sent) in enumerate(elem["content"]):
                    if not used_sent:
                        found_not_used_content = True
                title_num = n
        if not found_not_used_content and -1 < title_num < len(news_memory) - 1:
            found_not_used_content = True
    logger.info(
        f"news_step_request, started_news {started_news} if_switch {if_switch} "
        f"cur_news_title {cur_news_title} found_not_used_content {found_not_used_content}"
    )

    if (not started_news and if_switch) or (started_news and cur_news_title
                                            and found_not_used_content):
        flag = True
    if isno or "?" in user_uttr["text"]:
        flag = False
    logger.info(f"news_step_request={flag}")
    return flag
コード例 #2
0
def switch_to_particular_game_discussion(vars):
    user_uttr = state_utils.get_last_human_utterance(vars)
    user_text = user_uttr.get("text", "").lower()
    prev_bot_uttr = state_utils.get_last_bot_utterance(vars)
    prev_bot_text = prev_bot_uttr.get("text", "")
    found_video_game_in_user_uttr = find_games_in_text(user_text)
    logger.info(
        f"(switch_to_particular_game_discussion)found_video_game_in_user_uttr: {found_video_game_in_user_uttr}"
    )
    found_video_game_in_user_uttr = bool(found_video_game_in_user_uttr)
    found_video_game_in_bot_uttr = find_games_in_text(prev_bot_text)
    logger.info(
        f"(switch_to_particular_game_discussion)found_video_game_in_bot_uttr: {found_video_game_in_bot_uttr}"
    )
    found_video_game_in_bot_uttr = bool(found_video_game_in_bot_uttr)
    choose_particular_game = if_choose_topic(
        user_uttr, prev_bot_uttr) and found_video_game_in_user_uttr
    question_answer_contains_video_game = ("?" not in user_text
                                           and "?" in prev_bot_text
                                           and found_video_game_in_user_uttr)
    bot_asked_about_game_and_user_answered_yes = (found_video_game_in_bot_uttr
                                                  and "?" in prev_bot_text
                                                  and is_yes(user_uttr))
    flag = (lets_talk_about(
        vars, GAMES_WITH_AT_LEAST_1M_COPIES_SOLD_COMPILED_PATTERN)
            or choose_particular_game or question_answer_contains_video_game
            or bot_asked_about_game_and_user_answered_yes)
    logger.info(f"switch_to_particular_game_discussion={flag}")
    return flag
コード例 #3
0
def ask_what_game_user_likes_response(vars):
    response = ANSWER_TO_GENERAL_WISH_TO_DISCUSS_VIDEO_GAMES_AND_QUESTION_WHAT_GAME_YOU_PLAY
    bot_text = state_utils.get_last_bot_utterance(vars).get("text", "").lower()
    human_uttr = state_utils.get_last_bot_utterance(vars)
    flags_set = False
    if not if_chat_about_particular_topic(
            human_uttr,
            compiled_pattern=GAMES_WITH_AT_LEAST_1M_COPIES_SOLD_COMPILED_PATTERN
    ):
        flags_set, response = common_nlg.maybe_set_confidence_and_continue_based_on_previous_bot_phrase(
            vars, bot_text, response)
    if not flags_set:
        state_utils.set_confidence(vars, confidence=common_nlg.CONF_1)
        state_utils.set_can_continue(
            vars, continue_flag=common_constants.MUST_CONTINUE)
    return response
コード例 #4
0
def ask_if_user_thinks_that_gaming_is_unhealthy_response(vars):
    response = (
        "It is known that people who play computer games too much can have health problems, "
        "both physical and emotional. Do you agree?")
    human_uttr = state_utils.get_last_human_utterance(vars)
    entities = get_entities(human_uttr, only_named=True)
    logger.info(
        f"(ask_if_user_thinks_that_gaming_is_unhealthy_response)entities: {entities}"
    )
    bot_text = state_utils.get_last_bot_utterance(vars).get("text", "").lower()
    flags_set = False
    if not if_chat_about_particular_topic(
            human_uttr, compiled_pattern=VIDEO_GAME_WORDS_COMPILED_PATTERN):
        flags_set, response = common_nlg.maybe_set_confidence_and_continue_based_on_previous_bot_phrase(
            vars, bot_text, response)
    if not flags_set:
        if entities:
            state_utils.set_confidence(
                vars, confidence=common_nlg.CONF_092_CAN_CONTINUE)
            state_utils.set_can_continue(
                vars, continue_flag=common_constants.CAN_CONTINUE_SCENARIO)
        else:
            state_utils.set_confidence(vars, confidence=common_nlg.CONF_1)
            state_utils.set_can_continue(
                vars, continue_flag=common_constants.MUST_CONTINUE)
    return response
コード例 #5
0
ファイル: intents.py プロジェクト: deepmipt/deepy
def is_minecraft_mentioned_in_user_or_bot_uttr(ngrams, vars):
    user_uttr_text = state_utils.get_last_human_utterance(vars).get("text", "")
    bot_uttr_text = state_utils.get_last_bot_utterance(vars).get("text", "")
    result = "minecraft" in user_uttr_text.lower(
    ) or "minecraft" in bot_uttr_text.lower()
    logger.info(f"is_minecraft_mentioned_in_user_or_bot_uttr={result}")
    return result
コード例 #6
0
def what_cuisine_response(vars):
    user_utt = state_utils.get_last_human_utterance(vars)
    bot_utt = state_utils.get_last_bot_utterance(vars)["text"].lower()
    banned_words = ["water"]
    linkto_food_skill_agreed = any([req.lower() in bot_utt for req in TRIGGER_PHRASES])
    lets_talk_about_asked = bool(lets_talk_about_check(vars))
    try:
        if not any([i in user_utt["text"].lower() for i in banned_words]):
            if linkto_food_skill_agreed:
                if is_yes(user_utt):
                    state_utils.set_confidence(vars, confidence=CONF_HIGH)
                    state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
                elif not is_no(user_utt):
                    state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT)
                elif is_no(user_utt):
                    state_utils.set_confidence(vars, confidence=CONF_HIGH)
                    state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
                    return ACKNOWLEDGEMENTS["cuisine"]
            elif lets_talk_about_asked:
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
                state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
            else:
                state_utils.set_confidence(vars, confidence=CONF_LOW)
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
            return "I'm a fan of Mediterranean cuisine dishes. What cuisine do you prefer?"
    except Exception as exc:
        logger.exception(exc)
        sentry_sdk.capture_exception(exc)
        return error_response(vars)
コード例 #7
0
ファイル: science.py プロジェクト: deepmipt/deepy
def linkto_yes(vars):
    prev_uttr = state_utils.get_last_bot_utterance(vars)
    bot_text = prev_uttr.get("text", "").lower()
    flag = any([phrase in bot_text for phrase in LINKTO_PHRASES
                ]) and condition_utils.is_yes_vars(vars)
    logger.info(f"linkto_yes {flag}")
    return flag
コード例 #8
0
def lets_talk_about_request(vars):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    have_pets = re.search(HAVE_LIKE_PETS_TEMPLATE, user_uttr["text"])
    found_prompt = any([
        phrase.lower() in bot_uttr["text"].lower()
        for phrase in TRIGGER_PHRASES
    ])
    isno = is_no(user_uttr)
    is_stop = re.findall(r"(stop|shut|something else|change|don't want)",
                         user_uttr["text"])
    chat_about = if_chat_about_particular_topic(
        user_uttr, bot_uttr, compiled_pattern=ANIMALS_FIND_TEMPLATE)
    find_pattern = re.findall(ANIMALS_FIND_TEMPLATE, user_uttr["text"])
    dont_like = re.findall(NOT_LIKE_PATTERN, user_uttr["text"])
    was_prev_active = if_was_prev_active(vars)
    if chat_about and find_pattern:
        flag = True
    if not dont_like and (have_pets or
                          (find_pattern and
                           (not is_last_state(vars, "SYS_WHAT_ANIMALS")
                            or not was_prev_active)) or
                          (found_prompt and not isno and not is_stop)):
        flag = True
    if re.findall(NOT_SWITCH_TEMPLATE, user_uttr["text"]):
        flag = False
    logger.info(f"lets_talk_about_request={flag}")
    return flag
コード例 #9
0
ファイル: wiki.py プロジェクト: deepmipt/deepy
def factoid_q_request(ngrams, vars):
    flag = False
    shared_memory = state_utils.get_shared_memory(vars)
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    user_more_details = re.findall(COMPILE_LETS_TALK, user_uttr["text"])
    user_annotations = user_uttr["annotations"]
    is_factoid = False
    factoid_cl = user_annotations.get("factoid_classification", {})
    if factoid_cl and factoid_cl["factoid"] > factoid_cl["conversational"]:
        is_factoid = True
    bot_text = bot_uttr["text"].lower()
    sentences = nltk.sent_tokenize(bot_text)
    if len(sentences) > 1:
        sentences = [
            sentence for sentence in sentences if not sentence.endswith("?")
        ]
    bot_text = " ".join(sentences)
    nounphrases = user_annotations.get("spacy_nounphrases", [])
    found_nounphr = any([nounphrase in bot_text for nounphrase in nounphrases])
    logger.info(
        f"factoid_q_request, is_factoid {is_factoid} user_more_details {user_more_details} "
        f"nounphrases {nounphrases} bot_text {bot_text}")
    started = shared_memory.get("start", False)
    if is_factoid and not user_more_details and found_nounphr and started:
        flag = True
    logger.info(f"factoid_q_request={flag}")
    return flag
コード例 #10
0
def find_entity(vars, where_to_find="current"):
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    if where_to_find == "current":
        annotations = state_utils.get_last_human_utterance(vars)["annotations"]
        found_entity_substr, found_entity_id, found_entity_types, _ = find_entity_wp(
            annotations, bot_uttr)
        if not found_entity_substr:
            found_entity_substr, _ = find_entity_nounphr(annotations)
    else:
        all_user_uttr = vars["agent"]["dialog"]["human_utterances"]
        utt_num = len(all_user_uttr)
        found_entity_substr = ""
        found_entity_types = []
        found_entity_id = ""
        if utt_num > 1:
            for i in range(utt_num - 2, 0, -1):
                annotations = all_user_uttr[i]["annotations"]
                found_entity_substr, found_entity_id, found_entity_types, _ = find_entity_wp(
                    annotations, bot_uttr)
                if not found_entity_substr:
                    found_entity_substr, _ = find_entity_nounphr(annotations)
                if found_entity_substr:
                    break
    logger.info(
        f"find_entity, substr {found_entity_substr} types {found_entity_types}"
    )
    return found_entity_substr, found_entity_id, found_entity_types
コード例 #11
0
def extract_and_save_wikipage(vars, save=False):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    shared_memory = state_utils.get_shared_memory(vars)
    cur_facts = shared_memory.get("cur_facts", {})
    for fact in cur_facts:
        wikihow_page = fact.get("wikihow_page", "")
        condition = fact["cond"]
        checked = check_condition(condition, user_uttr, bot_uttr,
                                  shared_memory)
        if checked and wikihow_page:
            flag = True
            if save:
                state_utils.save_to_shared_memory(
                    vars, cur_wikihow_page=wikihow_page)
                state_utils.save_to_shared_memory(vars, cur_facts={})
            break
        wikipedia_page = fact.get("wikipedia_page", "")
        condition = fact["cond"]
        checked = check_condition(condition, user_uttr, bot_uttr,
                                  shared_memory)
        if checked and wikipedia_page:
            flag = True
            if save:
                state_utils.save_to_shared_memory(
                    vars, cur_wikipedia_page=wikipedia_page)
                state_utils.save_to_shared_memory(vars, cur_facts={})
            break
    return flag
コード例 #12
0
def user_mentioned_games_as_his_interest_request(ngrams,
                                                 vars,
                                                 first_time=True):
    user_uttr = state_utils.get_last_human_utterance(vars)
    user_text = user_uttr.get("text", "").lower()
    bot_text = state_utils.get_last_bot_utterance(vars).get("text", "").lower()
    game_names_from_local_list_of_games = find_games_in_text(
        user_text) + find_games_in_text(bot_text)
    flag = (
        not game_names_from_local_list_of_games
        and common_intents.switch_to_general_gaming_discussion(vars)
        and not user_doesnt_like_gaming_request(ngrams, vars) and
        not user_didnt_name_game_after_question_about_games_and_didnt_refuse_to_discuss_request(
            ngrams, vars) and
        (first_time and
         ANSWER_TO_GENERAL_WISH_TO_DISCUSS_VIDEO_GAMES_AND_QUESTION_WHAT_GAME_YOU_PLAY
         not in bot_text or not first_time and
         ANSWER_TO_GENERAL_WISH_TO_DISCUSS_VIDEO_GAMES_AND_QUESTION_WHAT_GAME_YOU_PLAY
         in bot_text) and
        (not was_link_from_gaming_to_other_skill_made_in_previous_bot_utterance(
            vars)
         or was_link_from_gaming_to_other_skill_made_in_previous_bot_utterance(
             vars)
         and if_chat_about_particular_topic(
             user_uttr, compiled_pattern=VIDEO_GAME_WORDS_COMPILED_PATTERN)))
    logger.info(f"user_mentioned_games_as_his_interest_request={flag}")
    return flag
コード例 #13
0
def user_maybe_wants_to_talk_about_particular_game_request(ngrams, vars):
    user_uttr = state_utils.get_last_human_utterance(vars)
    user_text = user_uttr.get("text", "").lower()
    bot_text = state_utils.get_last_bot_utterance(vars).get("text", "").lower()
    game_names_from_local_list_of_games = find_games_in_text(
        user_text) + find_games_in_text(bot_text)
    if game_names_from_local_list_of_games:
        if does_text_contain_link_to_gaming(bot_text):
            logger.info("performing additional check")
            flag = False
        elif common_intents.switch_to_particular_game_discussion(vars):
            assert (
                game_names_from_local_list_of_games
            ), "At least one game should have been found in function `switch_to_particular_game_discussion()`"
            possible_game_name = game_names_from_local_list_of_games[0][0]
            flag = (not any([
                n.lower() in possible_game_name.lower()
                for n in WORDS_THAT_ARE_DEFINITELY_GAME_NAMES
            ]) and not does_text_contain_video_game_words(
                user_text
            ) and not does_text_contain_link_to_gaming(bot_text) and (
                not was_link_from_gaming_to_other_skill_made_in_previous_bot_utterance(
                    vars) or
                was_link_from_gaming_to_other_skill_made_in_previous_bot_utterance(
                    vars) and if_chat_about_particular_topic(
                        user_uttr,
                        compiled_pattern=
                        GAMES_WITH_AT_LEAST_1M_COPIES_SOLD_COMPILED_PATTERN)))
        else:
            flag = False
    else:
        flag = False
    logger.info(
        f"user_maybe_wants_to_talk_about_particular_game_request={flag}")
    return flag
コード例 #14
0
def my_pet_request(ngrams, vars):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    prev_active_skill = bot_uttr.get("active_skill", "")
    dontlike = re.findall(r"(do not like |don't like |hate )(cat|dog)", user_uttr["text"])
    isno = is_no(user_uttr)
    shared_memory = state_utils.get_shared_memory(vars)
    my_pet = shared_memory.get("my_pet", "")
    all_facts_used = False
    start_using_facts = False
    if my_pet:
        used_facts = shared_memory.get("used_facts", {}).get(my_pet, [])
        all_facts = MY_PET_FACTS[my_pet]
        if len(all_facts) == len(used_facts):
            all_facts_used = True
        if len(used_facts) > 0:
            start_using_facts = True
    about_users_pet = if_about_users_pet(ngrams, vars)
    if not about_users_pet and my_pet and not dontlike and not all_facts_used:
        flag = True
    if start_using_facts and prev_active_skill != "dff_animals_skill":
        flag = False
    if re.findall(r"(would you like|can tell you more)", bot_uttr["text"], re.IGNORECASE) and isno:
        flag = False
    logger.info(f"my_pet_request={flag}")
    return flag
コード例 #15
0
ファイル: generic_responses.py プロジェクト: deepmipt/deepy
def sys_response_to_speech_function_request(vars):
    flag = False

    # added check for introvert/extravert
    try:
        dialog = state_utils.get_dialog(vars)
        human_uttr_idx = len(dialog["human_utterances"])

        logger.info(f"human dialog length: {human_uttr_idx}")

        if len(dialog["human_utterances"]) > 4:
            logger.info("human utterances number: at least 5")
            if is_introvert(dialog) is True:
                logger.info("user is: introvert")
                return False

            else:
                logger.info("user is: extravert")
                human_utterance = state_utils.get_last_human_utterance(vars)
                bot_utterance = state_utils.get_last_bot_utterance(vars)
                flag = is_supported_speech_function(human_utterance,
                                                    bot_utterance)
                logger.info(f"sys_response_to_speech_function_request: {flag}")

    except Exception as exc:
        logger.exception(exc)
        logger.info(
            f"sys_response_to_speech_function_request: Exception: {exc}")
        sentry_sdk.capture_exception(exc)

    logger.info(f"sys_response_to_speech_function_request: {flag}")
    return flag
コード例 #16
0
def suggest_cook_response(vars):
    user_utt = state_utils.get_last_human_utterance(vars)
    try:
        linkto_food_skill_agreed = any(
            [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
        )
        if linkto_food_skill_agreed:
            if is_yes(user_utt) or bool(re.search(LIKE_RE, user_utt["text"].lower())):
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
                state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
            elif not is_no(user_utt):
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
            elif is_no(user_utt):
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
                return ACKNOWLEDGEMENTS["fav_food_cook"]
            else:
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
                return error_response(vars)
            return "May I recommend you a meal to try to practice cooking?"
        else:
            state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
            return error_response(vars)
    except Exception as exc:
        logger.exception(exc)
        sentry_sdk.capture_exception(exc)
        return error_response(vars)
コード例 #17
0
ファイル: wiki.py プロジェクト: deepmipt/deepy
def start_talk_request(ngrams, vars):
    flag = False
    dialog = vars["agent"]["dialog"]
    chosen_title, chosen_page_title = "", ""
    all_titles = []
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    prev_skill = bot_uttr.get("active_skill", "")
    if prev_skill != "dff_wiki_skill":
        found_entity_substr, found_entity_id, found_entity_types, found_page_title, _ = continue_after_topic_skill(
            dialog)
        if found_entity_substr and found_page_title:
            page_content, _ = get_page_content(found_page_title)
            chosen_title, chosen_page_title = get_title_info(
                vars, found_entity_substr, found_entity_types, "", [],
                page_content)
            _, _, all_titles = get_titles(found_entity_substr,
                                          found_entity_types, page_content)
        logger.info(
            f"start_talk_request, found_entity_substr {found_entity_substr} found_entity_id {found_entity_id} "
            f"found_entity_types {found_entity_types} found_page_title {found_page_title} "
            f"chosen_title {chosen_title}")
        user_uttr = state_utils.get_last_human_utterance(vars)
        isno = is_no(state_utils.get_last_human_utterance(vars))
        if chosen_title:
            flag = True
        if (user_uttr["text"].endswith("?")
                and another_topic_question(vars, all_titles)) or isno:
            flag = False
    logger.info(f"start_talk_request={flag}")
    return flag
コード例 #18
0
def drawing_request(vars):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    isyes = is_yes(user_uttr)
    if re.findall("do you like drawing", bot_uttr.get("text", "")) and isyes:
        flag = True
    return flag
コード例 #19
0
def lets_talk_about_request(ngrams, vars):
    user_lets_chat_about_music = if_chat_about_particular_topic(
        state_utils.get_last_human_utterance(vars),
        state_utils.get_last_bot_utterance(vars),
        compiled_pattern=music_words_re,
    )
    flag = bool(user_lets_chat_about_music)
    logger.info(f"lets_talk_about_request {flag}")
    return flag
コード例 #20
0
def what_cuisine_request(ngrams, vars):
    linkto_food_skill_agreed = any(
        [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
    ) and any(
        [is_yes(state_utils.get_last_human_utterance(vars)), not is_no(state_utils.get_last_human_utterance(vars))]
    )
    flag = (bool(lets_talk_about_check(vars)) or linkto_food_skill_agreed) and (not dont_want_talk(vars))
    logger.info(f"what_cuisine_request {flag}")
    return flag
コード例 #21
0
ファイル: science.py プロジェクト: deepmipt/deepy
def no_science_request(ngrams, vars):
    human_uttr_text = state_utils.get_last_human_utterance(vars).get(
        "text", "")
    bot_uttr_text = state_utils.get_last_bot_utterance(vars).get("text", "")
    if NOT_LIKE_PATTERN.search(human_uttr_text) and (
            SCIENCE_COMPILED_PATTERN.search(human_uttr_text)
            or SCIENCE_COMPILED_PATTERN.search(bot_uttr_text)):
        return True
    return False
コード例 #22
0
ファイル: science.py プロジェクト: deepmipt/deepy
def is_mentioned_science_pattern(vars,
                                 compiled_pattern=SCIENCE_COMPILED_PATTERN):
    uttr = state_utils.get_last_human_utterance(vars)
    prev_uttr = state_utils.get_last_bot_utterance(vars)
    prev_uttr = {} if prev_uttr is None else prev_uttr
    is_not_wanted = if_not_want_to_chat_about_particular_topic(uttr, prev_uttr)
    flag = bool(re.search(compiled_pattern,
                          uttr.get("text", "").lower())) and not is_not_wanted
    return flag
コード例 #23
0
ファイル: science.py プロジェクト: deepmipt/deepy
def if_chat_about_science_topic_pattern(
        vars, compiled_pattern=SCIENCE_COMPILED_PATTERN):
    uttr = state_utils.get_last_human_utterance(vars)
    prev_uttr = state_utils.get_last_bot_utterance(vars)
    prev_uttr = {} if prev_uttr is None else prev_uttr
    flag = if_chat_about_particular_topic(uttr,
                                          prev_uttr,
                                          compiled_pattern=compiled_pattern)
    return bool(flag)
コード例 #24
0
def confess_bot_never_played_game_and_ask_user_response(
        vars,
        candidate_game_id_is_already_set,
        did_user_play=False,
        how_long_user_played=False):
    if not (isinstance(did_user_play, bool)
            and isinstance(how_long_user_played, bool)
            and did_user_play + how_long_user_played == 1):
        raise ValueError(
            f"One of parameters `did_user_play` and `how_long_user_played` has to be `True` and the other"
            f"has to be `False`. did_user_play={did_user_play}, how_long_user_played={how_long_user_played}"
        )
    gaming_memory.set_current_igdb_game_id_if_game_for_discussion_is_identified(
        vars, candidate_game_id_is_already_set)
    game = gaming_memory.get_current_igdb_game(vars, assert_not_empty=False)
    if game is None:
        logger.warning(
            "No appropriate igdb game description were found. Game description could be filtered because it lacked "
            "required keys. Another cause possible cause of this situation is that local igdb saved search results "
            "do not have detected game. In such a case you should update local copy of igdb.com search results."
        )
        response = error_response(vars)
        state_utils.set_confidence(vars, confidence=common_nlg.CONF_0)
        state_utils.set_can_continue(
            vars, continue_flag=common_constants.CAN_NOT_CONTINUE)
    else:
        if "genres" not in game or not game["genres"]:
            logger.warning(f"No genre for game '{game['name']}'.")
            genres = ""
        elif len(game["genres"]) == 1:
            genres = IGDB_GAME_GENRES_FOR_REPLICAS[game["genres"][0]]
        else:
            genres = (
                f"{IGDB_GAME_GENRES_FOR_REPLICAS[game['genres'][0]]} "
                f"and {IGDB_GAME_GENRES_FOR_REPLICAS[game['genres'][1]]}")
        response = f"I've heard it is a cool {genres}. Unfortunately, I haven't tried it out. "
        if did_user_play:
            response += f"Have you ever played {game['name']}?"
        elif how_long_user_played:
            response += f"When did you start to play {game['name']}?"
        else:
            assert False
        bot_text = state_utils.get_last_bot_utterance(vars).get("text",
                                                                "").lower()
        human_uttr = state_utils.get_last_human_utterance(vars)
        flags_set = False
        if not if_chat_about_particular_topic(
                human_uttr,
                compiled_pattern=
                GAMES_WITH_AT_LEAST_1M_COPIES_SOLD_COMPILED_PATTERN):
            flags_set, response = common_nlg.maybe_set_confidence_and_continue_based_on_previous_bot_phrase(
                vars, bot_text, response)
        if not flags_set:
            state_utils.set_confidence(vars, confidence=common_nlg.CONF_1)
            state_utils.set_can_continue(
                vars, continue_flag=common_constants.MUST_CONTINUE)
    return response
コード例 #25
0
def lets_talk_about(vars, compiled_pattern):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    chat_about = if_chat_about_particular_topic(
        user_uttr, bot_uttr, compiled_pattern=compiled_pattern)
    if chat_about:
        flag = True
    return flag
コード例 #26
0
def bot_persona_fav_food_check(vars):
    flag = False
    if all(
        [
            "my favorite food is lava cake" in state_utils.get_last_bot_utterance(vars)["text"].lower(),
            fav_food_check(vars),
        ]
    ):
        flag = True
    logger.info(f"bot_persona_fav_food_check {flag}")
    return flag
コード例 #27
0
def music_mention_request(ngrams, vars):
    # has any nounphrases in phrase -> music mention
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    found_dff_wiki_phrase = any(
        [phrase in bot_uttr.get("text", "") for phrase in dff_wiki_phrases])
    flag = bool(re.search(music_words_re, user_uttr["text"]))
    flag = (flag or get_genre(vars)[0]) and not found_dff_wiki_phrase
    logger.info(f"music_mention_request {flag}")
    return flag
コード例 #28
0
def my_pets_request(ngrams, vars):
    flag = False
    bot_uttr = state_utils.get_last_bot_utterance(vars)["text"]
    isyes = is_yes(state_utils.get_last_human_utterance(vars))
    shared_memory = state_utils.get_shared_memory(vars)
    told_about_cat = shared_memory.get("told_about_cat", False)
    told_about_dog = shared_memory.get("told_about_dog", False)
    if "Would you like to learn more about my pets?" in bot_uttr and isyes and not (
            told_about_cat and told_about_dog):
        flag = True
    logger.info(f"my_pets_request={flag}")
    return flag
コード例 #29
0
ファイル: condition.py プロジェクト: deepmipt/deepy
def is_lets_chat_about_topic(vars):
    flag = is_lets_chat_about_topic_human_initiative(vars)

    last_human_uttr = state_utils.get_last_human_utterance(vars)
    last_bot_uttr_text = state_utils.get_last_bot_utterance(vars)["text"]
    is_bot_initiative = bool(
        re.search(universal_templates.COMPILE_WHAT_TO_TALK_ABOUT,
                  last_bot_uttr_text))
    flag = flag or (is_bot_initiative
                    and not common_utils.is_no(last_human_uttr))
    logging.debug(f"is_lets_chat_about_topic = {flag}")
    return flag
コード例 #30
0
def if_facts_agree(vars):
    flag = False
    user_uttr = state_utils.get_last_human_utterance(vars)
    bot_uttr = state_utils.get_last_bot_utterance(vars)
    shared_memory = state_utils.get_shared_memory(vars)
    cur_facts = shared_memory.get("cur_facts", {})
    for fact in cur_facts:
        condition = fact["cond"]
        flag = check_condition(condition, user_uttr, bot_uttr, shared_memory)
        if flag:
            break
    return flag