示例#1
0
def list_goal_helper(user_id):
    goal_list = dynamo_helper.list_goals(user_id)

    if len(goal_list) == 0:
        speech_text = "You do not have any active goals. Create a new goal by saying something like: 'I want to go to the gym today'"
    else:
        if len(goal_list) == 1:
            speech_text = "Your goal is to " + goal_list[0]
        else:
            speech_text = "Your goals are to "
            for ind, goal in enumerate(goal_list):
                if ind == len(goal_list) - 1:
                    speech_text += "and " + goal
                else:
                    speech_text += goal + ", "

    return speech_text
示例#2
0
def complete_goal_helper(user_id, slots):
    # the goal slot in the intent should be required
    if slots is None:
        # should not happen, but check here in case this intent somehow gets called
        speech_text = "Sorry, I did not understand what you said there. Can you say it again or word it differently?"
    else:
        goal_list = dynamo_helper.list_goals(user_id)
        if len(goal_list) == 0:
            speech_text = "Sorry you do not have any active goals to complete"
        else:
            # If you can connect to tensor flow model use that, otherwise use language_helper
            # This is gross and should probably be made into its own method but ¯\_(ツ)_/¯
            try:
                similarity_list = similarity_helper.match_similarity_with_list(
                    slots['Goal'].value, goal_list)
                if similarity_list is not None and similarity_list[0][
                        0] is not None and similarity_list[0][1] is not None:
                    print("Using similarity server")
                    most_similar_string = similarity_list[0][0]
                    similar_value = similarity_list[0][1]
                else:
                    most_similar_string, similar_value = language_helper.get_most_similar_string(
                        slots['Goal'].value, goal_list)
                    print("Most similar string: ", most_similar_string)
                    print("Similarity value: ", similar_value)
            except Exception as e:
                most_similar_string, similar_value = language_helper.get_most_similar_string(
                    slots['Goal'].value, goal_list)

            # Check here right now just in case we dont want to return something if they say something that is not like
            # one of their goals
            if similar_value >= 0.6:
                goal_description = most_similar_string
                dynamo_helper.update_goal_status(user_id, goal_description,
                                                 "COMPLETED")
                speech_text = "I have marked your goal to " + goal_description + " as completed. " + congrats[
                    random.randint(0,
                                   len(congrats) - 1)]
            else:
                # Maybe if we get here, we could ask if we should list the goals (add info to session_attributes)
                speech_text = "Sorry, you do not have a goal to " + slots[
                    'Goal'].value + ". You can ask me to list your goals if you want."

    return speech_text
示例#3
0
def retrieve_goal_to_delete_helper(user_id, slots):
    # the goal slot in the intent should be required
    if slots is None:
        # should not happen, but check here in case this intent somehow gets called
        speech_text = "Sorry, I did not understand what you said there. Can you say it again or word it differently?"
        goal_description = None
    else:
        goal_list = dynamo_helper.list_goals(user_id)
        if len(goal_list) == 0:
            speech_text = "Sorry you do not have any active goals to delete"
            goal_description = None
        else:
            # If you can connect to tensor flow model use that, otherwise use language_helper
            try:
                similarity_list = similarity_helper.match_similarity_with_list(
                    slots['Goal'].value, goal_list)
                if similarity_list is not None and similarity_list[0][
                        0] is not None and similarity_list[0][1] is not None:
                    print("Using similarity server")
                    most_similar_string = similarity_list[0][0]
                    similar_value = similarity_list[0][1]
                else:
                    most_similar_string, similar_value = language_helper.get_most_similar_string(
                        slots['Goal'].value, goal_list)
                    print("Most similar string: ", most_similar_string)
                    print("Similarity value: ", similar_value)
            except Exception as e:
                most_similar_string, similar_value = language_helper.get_most_similar_string(
                    slots['Goal'].value, goal_list)

            # Check here right now just in case we dont want to return something if they say something that is not like
            # one of their goals
            if similar_value >= 0.6:
                speech_text = "Are you sure you want me to delete your goal to " + most_similar_string + "?"
                goal_description = most_similar_string
            else:
                # Maybe if we get here, we could ask if we should list the goals (add info to session_attributes)
                speech_text = "Sorry, you do not have a goal to " + slots[
                    'Goal'].value + ". You can ask me to list your goals if you want."
                goal_description = None

    return speech_text, goal_description
示例#4
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response

        user_id = handler_input.request_envelope.session.user.user_id[18:]

        goal_list = dynamo_helper.list_goals(user_id)
        completed_goal_list = dynamo_helper.list_goals_with_status(
            user_id, "COMPLETED")
        journal_entries = journal_helper.get_all_entries(user_id)

        all_text = ""

        for goal in goal_list:
            all_text = all_text + goal + " "
        for goal in completed_goal_list:
            all_text = all_text + goal + " "
        for journal_entry in journal_entries:
            all_text = all_text + journal_entry["text"] + " "

        if all_text == "":
            speech_text = "You don't have any journal entries or goals. Add some so we know more about you."
        else:
            user_sentiment = sentiment_helper.sentiment_with_threshold(
                all_text)

            if user_sentiment == "HAPPY":
                speech_text = "You've been very happy. Keep it up! You're a positive force in the universe!"
            elif user_sentiment == "SLIGHTLY_HAPPY":
                speech_text = "You've been quite happy. That's pretty good."
            elif user_sentiment == "NEUTRAL":
                speech_text = "You've been feeling neutral. I have no feelings about this, one way or another."
            elif user_sentiment == "SLIGHTLY_SAD":
                speech_text = "It seems like you've been a little under the weather. That's okay. Tomorrow's a new day."
            elif user_sentiment == "SAD":
                speech_text = "It seems like you have not been feeling good. That's okay. Everybody feels sad " \
                              "sometimes."
        card_text = speech_text
        clearSessionAttributes(handler_input)
        return speech_helper.build_response(handler_input, card_title,
                                            card_text, speech_text)
示例#5
0
    def handle(self, handler_input):
        user_id = handler_input.request_envelope.session.user.user_id[18:]

        goal_list = dynamo_helper.list_goals(user_id)
        completed_goal_list = dynamo_helper.list_goals_with_status(
            user_id, "COMPLETED")
        journal_entries = journal_helper.get_all_entries(user_id)

        all_text = ""
        user_sentiment = ""

        for goal in goal_list:
            all_text = all_text + goal + " "
        for goal in completed_goal_list:
            all_text = all_text + goal + " "
        for journal_entry in journal_entries:
            all_text = all_text + journal_entry["text"] + " "

        if all_text == "":
            speech_text = "You don't have any journal entries or goals. Tell me more about yourself so I can give you relevant advice"
        else:
            user_sentiment = sentiment_helper.sentiment_with_threshold(
                all_text)

        if user_sentiment != "":
            query_word = sentiment_helper.get_query_word_from_sentiment(
                user_sentiment)
            handler_input.attributes_manager.session_attributes[
                LAST_QUERY_SESSION_ATTRIBUTE] = query_word
            queryResults = discovery_helper.query(query_word)
            print('query results:', queryResults)
            if queryResults is not None and isinstance(queryResults,
                                                       (tuple, list)):
                passage = queryResults[0]
                docId = queryResults[1]
                queryId = queryResults[2]
                author = queryResults[3]

                speech_text = passage + "<break time='1s'/> Was that helpful?"
                card_text = passage + "\nWas that helpful?"
                handler_input.attributes_manager.session_attributes[
                    LAST_QUERY_ID_SESSION_ATTRIBUTE] = queryId
                print('session attributes:',
                      handler_input.attributes_manager.session_attributes)
                handler_input.attributes_manager.session_attributes[
                    LAST_DOCUMENT_ID_SESSION_ATTRIBUTE] = docId
                handler_input.attributes_manager.session_attributes[
                    LAST_AUTHOR_SESSION_ATTRIBUTE] = author
                print('session attributes:',
                      handler_input.attributes_manager.session_attributes)
            elif queryResults is not None and isinstance(queryResults, str):
                speech_text = queryResults
                card_text = speech_text
                handler_input.attributes_manager.session_attributes[
                    LAST_AUTHOR_SESSION_ATTRIBUTE] = None
            else:
                speech_text = 'Ask me later when you have used the skill more'
                card_text = speech_text

            clearSessionAttributes(handler_input, deleteQueryID=False)
        else:
            card_text = speech_text

        return speech_helper.build_response(handler_input, card_title,
                                            card_text, speech_text)