コード例 #1
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)
コード例 #2
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)
コード例 #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_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)
コード例 #5
0
def all_response(intent_request, query = "", session = ""):
    if session["new"] == False:
        if (session["attributes"]["requested_value"] in ["next_question", "give_comment", "next_answer", "give_answer"]):
            if intent_request["intent"]["slots"]["answer"]["value"] not in ["yes", "no", "repeat"]:
                response, session_attributes = required_response(session)
    if session["new"] == True:
        questions_ids = search_questions(query)
        if len(questions_ids) > 0:
            response, session_attributes = next_question(questions_ids, 0)
        else:
            response, session_attributes = no_questions()
    elif (session["attributes"]["requested_value"] not in ["next_question", "give_comment", "next_answer", "give_answer"]):
        print "hello"
        questions_ids = search_questions(query)
        if len(questions_ids) > 0:
            response, session_attributes = next_question(questions_ids, 0)
        else:
            response, session_attributes = no_questions()
    elif intent_request["intent"]["slots"]["answer"]["value"] == "repeat":
        response, session_attributes = repeat_previous(session)
    elif session["attributes"]["requested_value"] == "give_answer":
        if intent_request["intent"]["slots"]["answer"]["value"] == "no":
            if session["attributes"]["previous_requested_value"] == "next_question":
                if session["attributes"]["question_now_id"] < len(session["attributes"]["questions_ids"]):
                    response, session_attributes = next_question(session["attributes"]["questions_ids"], session["attributes"]["question_now_id"])
                else:
                    response, session_attributes = no_more_questions()
            else:
                response, session_attributes = session_end_greetings()
        elif intent_request["intent"]["slots"]["answer"]["value"] == "yes":
            response, session_attributes = give_answer(session)

    elif session["attributes"]["requested_value"] == "give_comment":
        if intent_request["intent"]["slots"]["answer"]["value"] == "no":
            if session["attributes"]["answer_now_id"] == len(session["attributes"]["answers_ids"]):
                if session["attributes"]["question_now_id"] < len(session["attributes"]["questions_ids"]):
                    response, session_attributes = next_related_question(session)
                else:
                    response, session_attributes = session_end_greetings()
            else:
                response, session_attributes = next_related_answer(session)
        elif intent_request["intent"]["slots"]["answer"]["value"] == "yes":
            response, session_attributes = give_comment(session)

    elif session["attributes"]["requested_value"] == "next_question":
        if intent_request["intent"]["slots"]["answer"]["value"] == "no":
            response, session_attributes = session_end_greetings()
        elif intent_request["intent"]["slots"]["answer"]["value"] == "yes":
            if session["attributes"]["question_now_id"] < len(session["attributes"]["questions_ids"]):
                response, session_attributes = next_question(session["attributes"]["questions_ids"], session["attributes"]["question_now_id"])
            else:
                response, session_attributes = no_more_questions()
        else:
            response, session_attributes = session_end_greetings()
    return give_response(response = response, session_attributes = session_attributes)
コード例 #6
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)
コード例 #7
0
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)
コード例 #8
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)
コード例 #9
0
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)
コード例 #10
0
def get_cancel_instructions():
    response, session_attributes = session_end_greetings()
    return give_response(response = response, session_attributes = session_attributes)
コード例 #11
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)