def offered_topic_choice_declined_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: prev_bot_uttr = int_ctx.get_last_bot_utterance(ctx, actor)["text"] # asked what to talk about shared_memory = int_ctx.get_shared_memory(ctx, actor) greeting_step_id = shared_memory.get("greeting_step_id", 0) was_linking_topic_offering = (GREETING_STEPS[greeting_step_id - 1] == "what_to_talk_about" if greeting_step_id > 0 else False) user_asked_for_topic = any([ resp.lower() in prev_bot_uttr.lower() for resp in common_greeting.GREETING_QUESTIONS["what_to_talk_about"] ]) was_active = "dff_friendship_skill" == int_ctx.get_last_bot_utterance( ctx, actor).get("active_skill", "") # offered choice between two topics offered_topics = shared_memory.get("offered_topics", []) # and user declined declined = int_cnd.is_no_vars(ctx, actor) if was_active and offered_topics and was_linking_topic_offering and not user_asked_for_topic and declined: # was offered particular linking question, and user said no return True return False
def is_lets_chat_about_topic_human_initiative(ctx: Context, actor: Actor) -> bool: flag = universal_templates.if_chat_about_particular_topic( int_ctx.get_last_human_utterance(ctx, actor), int_ctx.get_last_bot_utterance(ctx, actor)) logger.debug(f"is_lets_chat_about_topic_human_initiative = {flag}") return bool(flag)
def chat_about_weather_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: human_utter = get_last_human_utterance(ctx, actor) bot_utter = get_last_bot_utterance(ctx, actor) return bool( if_chat_about_particular_topic( human_utter, bot_utter, compiled_pattern=WEATHER_COMPILED_PATTERN))
def set_start_confidence(ctx: Context, actor: Actor) -> Context: user_uttr = int_ctx.get_last_human_utterance(ctx, actor) bot_uttr = int_ctx.get_last_bot_utterance(ctx, actor) if if_chat_about_particular_topic(user_uttr, bot_uttr, compiled_pattern=ART_PATTERN): int_ctx.set_confidence(ctx, actor, SUPER_CONFIDENCE) elif re.findall(ART_PATTERN, user_uttr["text"]): int_ctx.set_confidence(ctx, actor, HIGH_CONFIDENCE) return ctx
def was_what_do_you_do_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: bot_uttr_text = int_ctx.get_last_bot_utterance(ctx, actor).get("text", "") if int_cnd.no_requests(ctx, actor) and any([ phrase in bot_uttr_text for phrase in common_greeting.GREETING_QUESTIONS["what_do_you_do_on_weekdays"] ]): return True return False
def how_are_you_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: prev_frindship_skill = int_ctx.get_last_bot_utterance(ctx, actor).get( "active_skill", "") == "dff_friendship_skill" how_are_you_found = common_greeting.HOW_ARE_YOU_TEMPLATE.search( int_ctx.get_last_human_utterance(ctx, actor)["text"]) how_are_you_precise_found = common_greeting.HOW_ARE_YOU_PRECISE_TEMPLATE.search( int_ctx.get_last_human_utterance(ctx, actor)["text"]) how_are_you_by_bot_found = common_greeting.HOW_ARE_YOU_TEMPLATE.search( int_ctx.get_last_bot_utterance(ctx, actor)["text"]) any_you_in_user = common_greeting.ANY_YOU_TEMPLATE.search( int_ctx.get_last_human_utterance(ctx, actor)["text"]) if how_are_you_precise_found: return True elif prev_frindship_skill and (how_are_you_found or (how_are_you_by_bot_found and any_you_in_user)): return True return False
def std_weekend_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: human_text = int_ctx.get_last_human_utterance(ctx, actor)["text"] prev_was_about_topic = common_universal_templates.if_utterance_requests_topic( int_ctx.get_last_bot_utterance(ctx, actor)) anything = re.search(re_patterns_human, human_text) flag = bool(prev_was_about_topic and anything) return flag
def is_lets_chat_about_topic(ctx: Context, actor: Actor) -> bool: flag = is_lets_chat_about_topic_human_initiative(ctx, actor) last_human_uttr = int_ctx.get_last_human_utterance(ctx, actor) last_bot_uttr_text = int_ctx.get_last_bot_utterance(ctx, actor)["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)) logger.debug(f"is_lets_chat_about_topic = {flag}") return bool(flag)
def asked_for_events_and_got_yes_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: prev_bot_uttr = int_ctx.get_last_bot_utterance(ctx, actor).get("text", "") was_event_question = any([ resp.lower() in prev_bot_uttr.lower() for resp in common_greeting.GREETING_QUESTIONS["recent_personal_events"] ]) agreed = int_cnd.is_yes_vars(ctx, actor) entities = int_ctx.get_nounphrases_from_human_utterance(ctx, actor) if was_event_question and agreed and len(entities) == 0: return True return False
def positive_or_negative_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: # SYS_USR_ANSWERS_HOW_IS_HE_DOING usr_sentiment = int_ctx.get_human_sentiment(ctx, actor) pos_temp = is_positive_regexp_based( int_ctx.get_last_human_utterance(ctx, actor)) neg_temp = is_negative_regexp_based( int_ctx.get_last_human_utterance(ctx, actor)) bot_asked_how_are_you = any([ resp in int_ctx.get_last_bot_utterance(ctx, actor)["text"] for resp in common_greeting.HOW_ARE_YOU_RESPONSES ]) if bot_asked_how_are_you and (usr_sentiment in ["positive", "negative"] or pos_temp or neg_temp): return True return False
def homeland_forecast_requested_condition(ctx: Context, actor: Actor, *args, **kwargs) -> bool: human_utter = get_last_human_utterance(ctx, actor) bot_utter = get_last_bot_utterance(ctx, actor) return bool(is_weather_for_homeland_requested(bot_utter, human_utter))
def is_proposed_skill(ctx: Context, actor: Actor) -> bool: return book_skill_was_proposed(int_ctx.get_last_bot_utterance(ctx, actor))
def start_condition(ctx: Context, actor: Actor) -> bool: return if_chat_about_particular_topic( int_ctx.get_last_human_utterance(ctx, actor), int_ctx.get_last_bot_utterance(ctx, actor), compiled_pattern=BOOK_PATTERN, )