Example #1
0
def compose_linkto_with_connection_phrase(skills,
                                          human_attributes,
                                          recent_active_skills=None,
                                          from_skill=None):
    from_skill = "" if from_skill is None else from_skill
    linkto_dict = link_to(skills, human_attributes, recent_active_skills)
    connection = get_prelinkto_connection(
        from_skill, linkto_dict["skill"],
        human_attributes.get("prelinkto_connections", []))
    if not connection:
        connection = get_prelinkto_topic_connection(
            linkto_dict["skill"],
            human_attributes.get("prelinkto_connections", []))

    if not connection:
        # not found prelinkto connection phrase AND not found prelinkto topic phrase
        connection = get_not_used_template(
            human_attributes.get("prelinkto_connections", []),
            COMPLETELY_CHANGING_THE_SUBJECT_PHRASES)

        result = f"{connection} {linkto_dict['phrase']}"
    else:
        # we have prelinkto connection phrase OR prelinkto topic phrase
        change_topic = choice(CHANGE_TOPIC_SUBJECT).replace(
            "SUBJECT", LIST_OF_SCRIPTED_TOPICS.get(linkto_dict["skill"], "it"))
        result = f"{choice(BY_THE_WAY)} {connection} {change_topic} {linkto_dict['phrase']}"
    return {
        "phrase": result,
        "skill": linkto_dict["skill"],
        "connection_phrase": connection
    }
Example #2
0
def get_not_used_and_save_reaction_to_new_mentioned_person(vars):
    shared_memory = state_utils.get_shared_memory(vars)
    last_reactions_to_new_person = shared_memory.get(
        "last_reactions_to_new_person", [])

    reaction = common_utils.get_not_used_template(
        used_templates=last_reactions_to_new_person,
        all_templates=this_gossip.OPINION_TO_USER_MENTIONING_SOMEONE_NEW)

    used_reacts = last_reactions_to_new_person + [reaction]
    state_utils.save_to_shared_memory(
        vars, last_reactions_to_new_person=used_reacts[-2:])
    return reaction
Example #3
0
def get_not_used_and_save_sentiment_acknowledgement(vars):
    sentiment = state_utils.get_human_sentiment(vars)
    if is_yes_vars(vars) or is_no_vars(vars):
        sentiment = "neutral"

    shared_memory = state_utils.get_shared_memory(vars)
    last_acknowledgements = shared_memory.get("last_acknowledgements", [])

    ack = common_utils.get_not_used_template(
        used_templates=last_acknowledgements,
        all_templates=GENERAL_ACKNOWLEDGEMENTS[sentiment])

    used_acks = last_acknowledgements + [ack]
    state_utils.save_to_shared_memory(vars,
                                      last_acknowledgements=used_acks[-2:])
    return ack
Example #4
0
def get_not_used_and_save_generic_response(proposed_sf, vars):
    logger.info(
        f"Getting not yet used generic response for proposed speech function {proposed_sf}..."
    )
    shared_memory = state_utils.get_shared_memory(vars)
    last_responses = shared_memory.get(proposed_sf + "_last_responses", [])

    resp = common_utils.get_not_used_template(
        used_templates=last_responses,
        all_templates=current_templates.
        GENERIC_REACTION_TO_USER_SPEECH_FUNCTION[proposed_sf],
    )

    used_resp = last_responses + [resp]
    state_utils.save_to_shared_memory(vars, last_responses=used_resp[-2:])
    return resp
Example #5
0
def recommend_movie_of_genre(genre, discussed_movie_ids=None):
    discussed_movie_ids = discussed_movie_ids if discussed_movie_ids is not None else []

    # let's convert genre from `criminal` to `Crime` (standard IMDb genre)
    for capitalized_genre in GENRES:
        if genre.lower() in GENRES[capitalized_genre]:
            genre = capitalized_genre

    # randomly pick up not discussed movie
    if RECOMMENDATIONS.get(genre, []):
        # because in RECOMMENDATIONS file imdb ids are started from tt, but in our case we store only digits
        available_ids = [pair[0][2:] for pair in RECOMMENDATIONS[genre]]
        return get_not_used_template(discussed_movie_ids,
                                     available_ids,
                                     any_if_no_available=False)

    return ""
Example #6
0
def get_not_used_and_save_sentiment_acknowledgement(ctx: Context,
                                                    actor: Actor,
                                                    sentiment=None):
    if sentiment is None:
        sentiment = int_ctx.get_human_sentiment(ctx, actor)
        if is_yes_vars(ctx, actor) or is_no_vars(ctx, actor):
            sentiment = "neutral"

    shared_memory = int_ctx.get_shared_memory(ctx, actor)
    last_acknowledgements = shared_memory.get("last_acknowledgements", [])

    ack = common_utils.get_not_used_template(
        used_templates=last_acknowledgements,
        all_templates=GENERAL_ACKNOWLEDGEMENTS[sentiment])

    used_acks = last_acknowledgements + [ack]
    int_ctx.save_to_shared_memory(ctx,
                                  actor,
                                  last_acknowledgements=used_acks[-2:])
    return ack
Example #7
0
def get_prelinkto_topic_connection(to_skill, used_templates):
    if to_skill in PRELINKTO_TOPIC_PHRASES:
        return get_not_used_template(used_templates,
                                     PRELINKTO_TOPIC_PHRASES[to_skill])
    return ""
Example #8
0
def get_prelinkto_connection(from_skill, to_skill, used_templates):
    skill_pair = sorted([from_skill, to_skill])
    for el in PRELINKTO_CONNECTION_PHRASES:
        if el.get("skill_pair") == skill_pair and el.get("phrases"):
            return get_not_used_template(used_templates, el["phrases"])
    return ""