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)
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
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
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