示例#1
0
def process_coordinator(entities):
    print("Which program do you want to know?")
    response_user = input("")
    entity_list = get_entities(response_user)["entities"]
    if "status" in entity_list:
        if contains("undergraduate", entity_list["status"]):
            response = "The coordinator for UG programs is Dr. Qiong Luo."
            print(response)
            new_state = "end"
            return new_state, entities
        if contains("postgraduate", entity_list["status"]):
            response = "The coordinator for PG programs is Dr. Kai Chen."
            print(response)
            new_state = "end"
            return new_state, entities
    if "program" in entity_list:
        program_info_matching = helper.load_program_info()
        response = ""
        for i in range(len(entity_list["program"])):
            if i != 0:
                response += "\n"
            program = entity_list["program"][i]["value"]
            coordinator = program_info_matching[program][4]
            response += response_generator.provide_coordinator_info(
                program, coordinator)
        print(response)
        new_state = "end"
        return new_state, entities
    response = response_generator.provide_general_coordinator_info()
    print(response)
    new_state = "end"
    return new_state, entities
示例#2
0
def process_admission_general(entities):
    response = response_generator.query_job_student()
    print(response)
    job_or_student = input("")
    entity_list = helper.change_entity_list(get_entities(job_or_student))
    if "info_target" in entity_list:
        if contains("job", entity_list["info_target"]) or contains(
                "title", entity_list["info_target"]):
            print(response_generator.query_job())
            new_state = "end"
            return new_state, entities
        else:
            print(response_generator.query_student())
            program_choice = input("")
            entities_list_original = get_entities(program_choice)
            entity_list_new = helper.change_entity_list(entities_list_original)
            if "program" in entity_list_new:
                response = ""
                for i in range(len(entity_list_new["program"])):
                    if i != 0:
                        response += "\n"
                    program = entity_list_new["program"][i]["value"]
                    admission = helper.load_program_info()[program][2]
                    response += admission
                print(response)
                new_state = "end"
                return new_state, entities
        return "end", entities
    print(response_generator.sorry())
    return "end", entities
def provide_general_coordinator_info():
    program_info = helper.load_program_info()
    response = "I am sorry that I may not understand what you said. "
    response += "But here are some general news about the coordinator in different programs.\n\n"
    response += "The coordinator for UG programs is Dr. Qiong Luo.\n"
    response += "The coordinator for PG programs is Dr. Kai Chen.\n\n"
    response += "The coordinator for each program is:\n"
    index = 0
    for program in program_info:
        if index != 0:
            response += "\n"
        coordinator = program_info[program][4]
        response += provide_coordinator_info(program, coordinator)
        index += 1
    return response
    if contains("get_access", entities["intent"]):
        if "site_name" in entities:
            if contains("fypms", entities["site_name"]):
                print("The URL of FYPMS is: ")
                return
        if "access_target" in entities:
            if contains("computing facilities", entities["access_target"]):
                print("There are several possible computation resources:")
                return

    # When the user attempts to know the general information about the chatbot
    if contains("get_general", entities["intent"]):
        response = response_generator.greeting()
        print(response)
        return

# connect it with ios
if __name__ == "__main__":
    helper.load_program_info()
    helper.load_enrichment_general_info()
    print("This line is for demo purpose. Please input a sentence.")
    helper.load_research_area_info()
    helper.load_faculty_research_info()
    while True:
        user_response = input("")
        entity_list = get_entities(user_response)["entities"]
        fsm = define_states()
        fsm.run(entity_list)
        helper.load_faculty_information()
        # process_dialog(entity_list)
示例#5
0
def divide_basic_questions(entities):
    if "info_target" in entities:
        if contains("rank", entities["info_target"]):
            response = response_generator.provide_ranking_information()
            print(response)
            new_state = "end"
            return new_state, entities
    # Enrichment opportunities
    if "enrich_target" in entities:
        response = ""
        enrich_general = helper.load_enrichment_general_info()
        for i in range(len(entities["enrich_target"])):
            if i != 0:
                response += "\n\n"
            enrichment = entities["enrich_target"][i]["value"]
            if enrichment == "Exchange Programs":
                if "exchange_type" in entities:
                    if contains("inbound",
                                entities["exchange_type"]) and contains(
                                    "outbound", entities["exchange_type"]):
                        response += response_generator.provide_inbound_exchange(
                        )
                        response += "\n"
                        response += response_generator.provide_outbound_exchange(
                        )
                    elif contains("inbound", entities["exchange_type"]):
                        response += response_generator.provide_inbound_exchange(
                        )
                    elif contains("outbound", entities["exchange_type"]):
                        response += response_generator.provide_outbound_exchange(
                        )
            else:
                response += enrich_general[enrichment][1]
        print(response)
        new_state = "end"
        return new_state, entities
    # Program information
    if "program" in entities:
        program_info = helper.load_program_info()
        response = ""
        for i in range(len(entities["program"])):
            if i != 0:
                response += "\n\n"
            program = entities["program"][i]["value"]
            intro = program_info[program][1]
            response += intro
        print(response)
        new_state = "end"
        return new_state, entities
    # Course information
    if "course" in entities and "honor_course" not in entities:
        if "info_target" in entities:
            if contains("prerequisite", entities["info_target"]):
                response = ""
                if "course" not in entities:
                    total_course = entities["honor_course"]
                elif "honor_course" not in entities:
                    total_course = entities["course"]
                else:
                    total_course = entities["course"] + entities["honor_course"]
                attributes, course_info = helper.load_course_information()
                for i in range(len(total_course)):
                    if i != 0:
                        response += "\n"
                    course_code = total_course[i]["value"]
                    prerequisite = course_info[course_code][4]
                    response += response_generator.provide_course_prerequisite(
                        course_code, prerequisite)
                print(response)
                new_state = "end"
                return new_state, entities
            if contains("exclusion", entities["info_target"]):
                response = ""
                if "course" not in entities:
                    total_course = entities["honor_course"]
                elif "honor_course" not in entities:
                    total_course = entities["course"]
                else:
                    total_course = entities["course"] + entities["honor_course"]
                attributes, course_info = helper.load_course_information()
                for i in range(len(total_course)):
                    if i != 0:
                        response += "\n"
                    course_code = total_course[i]["value"]
                    exclusion = course_info[course_code][3]
                    response += response_generator.provide_course_exclusion(
                        course_code, exclusion)
                print(response)
                new_state = "end"
                return new_state, entities
        course_attributes, course_info = helper.load_course_information()
        response = ""
        for i in range(len(entities["course"])):
            if i != 0:
                response += "\n\n"
            code = entities["course"][i]["value"]
            response += response_generator.provide_course_info_by_table(
                code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # To deal with the problem of unhandled "honor course" problem.
    if "honor_course" in entities and "course" not in entities:
        course_attributes, course_info = helper.load_course_information()
        response = ""
        for i in range(len(entities["honor_course"])):
            if i != 0:
                response += "\n\n"
            code = entities["honor_course"][i]["value"]
            response += response_generator.provide_course_info_by_table(
                code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # Dealing with the problem of "mixed" type of information.
    if "honor_course" in entities and "course" in entities:
        course_attributes, course_info = helper.load_course_information()
        response = ""
        course_entities_augmented = entities["honor_course"] + entities[
            "course"]
        for i in range(len(course_entities_augmented)):
            if i != 0:
                response += "\n\n"
            code = course_entities_augmented[i]["value"]
            response += response_generator.provide_course_info_by_table(
                code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # Dealing with the problem of research area
    if "research_area" in entities:
        response = ""
        fullname, attributes = helper.load_research_area_full_name()
        for i in range(len(entities["research_area"])):
            if i != 0:
                response += "\n\n"
            research_area = entities["research_area"][i]["value"]
            response += attributes[research_area]
        print(response)
        new_state = "end"
        return new_state, entities
    # Basic information about the department
    response = response_generator.provide_basic_dept_info()
    print(response)
    new_state = "end"
    return new_state, entities
示例#6
0
def process_people_query_questions(entities):
    if "staff_name" in entities:
        staff_attributes, staff_info = helper.load_staff_information()
        response = ""
        for i in range(len(entities["staff_name"])):
            if i != 0:
                response += "\n"
            staff_name = entities["staff_name"][i]["value"].replace("\n", "")
            position = staff_info[staff_name][4].replace("\n", "").lower()
            staff_type = staff_info[staff_name][5].replace("\n", "")
            response += response_generator.provide_staff_people_info(
                staff_name, position, staff_type)
        print(response)
        new_state = "end"
        return new_state, entities
    if "research_area" in entities:
        response = ""
        area_faculty, faculty_area = helper.load_faculty_research_info()
        for i in range(len(entities["research_area"])):
            if i != 0:
                response += "\n"
            research_area = entities["research_area"][i]["value"]
            faculty_list = area_faculty[research_area]
            response += response_generator.provide_faculty_in_research_area(
                research_area, faculty_list)
        print(response)
        new_state = "end"
        return new_state, entities
    if "faculty_name" in entities:
        faculty_attributes, faculty_info = helper.load_faculty_information()
        response = ""
        for i in range(len(entities["faculty_name"])):
            if i != 0:
                response += "\n"
            name = entities["faculty_name"][i]["value"]
            response += faculty_info[name][6]
        print(response)
        new_state = "end"
        return new_state, entities
    if "info_target" in entities:
        if contains("head", entities["info_target"]):
            response = "The head of the department is Prof. Dit-Yan Yeung."
            print(response)
            new_state = "end"
            return new_state, entities
        if contains("ug coordinator", entities["info_target"]):
            response = "The coordinator for UG programs is Dr. Qiong Luo."
            print(response)
            new_state = "end"
            return new_state, entities
        if contains("pg coordinator", entities["info_target"]):
            response = "The coordinator for PG programs is Dr. Kai Chen."
            print(response)
            new_state = "end"
            return new_state, entities
        if contains("coordinator", entities["info_target"]):
            if "program" in entities:
                response = ""
                for i in range(len(entities["program"])):
                    if i != 0:
                        response += "\n"
                    program = entities["program"][i]["value"]
                    coordinator = helper.load_program_info()[4]
                    response += response_generator.provide_coordinator_info(
                        program, coordinator)
                print(response)
                new_state = "end"
                return new_state, entities
            new_state = "query_coordinator"
            return new_state, entities
    new_state = "error"
    return new_state, entities
示例#7
0
def divide_admission_questions(entities):
    if "enrich_target" in entities:
        if contains("Exchange Programs", entities["enrich_target"]):
            if "exchange_type" in entities:
                if contains("inbound", entities["exchange_type"]):
                    response = response_generator.provide_inbound_exchange()
                    print(response)
                    new_state = "end"
                    return new_state, entities
                else:
                    response = response_generator.provide_outbound_exchange()
                    print(response)
                    new_state = "end"
                    return new_state, entities
            else:
                response = response_generator.query_in_out()
                print(response)
                in_or_out = input("")
                entity_list = get_entities(in_or_out)["entities"]
                if "exchange_type" in entity_list:
                    if contains("outbound", entity_list["exchange_type"]):
                        response = response_generator.provide_outbound_exchange(
                        )
                        print(response)
                        new_state = "end"
                        return new_state, entities
                    else:
                        response = response_generator.provide_inbound_exchange(
                        )
                        print(response)
                        new_state = "end"
                        return new_state, entities
                else:
                    response = response_generator.provide_inbound_outbound_exchange(
                    )
                    print(response)
                    new_state = "end"
                    return new_state, entities
        else:
            enrichment_info = helper.load_enrichment_general_info()
            response = ""
            for i in range(len(entities["enrich_target"])):
                if i != 0:
                    response += "\n\n"
                name = entities["enrich_target"][i]["value"]
                response += enrichment_info[name][4]
            print(response)
            new_state = "end"
            return new_state, entities

    # Process the queries related to specific information
    if "info_target" in entities:
        if contains("faculty", entities["info_target"]):
            response = response_generator.provide_faculty_recruitment()
            print(response)
            new_state = "end"
            return new_state, entities
        if contains("job", entities["info_target"]):
            new_state = "admission_job"
            return new_state, entities

    # Process the query of enrolling some course
    if "course" in entities or "honor_course" in entities:
        attributes, course_info = helper.load_course_information()
        if "course" not in entities:
            total_course = entities["honor_course"]
        elif "honor_course" not in entities:
            total_course = entities["course"]
        else:
            total_course = entities["course"] + entities["honor_course"]
        response = ""
        for i in range(len(total_course)):
            if i != 0:
                response += "\n"
            course_code = total_course[i]["value"]
            prerequisite = course_info[course_code][4]
            response += response_generator.provide_course_prerequisite(
                course_code, prerequisite)
        print(response)
        new_state = "end"
        return new_state, entities

    # Process the admission to specific program
    if "program" in entities:
        response = ""
        for i in range(len(entities["program"])):
            if i != 0:
                response += "\n"
            program = entities["program"][i]["value"]
            admission = helper.load_program_info()[program][2]
            response += admission
        print(response)
        new_state = "end"
        return new_state, entities
    new_state = "admission_general"
    return new_state, entities
示例#8
0
def divide_basic_questions(entities):
    # TODO: implement the "inbound"/"outbound" differentiation for exchange
    # Enrichment opportunities
    if "enrich_target" in entities:
        response = ""
        enrich_general = helper.load_enrichment_general_info()
        for i in range(len(entities["enrich_target"])):
            if i != 0:
                response += "\n\n"
            enrichment = entities["enrich_target"][i]["value"]
            # TODO
            if enrichment == "Exchange Programs":
                if contains("inbound", entities["enrich_target"]) and contains("outbound", entities["enrich_target"]):
                    response += ""
            response += enrich_general[enrichment][1]
        print(response)
        new_state = "end"
        return new_state, entities
    # Program information
    if "program" in entities:
        program_info = helper.load_program_info()
        response = ""
        for i in range(len(entities["program"])):
            if i != 0:
                response += "\n\n"
            program = entities["program"][i]["value"]
            intro = program_info[program][1]
            response += intro
        print(response)
        new_state = "end"
        return new_state, entities
    # Course information
    if "course" in entities and "honor_course" not in entities:
        course_attributes, course_info = helper.load_course_information()
        response = ""
        for i in range(len(entities["course"])):
            if i != 0:
                response += "\n\n"
            code = entities["course"][i]["value"]
            response += response_generator.provide_course_info_by_table(code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # To deal with the problem of unhandled "honor course" problem.
    if "honor_course" in entities and "course" not in entities:
        course_attributes, course_info = helper.load_course_information()
        response = ""
        for i in range(len(entities["honor_course"])):
            if i != 0:
                response += "\n\n"
            code = entities["honor_course"][i]["value"]
            response += response_generator.provide_course_info_by_table(code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # Dealing with the problem of "mixed" type of information.
    if "honor_course" in entities and "course" in entities:
        course_attributes, course_info = helper.load_course_information()
        response = ""
        course_entities_augmented = entities["honor_course"] + entities["course"]
        for i in range(len(course_entities_augmented)):
            if i != 0:
                response += "\n\n"
            code = course_entities_augmented[i]["value"]
            response += response_generator.provide_course_info_by_table(code, course_info)
        print(response)
        new_state = "end"
        return new_state, entities
    # Dealing with the problem of research area
    if "research_area" in entities:
        response = ""
        fullname, attributes = helper.load_research_area_full_name()
        for i in range(len(entities["research_area"])):
            if i != 0:
                response += "\n\n"
            research_area = entities["research_area"][i]["value"]
            response += attributes[research_area]
        print(response)
        new_state = "end"
        return new_state, entities
    # Basic information about the department
    if "basic_target" not in entities and "program" not in entities and "course" not in entities:
        if "department_name" in entities:
            response = response_generator.provide_basic_dept_info()
            print(response)
            new_state = "end"
            return new_state, entities
    new_state = "error"
    return new_state, entities