示例#1
0
def signup():
    print("What's your username?")
    name = input()
    print("What's is the secret code?")
    code = input()

    UserHandler.get_instance().set_global_curr_user(dbo_user.add_user(User(-1, name, code)))
示例#2
0
def signup():
    global status, dbo_user, pickle_filepath, orsen

    UserHandler.get_instance().set_global_curr_user(
        dbo_user.add_user(User(-1, name, code)))
    status = "storytelling"
    pickle_filepath = pickle_filepath + name

    initialize_orsen()

    temp_welcome = orsen.get_response(
        move_to_execute=orsen.dialogue_planner.get_welcome_message_type())
    return "Alright " + name + " . " + temp_welcome
    def remove_relation_to_concepts_if_not_valid(self, relation):
        print(relation)
        local_concept_manager = DBOConceptLocalImpl()

        concept = local_concept_manager.get_specific_concept(
            first=str(relation.first_token),
            relation=str(relation.relation),
            second=str(relation.second_token))
        user = UserHandler.get_instance().curr_user
        if concept is None:
            pass
        else:
            if str(concept.user_id) != str(user.id):
                Logger.log_information_extraction_basic(
                    "Decrementing concept: " + concept.one_line_print())

                if concept.score <= (MIGRATION_SCORE_THRESHOLD * -1) - 1:
                    # pass
                    local_concept_manager.update_valid(concept.first,
                                                       concept.relation,
                                                       concept.second, 0)
                    Logger.log_information_extraction_basic(
                        "Deleting the concept " + concept.one_line_print() +
                        " from local.")
                else:
                    local_concept_manager.update_score(concept.first,
                                                       concept.relation,
                                                       concept.second,
                                                       concept.score - 1)
                    Logger.log_information_extraction_basic(
                        "Decreasing the score of " + concept.one_line_print() +
                        " from " + str(concept.score) + " to " +
                        str(concept.score - 1))
示例#4
0
def login():
    global status, dbo_user, pickle_filepath, orsen

    temp_user = dbo_user.get_specific_user(name, code)

    if temp_user is None:
        status = "ask_code"
        return "I don't think that's right. Can you try again? What's your username?"
    else:
        UserHandler.get_instance().set_global_curr_user(temp_user)
        status = "storytelling"
        pickle_filepath = pickle_filepath + name

        initialize_orsen()

        temp_welcome = orsen.get_response(
            move_to_execute=orsen.dialogue_planner.get_welcome_message_type())
        return "Hi! Welcome back " + name + " . " + temp_welcome
示例#5
0
def login_signup():
    print("Hi! Do you have an account? (Y/N)")
    user_input = input()

    if user_input == "Y":  # login
        login()
    else:
        signup()
    print(UserHandler.get_instance().curr_user)
示例#6
0
def login():
    # ask for user details
    is_done = False

    while not is_done:
        print("What's your username?")
        name = input()
        print("What's is the secret code?")
        code = input()

        temp_user = dbo_user.get_specific_user(name, code)

        if temp_user is None:
            print("I don't think that's right. Can you try again?")

        else:
            # store user
            UserHandler.get_instance().set_global_curr_user(temp_user)
            print("Hi! Welcome back ", name)
            is_done = True
示例#7
0
def login_signup_automatic():
    print("What's your name?")
    name = get_input()

    user_list = dbo_user.get_user_by_name('name')
    if user_list is not []:
        print("Do we have a secret code?")
        has_code_answer = get_input()
        has_code = False

        if has_code_answer.lower() == "y" or has_code_answer.lower() == "yes":
            print("What is the secret code?")
            input_code = get_input()
            temp_user = dbo_user.get_specific_user(name, input_code)

        else:
            # has_code_answer.lower() == "n" or has_code_answer.lower() == "no":
            print("Alright then let's make one! What should it be?")
            input_code = get_input()
            temp_user = dbo_user.add_user(User(-1, name, input_code))

        UserHandler.get_instance().set_global_curr_user(temp_user)
        print("Alright %s, let's make a story. You start!")
    def add_relation_to_concepts_if_not_existing(self, relation, increment):
        global_concept_manager = DBOConceptGlobalImpl()
        local_concept_manager = DBOConceptLocalImpl()

        concept = global_concept_manager.get_specific_concept(
            first=str(relation.first_token),
            relation=str(relation.relation),
            second=str(relation.second_token))
        if concept is None:
            concept = local_concept_manager.get_specific_concept(
                first=str(relation.first_token),
                relation=str(relation.relation),
                second=str(relation.second_token))
            user = UserHandler.get_instance().curr_user
            if concept is None:
                # user = User(id=-1, name='Wisner', code='testing')
                new_concept = LocalConcept.create_local_concept_from_relation(
                    relation=relation, user=user)
                local_concept_manager.add_concept(new_concept)
                Logger.log_information_extraction_basic(
                    "Adding new concept from " + str(user.id) + "(" +
                    str(user.name) + "): " + new_concept.one_line_print())
            else:
                if str(concept.user_id) != str(user.id):
                    if concept.score >= MIGRATION_SCORE_THRESHOLD - 1:
                        # pass
                        concept_to_migrate = GlobalConcept.convert_local_to_global(
                            concept)
                        local_concept_manager.update_valid(
                            concept.first, concept.relation, concept.second, 0)
                        global_concept_manager.add_concept(concept_to_migrate)
                        Logger.log_information_extraction_basic(
                            "Transferring the concept " +
                            concept.one_line_print() +
                            " from local to global.")
                    else:
                        local_concept_manager.update_score(
                            concept.first, concept.relation, concept.second,
                            concept.score + increment)
                        Logger.log_information_extraction_basic(
                            "Increasing the score of " +
                            concept.one_line_print() + " from " +
                            str(concept.score) + " to " +
                            str(concept.score + increment))
示例#9
0
def driver(query):
    print(query)
    requestJson = request.get_json()
    print(requestJson['request']['intent']['name'])

    user_input = query
    global status, name, code, have_account

    if user_input == None:
        orsen_response = "Please try again"
        return question(orsen_response)

    # if user_input == None:
    #     orsen_response = "Please try again"
    #     Logger.log_conversation("Alexa didn't get the trigger")
    #     Logger.log_dialogue_model("Alexa didn't get the trigger")

    #     Logger.log_conversation("ORSEN: " + str(orsen_response))
    #     Logger.log_dialogue_model("ORSEN: " + str(orsen_response))

    #     return question (orsen_response)

    # LOGIN SIGNUP
    if status == "account_status":
        account_status(user_input)
        status = "ask_username"

    if status == "ask_username":
        orsen_response = "What's your username?"
        status = "ask_code"

    elif status == "ask_code":
        name = user_input
        orsen_response = "What's your code?"
        status = "login_signup"

    elif status == "login_signup":
        code = user_input
        orsen_response = login_signup()

    # STORYTELLING
    elif status == "storytelling":
        if UserHandler.get_instance().curr_user is None:
            Logger.log_conversation("User : "******": " +
                str(user_input))

        is_end_story = is_end_story_func(user_input)

        if not is_end_story:
            # TODO Connect to back end, get the response
            orsen_response = orsen.get_response(user_input)
            Logger.log_conversation(CURR_ORSEN_VERSION + ": " +
                                    str(orsen_response))
            is_end_story = is_end_story_func(user_input)
            print("IM AT END STORY FIRST")

        if is_end_story:
            if CURR_ORSEN_VERSION == EDEN:
                try:
                    Pickle.pickle_world_wb(pickle_filepath,
                                           orsen.world.get_pickled_world())
                    print("TRYING TO STORE PICKLE")
                except Exception as e:
                    print("Error: ", e)

                # orsen_response = orsen_response + " Do you want to make a new story?"
                orsen_response = "Do you want to share another story?"
                print("IM AT END STORY STATUS")
                status = "create_another_story"
            else:
                orsen_response = "Thank you for the story! Do you want to hear it again?"
                status = "repeat_story"

    elif status == "repeat_story":
        orsen_response = ""
        if user_input.lower() in IS_AFFIRM:
            # TODO Connect to back end, get repetition
            orsen_response = orsen.repeat_story()
            # orsen_response = "Repeating Story..."
        orsen_response += " Do you want to create another story?"
        status = "create_another_story"

    elif status == "create_another_story":
        print("IM AT CREATE NEW STORY")
        if user_input.lower() in IS_AFFIRM:
            initialize_orsen()

            temp_welcome = orsen.get_response(
                move_to_execute=orsen.dialogue_planner.
                get_welcome_message_type())
            # orsen_response = "Ok! Let's make another story! You go first"
            orsen_response = "Ok! " + temp_welcome

            status = "storytelling"
        else:
            orsen_response = "Ok! Goodbye."
            status = "end_session"

    if status == "end_session":
        return statement(orsen_response)

    return question(orsen_response)
示例#10
0
            user_input = get_input()
            if user_input.lower() in IS_AFFIRM:
                print(orsen.repeat_story())


orsen = ORSEN()

# start here
# Initialize loggers
Logger.setup_loggers()
# Retrieve User Details --- User objects
print("---------Retrieving User Details---------")
print("done")

# pickle_filepath = '../logs/user world/' + datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S") + "-" + UserHandler.get_instance().curr_user.name
pickle_filepath = '../logs/user world/' + UserHandler.get_instance(
).curr_user.name
# pickle_filepath = '../Mod_ORSEN_v2//logs/user world/' + datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S") + "-" + UserHandler.get_instance().curr_user.name

# try:
#
#
#
#     print("---------Launching ORSEN---------")
#
#     #TODO: uncomment after testingI'm happ
#     #for repeating the story
#     is_engaged = True
#     while is_engaged:
#         orsen.initialize_story_prerequisites()
#         print("Let's make another story! You go first")
#         start_storytelling()
示例#11
0
def driver():

    global status, name, code, have_account, orsen
    global pickle_filepath

    requestJson = request.get_json()
    focus = requestJson["inputs"][0]
    data = {}
    user_input = ""

    if focus["intent"] != "actions.intent.NO_INPUT":
        user_input = requestJson["inputs"][0]["rawInputs"][0]["query"]

    if focus["intent"] == "actions.intent.NO_INPUT":
        orsen_response = "I can't seem to hear you. What did you say?"
        Logger.log_conversation("NO INPUT : " + str(orsen_response))
        data = json_reply.response(orsen_response)

    # Greet the User
    elif focus["intent"] == "actions.intent.MAIN":

        orsen_response = "Hi! I'm " + CURR_ORSEN_VERSION + ". "

        if status == "login_signup":
            orsen_response += "Do you have an account?"
            status = "account_status"

        elif status == "start_storytelling":
            initialize_orsen()

            temp_welcome = orsen.get_response(
                move_to_execute=orsen.dialogue_planner.
                get_welcome_message_type())
            orsen_response += temp_welcome
            status = "storytelling"

        data = json_reply.response(orsen_response)

    else:
        # LOGIN SIGNUP
        if status == "account_status":
            account_status(user_input)
            status = "ask_username"

        if status == "ask_username":
            orsen_response = "What's your username?"
            status = "ask_code"

        elif status == "ask_code":
            name = user_input
            orsen_response = "What's your code?"
            status = "login_signup"

        elif status == "login_signup":
            code = user_input
            orsen_response = login_signup()

        # STORYTELLING
        elif status == "storytelling":
            if UserHandler.get_instance().curr_user is None:
                Logger.log_conversation("User : "******": " +
                    str(user_input))

            is_end_story = is_end_story_func(user_input)

            if not is_end_story:
                # TODO Connect to back end, get the response
                orsen_response = orsen.get_response(user_input)
                Logger.log_conversation(CURR_ORSEN_VERSION + ": " +
                                        str(orsen_response))
                is_end_story = is_end_story_func(user_input)
                print("IM AT END STORY FIRST")

            if is_end_story:
                if CURR_ORSEN_VERSION == EDEN:
                    try:
                        Pickle.pickle_world_wb(pickle_filepath,
                                               orsen.world.get_pickled_world())
                        print("TRYING TO STORE PICKLE")
                    except Exception as e:
                        print("Error: ", e)

                    # orsen_response = orsen_response + " Do you want to make a new story?"
                    orsen_response = "Do you want to share another story?"
                    print("IM AT END STORY STATUS")
                    status = "create_another_story"
                else:
                    orsen_response = "Thank you for the story! Do you want to hear it again?"
                    status = "repeat_story"

        elif status == "repeat_story":
            if user_input.lower() in IS_AFFIRM:
                # TODO Connect to back end, get repetition
                orsen_response = orsen.repeat_story()
                # orsen_response = "Repeating Story..."
            orsen_response += " Do you want to create another story?"
            status = "create_another_story"

        elif status == "create_another_story":
            print("IM AT CREATE NEW STORY")
            if user_input.lower() in IS_AFFIRM:
                initialize_orsen()

                temp_welcome = orsen.get_response(
                    move_to_execute=orsen.dialogue_planner.
                    get_welcome_message_type())
                # orsen_response = "Ok! Let's make another story! You go first"
                orsen_response = "Ok! " + temp_welcome

                status = "storytelling"
            else:
                orsen_response = "Ok! Goodbye."
                status = "end_session"

    if status == "end_session":
        data = json_reply.final_response(orsen_response)
    else:
        data = json_reply.response(orsen_response)

    return jsonify(data)