Exemple #1
0
def wikify_region():
	"""
	This function perfoms three tasks; calls the wikifier service to wikifiy a region, delete a region's wikification result
	and update the wikification result.
	:return:
	"""
	user_id = session["uid"]
	project_id = request.form["pid"]
	action = request.form["action"]
	region = request.form["region"]
	project_config_path = get_project_config_path(user_id, project_id)
	project = Project(project_config_path)
	data_file_name, sheet_name = project.get_current_file_and_sheet()
	data_file_path = str(Path.cwd() / "config" / "uploads" / user_id / project_id / "df" / data_file_name)
	region_map, region_file_name = get_region_mapping(user_id, project_id, project)
	item_table = ItemTable(region_map)
	data = dict()

	if action == "add_region":
		if not data_file_path:
			data['error'] = "No excel file to wikify"
		else:
			data = wikifier(item_table, region, data_file_path, sheet_name)
			wikifier_region_file_name = project.get_or_create_wikifier_region_filename()
			update_wikifier_region_file(user_id, project_id, wikifier_region_file_name, data)
	elif action == "delete_region":
		item_table.delete_region(region)
		data = item_table.get_region_qnodes()
		wikifier_region_file_name = project.get_or_create_wikifier_region_filename()
		update_wikifier_region_file(user_id, project_id, wikifier_region_file_name, data)
	elif action == "update_qnode":
		cell = request.form["cell"]
		qnode = request.form["qnode"]
		apply_to = int(request.form["apply_to"])
		if apply_to == 0:
			item_table.update_cell(region, cell, qnode)
		elif apply_to == 1:
			item_table.update_all_cells_within_region(region, cell, qnode, data_file_path, sheet_name)
		elif apply_to == 2:
			item_table.update_all_cells_in_all_region(cell, qnode, data_file_path, sheet_name)
		data = item_table.get_region_qnodes()
		wikifier_region_file_name = project.get_or_create_wikifier_region_filename()
		update_wikifier_region_file(user_id, project_id, wikifier_region_file_name, data)
	if 'error' not in data:
		data['error'] = None
	project_meta = dict()
	project_meta["wikifierRegionMapping"] = dict()
	project_meta["wikifierRegionMapping"][data_file_name] = dict()
	project_meta["wikifierRegionMapping"][data_file_name][sheet_name] = region_file_name
	project.update_project_config(project_meta)
	return json.dumps(data, indent=3)
Exemple #2
0
def wikify_region():
	"""
	This function perfoms three tasks; calls the wikifier service to wikifiy a region, delete a region's wikification result
	and update the wikification result.
	:return:
	"""
	user_id = request.form["id"]
	action = request.form["action"]
	region = request.form["region"]
	user = app.config['users'].get_user(user_id)
	data = ""
	if action == "add_region":
		excel_filepath = user.get_excel_data().get_file_location()
		sheet_name = user.get_excel_data().get_sheet_name()
		item_table = user.get_wikifier_output_data().get_item_table()
		if not item_table:
			item_table = ItemTable()
			user.get_wikifier_output_data().set_item_table(item_table)
		if not excel_filepath:
			data = "No excel file to wikify"
		else:
			data = wikifier(item_table, region, excel_filepath, sheet_name)
	elif action == "delete_region":
		item_table = user.get_wikifier_output_data().get_item_table()
		item_table.delete_region(region)
		data = item_table.get_region_qnodes()
	elif action == "update_qnode":
		cell = request.form["cell"]
		qnode = request.form["qnode"]
		apply_to = int(request.form["apply_to"])
		item_table = user.get_wikifier_output_data().get_item_table()
		if apply_to == 0:
			item_table.update_cell(region, cell, qnode)
		elif apply_to == 1:
			excel_filepath = user.get_excel_data().get_file_location()
			sheet_name = user.get_excel_data().get_sheet_name()
			item_table.update_all_cells_within_region(region, cell, qnode, excel_filepath, sheet_name)
		elif apply_to == 2:
			excel_filepath = user.get_excel_data().get_file_location()
			sheet_name = user.get_excel_data().get_sheet_name()
			item_table.update_all_cells_in_all_region(cell, qnode, excel_filepath, sheet_name)
		data = item_table.get_region_qnodes()
	return json.dumps(data, indent=3)