forked from Learning0411/Knowledge-data-evaluation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
153 lines (109 loc) · 4.84 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import json
from flask import Blueprint, render_template, send_from_directory, redirect,jsonify, current_app
import os
import threading
import similarity_computation
import Content_relevance_calculation
import quality_screening
import quantity_evaluation
import ratio
from flask import request, jsonify
triplet_bp = Blueprint('triplet_bp', __name__)
@triplet_bp.route('/')
@triplet_bp.route('/index.html')
def index():
return render_template('index.html')
@triplet_bp.route('/login.html')
def login():
return render_template('login.html')
# 数据上传
@triplet_bp.route('/uploading/<file_type>', methods=['POST'])
def upload_file(file_type):
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'Data')
TRIPLES_FILE_NAME = 'triples_file.csv'
ENTITIES_FILE_NAME = 'entities_file.csv'
try:
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
except Exception as e:
print(e)
return jsonify({'message': 'Failed to create upload folder', 'error': str(e)}), 500
if 'file' not in request.files:
return jsonify({'message': 'No file part in the request'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'message': 'No selected file'}), 400
try:
if file_type == 'triples':
filename = TRIPLES_FILE_NAME
elif file_type == 'entities':
filename = ENTITIES_FILE_NAME
else:
return jsonify({'message': 'Invalid file type'}), 400
file_path = os.path.join(UPLOAD_FOLDER, filename)
file.save(file_path)
return jsonify({'message': 'File uploaded successfully'})
except Exception as e:
print(e)
return jsonify({'message': 'File upload failed', 'error': str(e)}), 500
# 基于实体关系数量的数据质量评价参数
def Quantity_evaluation():
result = quantity_evaluation.main() # 调用主计算函数获取结果
quantity_evaluation.progress = 100 # 完成后更新进度为100%
return result
@triplet_bp.route('/start-computation-quantity', methods=['GET'])
def start_computation_quantity():
threading.Thread(target=Quantity_evaluation).start()
return jsonify({"status": "Quantity_evaluation started"})
@triplet_bp.route('/get-quantity-progress', methods=['GET'])
def get_quantity_progress():
return jsonify({"progress": quantity_evaluation.progress}), 200
# 基于实体关系一致性评测
def compute_similarity():
result = similarity_computation.compute_and_save_consistency(similarity_computation.label_groups)
return result
@triplet_bp.route('/start-computation-similarity', methods=['GET'])
def start_computation_similarity():
threading.Thread(target=compute_similarity).start()
return jsonify({"status": "similarity computation started"})
@triplet_bp.route('/get-similarity-progress', methods=['GET'])
def get_similarity_progress():
with open('Data/similarity/progress.json', 'r', encoding='utf-8') as f:
progress_data = json.load(f)
return jsonify(progress_data)
# 基于实体关系比例
def start_calculation_thread():
result = ratio.calculate_and_save_degree_counts() # 调用主计算函数获取结果
return result
@triplet_bp.route('/start-degree-count-calculation', methods=['GET'])
def start_degree_count_calculation():
threading.Thread(target=start_calculation_thread).start()
return jsonify({"status": "degree-count started"})
@triplet_bp.route('/get-degree-count-progress', methods=['GET'])
def get_degree_count_progress():
return jsonify(ratio.progress), 200
# 基于三元组内容关联度
def compute_relevance():
result =Content_relevance_calculation.main()
Content_relevance_calculation.progress = 100 # 完成后更新进度为100%
return result
@triplet_bp.route('/start-computation-relevance', methods=['GET'])
def start_computation_relevance():
threading.Thread(target=compute_relevance).start()
return jsonify({"status": "compute_relevance started"})
@triplet_bp.route('/get-relevance-progress', methods=['GET'])
def get_relevance_progress():
return jsonify({"progress": Content_relevance_calculation.progress}), 200
# 存量数据质量报告
def Quality_screening_trid():
quality_screening.main()
@triplet_bp.route('/start-computation-screening', methods=['GET'])
def start_computation_screening():
threading.Thread(target=Quality_screening_trid).start()
return jsonify({"status": "Quality_screening started"})
@triplet_bp.route('/get-screening-progress', methods=['GET'])
def get_screening_progress():
return jsonify(quality_screening.progress), 200
@triplet_bp.route('/results/<filename>', methods=['GET'])
def get_results(filename):
return send_from_directory('results', filename)