update
This commit is contained in:
parent
3f1390a62c
commit
d9dbf5cbc7
|
@ -7,7 +7,7 @@ import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ...entities.entities import ReturnInfo, FileInfo
|
from ...entities.entities import ReturnInfo, FileInfo
|
||||||
from ...libs.tools import read_json_file, read_txt_file, write_json
|
from ...libs.tools import read_json_file, read_txt_file, write_json, get_project_file
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -65,28 +65,47 @@ def query_file():
|
||||||
def get_lables():
|
def get_lables():
|
||||||
ret_info = ReturnInfo()
|
ret_info = ReturnInfo()
|
||||||
try:
|
try:
|
||||||
project_name = request.args.get("projectName")
|
|
||||||
# current_filename = request.args.get("current_filename")
|
|
||||||
download_json = []
|
download_json = []
|
||||||
|
project_name = request.args.get("projectName")
|
||||||
|
project_path = PROJECT_PATH.format(project_name)
|
||||||
|
print(project_path)
|
||||||
|
project_file_list = get_project_file(project_path)
|
||||||
|
print(project_file_list)
|
||||||
|
# current_filename = request.args.get("current_filename")
|
||||||
|
anno_data_set = set()
|
||||||
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
||||||
for item in anno_data:
|
for item in anno_data:
|
||||||
|
|
||||||
item_dict = {'file': item['fileName'],
|
item_dict = {'file': item['fileName'],
|
||||||
'text': read_txt_file(PROJECT_PATH.format(project_name) + '/' + item['fileName']),
|
# 'text': read_txt_file(PROJECT_PATH.format(project_name) + '/' + item['fileName']),
|
||||||
'labels': list(set([x['type'] for x in item["annoDetails"]]))}
|
'labels': list(set([x['type'] for x in item["annoDetails"]]))}
|
||||||
print(item_dict)
|
print(item_dict)
|
||||||
|
anno_data_set.add(item['fileName'])
|
||||||
download_json.append(item_dict)
|
download_json.append(item_dict)
|
||||||
|
#add no label data
|
||||||
|
for filename in set(project_file_list).difference(anno_data_set):
|
||||||
|
item_dict = {'file': filename,
|
||||||
|
'labels': []
|
||||||
|
}
|
||||||
|
download_json.append(item_dict)
|
||||||
|
|
||||||
|
# print(set(project_file_list).difference(anno_data_set))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ret_info.errCode = 404
|
ret_info.errCode = 404
|
||||||
ret_info.errMsg = str(e)
|
ret_info.errMsg = str(e)
|
||||||
return json.dumps(download_json, default=lambda o: o.__dict__)
|
return json.dumps(download_json, default=lambda o: o.__dict__)
|
||||||
|
|
||||||
|
|
||||||
@api.route('/get_json', methods=['GET'])
|
@api.route('/get_json', methods=['GET'])
|
||||||
def get_json():
|
def get_json():
|
||||||
ret_info = ReturnInfo()
|
ret_info = ReturnInfo()
|
||||||
try:
|
try:
|
||||||
|
|
||||||
project_name = request.args.get("projectName")
|
project_name = request.args.get("projectName")
|
||||||
|
project_path = PROJECT_PATH.format(project_name)
|
||||||
|
project_file_list = get_project_file(project_path)
|
||||||
|
anno_data_set = set()
|
||||||
download_json = []
|
download_json = []
|
||||||
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
||||||
for item in anno_data:
|
for item in anno_data:
|
||||||
|
@ -101,7 +120,17 @@ def get_json():
|
||||||
# 也可以用这种方式来实现
|
# 也可以用这种方式来实现
|
||||||
# item['annoDetails'].pop('isSmall','0')
|
# item['annoDetails'].pop('isSmall','0')
|
||||||
item_dict['entity'] = item['annoDetails']
|
item_dict['entity'] = item['annoDetails']
|
||||||
|
anno_data_set.add(item['fileName'])
|
||||||
download_json.append(item_dict)
|
download_json.append(item_dict)
|
||||||
|
print(anno_data_set)
|
||||||
|
# add no label data
|
||||||
|
for filename in set(project_file_list).difference(anno_data_set):
|
||||||
|
item_dict = {'file': filename,
|
||||||
|
'txt': read_txt_file(PROJECT_PATH.format(project_name) + '/' + filename),
|
||||||
|
'entity': []
|
||||||
|
}
|
||||||
|
download_json.append(item_dict)
|
||||||
|
|
||||||
write_json(PROJECT_PATH.format(project_name) + '/result.json', download_json)
|
write_json(PROJECT_PATH.format(project_name) + '/result.json', download_json)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -37,6 +37,14 @@ def read_txt_file(file_path):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def get_project_file(project_path):
|
||||||
|
|
||||||
|
file_name = os.listdir(project_path)
|
||||||
|
file_name.remove('anno.json')
|
||||||
|
file_name.remove('config.json')
|
||||||
|
return file_name
|
||||||
|
|
||||||
|
|
||||||
def unzip_file(zip_src, dst_dir):
|
def unzip_file(zip_src, dst_dir):
|
||||||
"""
|
"""
|
||||||
解压数据文件
|
解压数据文件
|
||||||
|
@ -65,7 +73,7 @@ def unzip_file(zip_src, dst_dir):
|
||||||
ft = tarfile.TarFile(zip_src, "r")
|
ft = tarfile.TarFile(zip_src, "r")
|
||||||
print(ft.getnames())
|
print(ft.getnames())
|
||||||
for file in ft.getnames():
|
for file in ft.getnames():
|
||||||
ft.extract(file,dst_dir)
|
ft.extract(file, dst_dir)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return "请上传.zip .tar格式的文件"
|
return "请上传.zip .tar格式的文件"
|
||||||
|
|
Loading…
Reference in New Issue