def get_comparision_instructions(intent_request, session, answer_intent=False):
    # print "yesy"
    intent_attributes = get_intent_attributes(intent_request, session,
                                              answer_intent)
    if (intent_attributes["Comparision_a"]
            == "NONE") & (intent_attributes["Comparision_b"] != "NONE"):
        outputSpeech_text = "With what do you want to compare " + intent_attributes[
            "Comparision_b"]
        repromt_outputSpeech_text = "Please tell me with what do you want to compare " + intent_attributes[
            "Comparision_b"]
        session_attributes = get_session_attributes(
            previous_intent="Comparision_Intent",
            previous_intent_attributes=intent_attributes,
            requested_value="Comparision_a")
        response = get_response(
            outputSpeech_text=outputSpeech_text,
            repromt_outputSpeech_text=repromt_outputSpeech_text,
            shouldEndSession=False)
    elif (intent_attributes["Comparision_a"] !=
          "NONE") & (intent_attributes["Comparision_b"] == "NONE"):
        outputSpeech_text = "With what do you want to compare " + intent_attributes[
            "Comparision_a"]
        repromt_outputSpeech_text = "Please tell me with what do you want to compare " + intent_attributes[
            "Comparision_a"]
        session_attributes = get_session_attributes(
            previous_intent="Comparision_Intent",
            previous_intent_attributes=intent_attributes,
            requested_value="Comparision_b")
        response = get_response(
            outputSpeech_text=outputSpeech_text,
            repromt_outputSpeech_text=repromt_outputSpeech_text,
            shouldEndSession=False)
    elif (intent_attributes["Comparision_a"]
          == "NONE") & (intent_attributes["Comparision_b"] == "NONE"):
        outputSpeech_text = "What do you want to compare."
        session_attributes = get_session_attributes(
            previous_intent="Comparision_Intent",
            previous_intent_attributes=intent_attributes,
            requested_value="Comparision_a")
        response = get_response(outputSpeech_text=outputSpeech_text,
                                shouldEndSession=False)
    else:
        query = "xwhich is better " + intent_attributes[
            "Comparision_a"] + " or " + intent_attributes["Comparision_b"]
        return all_response(query=query,
                            session=session,
                            intent_request=intent_request)
    return give_response(response=response,
                         session_attributes=session_attributes)
def next_related_question(session):
    outputSpeech_text = "Do you want me to go to next related question?"
    shouldEndSession = False
    repromt_outputSpeech_text = "Do you want me to go to next related question?"
    session_attributes = get_session_attributes(requested_value="next_question", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"])
    response = get_response(outputSpeech_text = outputSpeech_text, repromt_outputSpeech_text = repromt_outputSpeech_text, shouldEndSession = shouldEndSession)
    return response, session_attributes
예제 #3
0
def get_welcome_response():
    response_text = "Hi! I am Ginger, I can help you correct your english. Try me by saying correct the statement"
    response = get_response(outputSpeech_text=response_text,
                            shouldEndSession=False)
    session_attributes = get_session_attributes()
    return give_response(response=response,
                         session_attributes=session_attributes)
예제 #4
0
def get_helping_instructions():
    outputSpeech_text = "I can help you correct your english. Try me by saying correct the statement"
    response = get_response(outputSpeech_text=outputSpeech_text,
                            shouldEndSession=False)
    session_attributes = get_session_attributes()
    return give_response(response=response,
                         session_attributes=session_attributes)
예제 #5
0
def get_helping_instructions():
    outputSpeech_text = "You can ask me any programming related query or any library install or remove instructions. For example, What is indentation error or how to install pandas in ubuntu or how to remove android studio"
    response = get_response(outputSpeech_text=outputSpeech_text,
                            shouldEndSession=False)
    session_attributes = get_session_attributes()
    return give_response(response=response,
                         session_attributes=session_attributes)
def give_answer(session, is_repeat = False):
    if is_repeat == True:
        answer = session["attributes"]["complete_answer"]
        session["attributes"]["answer_now_id"] = session["attributes"]["answer_now_id"] - 1
    else:
        answer = search_answer(session["attributes"]["questions_urls"][session["attributes"]["question_now_id"] - 1], session["attributes"]["answers_ids"], session["attributes"]["answer_now_id"])
    if (answer["comment"] != ""):
        outputSpeech_text = answer["answer_text"] + " or do you want me to repeat the answer"
        shouldEndSession = False
        repromt_outputSpeech_text = "Please answer yes or no to get comments or say repeat to repeat the answer again."
        session_attributes = get_session_attributes(requested_value = "give_comment", previous_requested_value = "give_answer", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], answers_ids = session["attributes"]["answers_ids"], answer_now_id = session["attributes"]["answer_now_id"] + 1, complete_answer = answer)
    else:
        outputSpeech_text = answer["answer_text"]
        if session["attributes"]["answer_now_id"] == len(session["attributes"]["answers_ids"]) - 1:
            if session["attributes"]["question_now_id"] < len(session["attributes"]["questions_urls"]):
                outputSpeech_text = outputSpeech_text + " Do you want me to go to next related question? or do you want me to repeat the answer?"
                shouldEndSession = False
                repromt_outputSpeech_text = "Please answer yes or no to go to next related question or say repeat to repeat the answer again."
                session_attributes = get_session_attributes(requested_value = "next_question", previous_requested_value = "give_answer", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], complete_answer = answer)
            else:
                shouldEndSession = True
                repromt_outputSpeech_text = ""
                session_attributes = get_session_attributes()
        else:
            outputSpeech_text = outputSpeech_text + " Do you want me to go to next answer to the question? or do you want me to repeat the answer?"
            shouldEndSession = False
            repromt_outputSpeech_text = "Please answer yes or no to go to next answer or say repeat to repeat the answer again."
            session_attributes = get_session_attributes(requested_value = "give_answer", previous_requested_value = "give_answer", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], answers_ids = session["attributes"]["answers_ids"], answer_now_id = session["attributes"]["answer_now_id"] + 1, complete_answer = answer)
    response = get_response(outputSpeech_text = outputSpeech_text, card_title = session["attributes"]["question_name"], card_content = "code", card_text = answer["card"], shouldEndSession = shouldEndSession, repromt_outputSpeech_text = repromt_outputSpeech_text)
    return response, session_attributes
def next_related_answer(session):
    outputSpeech_text = "Do you want me to go to next answer to the question?"
    shouldEndSession = False
    repromt_outputSpeech_text = "Do you want me to go to next answer to the question?"
    session_attributes = get_session_attributes(requested_value = "give_answer", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], answers_ids = session["attributes"]["answers_ids"], answer_now_id = session["attributes"]["answer_now_id"])
    response = get_response(outputSpeech_text = outputSpeech_text, repromt_outputSpeech_text = repromt_outputSpeech_text, shouldEndSession = shouldEndSession)
    return response, session_attributes
예제 #8
0
def get_welcome_response():
    response_text = "Hi! I am from stack overflow, I can help you with any programming query!"
    # card_title = "Title of the card"
    # card_content = "Content of a simple card"
    # card_text = "Text content for a standard card"
    response = get_response(outputSpeech_text = response_text, shouldEndSession = False)
    session_attributes = get_session_attributes()
    return give_response(response = response, session_attributes = session_attributes)
예제 #9
0
def get_remove_instructions(intent_request, session, answer_intent = False):
    print "yesy"
    intent_attributes = get_intent_attributes(intent_request, session, answer_intent)
    if intent_attributes["library_name"] == "NONE":
        outputSpeech_text = "Which library do you want to remove."
        repromt_outputSpeech_text="Please tell which library do you want to remove."
        session_attributes = get_session_attributes(previous_intent = "library_remove_Intent", previous_intent_attributes = intent_attributes, requested_value = "library_name")
        response = get_response(outputSpeech_text = outputSpeech_text, repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = False)
    elif intent_attributes["operating_system"] == "NONE":
        outputSpeech_text = "From which operating system do you like to remove " + intent_attributes["library_name"]
        repromt_outputSpeech_text = "Please tell from which operating system do you like to remove " + intent_attributes["library_name"]
        session_attributes = get_session_attributes(previous_intent = "library_remove_Intent", previous_intent_attributes = intent_attributes, requested_value = "operating_system")
        response = get_response(outputSpeech_text = outputSpeech_text,  repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = False)
    else:
        query = "stackoverflow how to remove " + intent_attributes["library_name"] + " from " + intent_attributes["operating_system"]
        return all_response(query = query, session = session, intent_request = intent_request)
    return give_response(response = response, session_attributes = session_attributes)
def required_response(session):
    if session["attributes"]["previous_requested_value"] != "":
        outputSpeech_text = "Please provide your response in yes, no or repeat only"
    else:
        outputSpeech_text = "Please provide your response in yes or no only"
    shouldEndSession = False
    session_attributes = session["attributes"]
    response = get_response(outputSpeech_text = outputSpeech_text, repromt_outputSpeech_text = outputSpeech_text, shouldEndSession = shouldEndSession)
    return response, session_attributes
def next_question(questions_urls, id_number):
    answers_ids, question_now_id_id, question_name, question_now_id = search_name(questions_urls, id_number)
    if answers_ids != 0:
        outputSpeech_text = "Are you looking for " + question_name
        shouldEndSession = False
        repromt_outputSpeech_text = "Please answer yes or no or repeat"
        session_attributes = get_session_attributes(requested_value = "give_answer", previous_requested_value = "next_question", questions_urls = questions_urls, question_now_id = question_now_id, question_name = question_name, answers_ids=answers_ids)
        response = get_response(outputSpeech_text = outputSpeech_text,  repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = shouldEndSession)
        return response, session_attributes
    else:
        return no_correct_answer()
예제 #12
0
def get_help_instructions(intent_request, session, answer_intent = False):
    # print "yesy"
    intent_attributes = get_intent_attributes(intent_request, session, answer_intent)
    if intent_attributes["query_name"] == "NONE":
        outputSpeech_text = "What is your query."
        repromt_outputSpeech_text="Please tell me your query."
        session_attributes = get_session_attributes(previous_intent = "Help_Intent", previous_intent_attributes = intent_attributes, requested_value = "query_name")
        response = get_response(outputSpeech_text = outputSpeech_text, repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = False)
    else:
        query = "stackoverflow help " + intent_attributes["query_name"]
        return all_response(query = query, session = session, intent_request = intent_request)
    return give_response(response = response, session_attributes = session_attributes)
def repeat_previous(session):
    if session["attributes"]["previous_requested_value"] != "":
        if session["attributes"]["previous_requested_value"] == "next_question":
            outputSpeech_text = session["attributes"]["question_name"]
            shouldEndSession = False
            repromt_outputSpeech_text = "Please answer yes or no or repeat"
            session_attributes = session["attributes"]
            response = get_response(outputSpeech_text = outputSpeech_text,  repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = shouldEndSession)
            return response, session_attributes
        elif session["attributes"]["previous_requested_value"] == "give_answer":
            return give_answer(session = session, is_repeat = True)
        elif session["attributes"]["previous_requested_value"] == "give_comment":
            return give_comment(session)
    else:
        return required_response(session)
def give_comment(session):
    outputSpeech_text = session["attributes"]["complete_answer"]["comment"]
    if session["attributes"]["answer_now_id"] == len(session["attributes"]["answers_ids"]):
        if session["attributes"]["question_now_id"] < len(session["attributes"]["questions_urls"]):
            outputSpeech_text = outputSpeech_text + " Do you want me to go to next related question? or do you want me to repeat the comments?"
            shouldEndSession = False
            repromt_outputSpeech_text = "Please answer yes or no to go to next related question or say repeat to repeat the comments again."
            session_attributes = get_session_attributes(requested_value = "next_question", previous_requested_value = "give_comment", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], answers_ids = session["attributes"]["answers_ids"], complete_answer = session["attributes"]["complete_answer"])
        else:
            shouldEndSession = True
            session_attributes = get_session_attributes()
    else:
        outputSpeech_text = outputSpeech_text + " Do you want me to go to next answer to the question? or do you want me to repeat the comment?"
        shouldEndSession = False
        repromt_outputSpeech_text = "Please answer yes or no to go to next answer or say repeat to repeat the comment again."
        session_attributes = get_session_attributes(requested_value = "give_answer", previous_requested_value = "give_comment", questions_urls = session["attributes"]["questions_urls"], question_now_id = session["attributes"]["question_now_id"], question_name = session["attributes"]["question_name"], answers_ids = session["attributes"]["answers_ids"], answer_now_id = session["attributes"]["answer_now_id"], complete_answer = session["attributes"]["complete_answer"])
    response = get_response(outputSpeech_text = outputSpeech_text, shouldEndSession = shouldEndSession, repromt_outputSpeech_text = repromt_outputSpeech_text)    
    return response, session_attributes
def get_error_instructions(intent_request, session, answer_intent=False):
    # print "yesy"
    intent_attributes = get_intent_attributes(intent_request, session,
                                              answer_intent)
    if intent_attributes["error_name"] == "NONE":
        outputSpeech_text = "What is your error."
        repromt_outputSpeech_text = "Please tell what is the error you are facing."
        session_attributes = get_session_attributes(
            previous_intent="Error_Intent",
            previous_intent_attributes=intent_attributes,
            requested_value="error_name")
        response = get_response(
            outputSpeech_text=outputSpeech_text,
            repromt_outputSpeech_text=repromt_outputSpeech_text,
            shouldEndSession=False)
    else:
        query = "error " + intent_attributes["error_name"]
        return all_response(query=query,
                            session=session,
                            intent_request=intent_request)
    return give_response(response=response,
                         session_attributes=session_attributes)
def no_correct_answer():
    outputSpeech_text = "Sorry no one has posted correct answer to this question"
    return get_response(outputSpeech_text = outputSpeech_text), get_session_attributes()
예제 #17
0
def statement(original_text):
    """main function"""
    # original_text = " ".join(sys.argv[1:])
    if len(original_text) > 600:
        print("You can't check more than 600 characters at a time.")
        outputSpeech_text = "You can't check more than 600 characters at a time."
        response = get_response(outputSpeech_text)
        session_attributes = get_session_attributes()
        return give_response(response=response,
                             session_attributes=session_attributes)
        # quit()
    fixed_text = original_text
    correct_statement = original_text
    results = get_ginger_result(original_text)

    # Correct grammar
    if (not results["LightGingerTheTextResult"]):
        print("Good English :)")
        outputSpeech_text = "Good English"
        response = get_response(outputSpeech_text)
        session_attributes = get_session_attributes()
        return give_response(response=response,
                             session_attributes=session_attributes)
        # quit()

    # Incorrect grammar
    gap, fixed_gap = 0, 0
    mistake_text = ""
    card_mistake_text = ""
    for result in results["LightGingerTheTextResult"]:
        # print result
        if (result["Suggestions"]):
            from_index = result["From"] + gap
            to_index = result["To"] + 1 + gap
            suggest = result["Suggestions"][0]["Text"]
            mistake = result["Mistakes"][0]["Definition"]

            # Colorize text
            # colored_incorrect = ColoredText.colorize(original_text[from_index:to_index], 'red')[0]
            # colored_suggest, gap = ColoredText.colorize(suggest, 'green')
            # correct_statement = fixed_text[:from_index-fixed_gap] + suggest + fixed_text[to_index-fixed_gap:]
            mistake_phrase = original_text[from_index:to_index]
            original_text = original_text[:from_index] + '"' + original_text[
                from_index:to_index] + '"' + original_text[to_index:]
            fixed_text = fixed_text[:from_index -
                                    fixed_gap] + '"' + suggest + '"' + fixed_text[
                                        to_index - fixed_gap:]
            correct_statement = correct_statement[:from_index - fixed_gap -
                                                  gap] + suggest + correct_statement[
                                                      to_index - fixed_gap -
                                                      gap:]

            gap += 2
            fixed_gap += to_index - from_index - len(suggest)
            mistake_text += mistake_phrase + " is converted to " + suggest + " reason " + mistake + "."
            card_mistake_text += mistake_phrase + " - " + suggest + " : " + mistake + "\n"

    print("original_text: " + original_text)
    print("fixed_text:   " + fixed_text)
    print("final: " + correct_statement)
    print card_mistake_text
    print mistake_text
    outputSpeech_text = "The correct statement is " + correct_statement
    card_text = "original_text: " + original_text + "\n" + "fixed_text:   " + fixed_text + '\n' + card_mistake_text
    response = get_response(outputSpeech_text,
                            outputSpeech_type="PlainText",
                            card_type="Standard",
                            card_title="Ginger English",
                            card_text=card_text)
    session_attributes = get_session_attributes(original_text=original_text,
                                                fixed_text=fixed_text)
    return give_response(response=response,
                         session_attributes=session_attributes)
def no_more_questions():
    outputSpeech_text = "Sorry their are no more questions regarding this query"
    return get_response(outputSpeech_text = outputSpeech_text), get_session_attributes()
def no_questions():
    outputSpeech_text = "Sorry no one has posted this question"
    return get_response(outputSpeech_text = outputSpeech_text), get_session_attributes()
def session_end_greetings():
    outputSpeech_text = "I hope you got your answer"
    return get_response(outputSpeech_text = outputSpeech_text), get_session_attributes()