Ejemplo n.º 1
0
def no_requests(ctx: Context, actor: Actor) -> bool:
    """Function to determine if
    - user didn't asked to switch topic,
    - user didn't ask to talk about something particular,
    - user didn't requested high priority intents (like what_is_your_name)
    - user didn't requested any special intents
    - user didn't ask questions
    """
    contain_no_special_requests = no_special_switch_off_requests(ctx, actor)

    request_intents = [
        "opinion_request",
        "topic_switching",
        "lets_chat_about",
        "what_are_you_talking_about",
        "Information_RequestIntent",
        "Topic_SwitchIntent",
        "Opinion_RequestIntent",
    ]
    intents = common_utils.get_intents(int_ctx.get_last_human_utterance(
        ctx, actor),
                                       which="all")
    is_not_request_intent = all(
        [intent not in request_intents for intent in intents])
    is_no_question = "?" not in int_ctx.get_last_human_utterance(ctx,
                                                                 actor)["text"]

    if contain_no_special_requests and is_not_request_intent and is_no_question:
        return True
    return False
Ejemplo n.º 2
0
def false_positive_condition(ctx: Context, actor: Actor, *args,
                             **kwargs) -> bool:
    flag = (bool(
        re.search(common_greeting.FALSE_POSITIVE_TURN_ON_RE,
                  int_ctx.get_last_human_utterance(ctx, actor)["text"]))
            and int_ctx.get_human_utter_index(ctx, actor) == 0)
    return flag
Ejemplo n.º 3
0
def sys_played_computer_game_condition(ctx: Context, actor: Actor, *args,
                                       **kwargs) -> bool:
    human_text = int_ctx.get_last_human_utterance(ctx, actor)["text"]
    flag = bool(
        re.search(played_computer_game_patterns_1_re, human_text)
        and re.search(played_computer_game_patterns_2_re, human_text))
    return flag
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
def set_conf_and_can_cont_by_universal_policy(ctx: Context, actor: Actor):
    DIALOG_BEGINNING_START_CONFIDENCE = 0.98
    DIALOG_BEGINNING_CONTINUE_CONFIDENCE = 0.9
    DIALOG_BEGINNING_SHORT_ANSWER_CONFIDENCE = 0.98
    MIDDLE_DIALOG_START_CONFIDENCE = 0.7

    if not is_begin_of_dialog(ctx, actor, begin_dialog_n=10):
        confidence = 0.0
        can_continue_flag = CAN_NOT_CONTINUE
    elif is_first_our_response(ctx, actor):
        confidence = DIALOG_BEGINNING_START_CONFIDENCE
        can_continue_flag = CAN_CONTINUE_SCENARIO
    elif not is_interrupted(ctx,
                            actor) and common_greeting.dont_tell_you_answer(
                                int_ctx.get_last_human_utterance(ctx, actor)):
        confidence = DIALOG_BEGINNING_SHORT_ANSWER_CONFIDENCE
        can_continue_flag = CAN_CONTINUE_SCENARIO
    elif not is_interrupted(ctx, actor):
        confidence = DIALOG_BEGINNING_CONTINUE_CONFIDENCE
        can_continue_flag = CAN_CONTINUE_SCENARIO
    else:
        confidence = MIDDLE_DIALOG_START_CONFIDENCE
        can_continue_flag = CAN_CONTINUE_SCENARIO

    int_ctx.set_can_continue(ctx, actor, can_continue_flag)
    int_ctx.set_confidence(ctx, actor, confidence)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def set_confidence_from_input(ctx: Context, actor: Actor, *args, **kwargs) -> Context:
    intent, confidence = get_detected_intents(int_ctx.get_last_human_utterance(ctx, actor))
    if intent in high_priority_intents["dff_intent_responder_skill"]:
        int_ctx.set_confidence(ctx, actor, 1.0)
    else:
        int_ctx.set_confidence(ctx, actor, confidence)
    return ctx
Ejemplo n.º 8
0
def intent_catcher_response(ctx: Context, actor: Actor, *args, **kwargs) -> str:
    annotated_utterance = int_ctx.get_last_human_utterance(ctx, actor)
    intention, confidence = get_detected_intents(annotated_utterance)

    response = ""
    if intention is not None and confidence > 0:
        logger.debug(f"Intent is defined as {intention}")
        dialog = int_ctx.get_dialog(ctx, actor)
        dialog["seen"] = dialog["called_intents"][intention]
        funcs = response_funcs.get_respond_funcs()[intention]
        response = funcs(ctx, actor, intention)
        # Special formatter which used in AWS Lambda to identify what was the intent
        while "#+#" in response:
            response = response[: response.rfind(" #+#")]
        logger.info(f"Response: {response}; intent_name: {intention}")
        try:
            response += " #+#{}".format(intention)
        except TypeError:
            logger.error(f"TypeError intent_name: {intention} response: {response};")
            response = "Hmmm... #+#{}".format(intention)
        # todo: we need to know what intent was called
        # current workaround is to use only one intent if several were detected
        # and to append special token with intent_name
    else:
        logger.debug("Intent is not defined")

    if response == "":
        logger.error(f"response is empty for intents: {get_intents(annotated_utterance).items()}")

    return response
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def is_side_or_stop(ctx: Context, actor: Actor) -> bool:
    """
    Check for side intents (including exit)
    """
    intents = set(get_intents(int_ctx.get_last_human_utterance(ctx, actor), which="intent_catcher", probs=False))
    side_intent_present = len(intents.intersection(SIDE_INTENTS)) > 0
    logger.debug("Side intent detected, exiting")
    return side_intent_present
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def is_no_human_abandon(ctx: Context, actor: Actor) -> bool:
    """Is dialog breakdown in human utterance or no. Uses MIDAS hold/abandon classes."""
    midas_classes = common_utils.get_intents(int_ctx.get_last_human_utterance(
        ctx, actor),
                                             which="midas")
    if "abandon" not in midas_classes:
        return True
    return False
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def intent_catcher_exists_condition(ctx: Context, actor: Actor, *args,
                                    **kwargs) -> bool:
    if ctx.validation:
        return False

    intents_by_catcher = common_utils.get_intents(
        int_ctx.get_last_human_utterance(ctx, actor),
        probs=False,
        which="intent_catcher",
    )

    response_funcs = get_respond_funcs()
    return bool(
        any([intent in response_funcs for intent in intents_by_catcher]))
Ejemplo n.º 17
0
def thematic_funfact_response(ctx: Context, actor: Actor, *args, **kwargs) -> str:
    response = ""
    set_confidence(ctx, actor, CONF_HIGH)
    set_can_continue(ctx, actor, MUST_CONTINUE)
    entity = ctx.last_request.split("about")
    if len(entity) > 1:
        entity = entity[1]
        human_utter = get_last_human_utterance(ctx, actor)
        topic = get_topics(human_utter, which="cobot_topics")[0]
        funfact = get_fact(entity, f"fact about {entity}")
        if funfact:
            link_question = make_question(topic)
            response = f"{funfact} {link_question}"
    if not response:
        set_confidence(ctx, actor, CONF_ZERO)
    return response
Ejemplo n.º 18
0
def forecast_response(ctx: Context, actor: Actor, *args, **kwargs) -> str:
    location_name = ""
    if homeland_forecast_requested_condition(ctx, actor):
        dialog = get_dialog(ctx, actor)
        if "human" in dialog and "profile" in dialog["human"]:
            location_name = dialog["human"]["profile"].get("location", "")
    else:
        human_utter = get_last_human_utterance(ctx, actor)
        location_name = retrieve_location_entity_from_utterance(human_utter)
    if location_name:
        forecast_intent_processing(ctx, actor)
        response = f"{request_weather_service(location_name)}. {QUESTION_PHRASE}"
    else:
        set_can_continue(ctx, actor, CAN_CONTINUE_SCENARIO)
        set_confidence(ctx, actor, MISSED_CITY_CONF)
        response = SORRY_PHRASE
    return response
Ejemplo n.º 19
0
def no_special_switch_off_requests(ctx: Context, actor: Actor) -> bool:
    """Function to determine if
    - user didn't asked to switch topic,
    - user didn't ask to talk about something particular,
    - user didn't requested high priority intents (like what_is_your_name)
    """
    intents_by_catcher = common_utils.get_intents(
        int_ctx.get_last_human_utterance(ctx, actor),
        probs=False,
        which="intent_catcher")
    is_high_priority_intent = any([
        intent not in common_utils.service_intents
        for intent in intents_by_catcher
    ])
    is_switch = is_switch_topic(ctx, actor)
    is_lets_chat = is_lets_chat_about_topic_human_initiative(ctx, actor)

    if not (is_high_priority_intent or is_switch or is_lets_chat):
        return True
    return False
Ejemplo n.º 20
0
def is_question(ctx: Context, actor: Actor) -> bool:
    text = int_ctx.get_last_human_utterance(ctx, actor)["text"]
    flag = common_utils.is_question(text)
    logger.debug(f"is_question = {flag}")
    return bool(flag)
Ejemplo n.º 21
0
def sys_feel_great_condition(ctx: Context, actor: Actor, *args,
                             **kwargs) -> bool:
    human_utterance = int_ctx.get_last_human_utterance(ctx, actor)

    flag = common_utils.is_no(human_utterance)
    return flag
Ejemplo n.º 22
0
def is_opinion_expression(ctx: Context, actor: Actor) -> bool:
    flag = common_utils.is_opinion_expression(
        int_ctx.get_last_human_utterance(ctx, actor))
    logger.debug(f"is_opinion_expression = {flag}")
    return bool(flag)
Ejemplo n.º 23
0
def is_switch_topic(ctx: Context, actor: Actor) -> bool:
    flag = universal_templates.is_switch_topic(
        int_ctx.get_last_human_utterance(ctx, actor))
    logger.debug(f"is_switch_topic = {flag}")
    return bool(flag)
Ejemplo n.º 24
0
def request_with_location_condition(ctx: Context, actor: Actor, *args,
                                    **kwargs) -> bool:
    human_utter = get_last_human_utterance(ctx, actor)
    location_name = retrieve_location_entity_from_utterance(human_utter)
    return bool(location_name)
Ejemplo n.º 25
0
def is_do_not_know_vars(ctx: Context, actor: Actor) -> bool:
    flag = True
    flag = flag and common_utils.is_donot_know(
        int_ctx.get_last_human_utterance(ctx, actor))
    return bool(flag)
Ejemplo n.º 26
0
def sys_slept_in_condition(ctx: Context, actor: Actor, *args,
                           **kwargs) -> bool:
    human_text = int_ctx.get_last_human_utterance(ctx, actor)["text"]

    flag = "slept" in human_text
    return flag
Ejemplo n.º 27
0
def art_skill_switch(ctx: Context, actor: Actor) -> bool:
    user_uttr = int_ctx.get_last_human_utterance(ctx, actor)
    return re.findall(ART_PATTERN, user_uttr["text"])
Ejemplo n.º 28
0
def sys_play_regularly_condition(ctx: Context, actor: Actor, *args,
                                 **kwargs) -> bool:
    human_utterance = int_ctx.get_last_human_utterance(ctx, actor)

    flag = common_utils.is_yes(human_utterance)
    return flag
Ejemplo n.º 29
0
def sys_play_on_weekends_condition(ctx: Context, actor: Actor, *args,
                                   **kwargs) -> bool:
    human_utterance = int_ctx.get_last_human_utterance(ctx, actor)

    flag = bool(was_game_mentioned(human_utterance))
    return flag
Ejemplo n.º 30
0
def sys_cleaned_up_condition(ctx: Context, actor: Actor, *args,
                             **kwargs) -> bool:
    human_text = int_ctx.get_last_human_utterance(ctx, actor)["text"]

    flag = bool(re.search(cleaned_up_patterns_re, human_text))
    return flag