Multiple fixes listed in 2024-01-03 changelog

This commit is contained in:
2024-01-22 14:56:12 +01:00
parent 9dc7561238
commit 5095bc8404
6 changed files with 254 additions and 394 deletions
+33 -29
View File
@@ -14,6 +14,18 @@ from stark import run
UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = {'conllu'}
DAYS_BEFORE_DELETION = 1
TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS = {
'Tree': 'Tree',
'Absolute frequency': 'Frequency',
'Number of nodes': 'Number of nodes',
'Head node': 'Head node',
'Grew-match URL': 'Grew-match URL',
'Order': 'Order',
'MI': 'MI',
'logDice': 'logDice',
't-score': 't-score'
}
DISPLAYED_TABLE_COLUMNS2TABLE_COLUMNS = {v: k for k, v in TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS.items()}
def create_app():
@@ -73,17 +85,10 @@ def create_app():
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
@app.route('/about', methods=['GET'])
def about():
return render_template('about.html')
# @app.route('/result/<result_id>/download', methods=['GET'])
# def download_result(result_id):
# return
@app.route('/result/<result_id>', methods=['GET', 'POST'])
def result(result_id):
@@ -99,15 +104,16 @@ def create_app():
# TODO TEST VARYING SIZES OF TEXT IN TABLE
return send_file(os.path.join('media', result_id), as_attachment=True, download_name='results.tsv')
order_by = request.args.get('order_by')
order_by_display = request.args.get('order_by')
order_by = DISPLAYED_TABLE_COLUMNS2TABLE_COLUMNS[order_by_display[:-1]] if order_by_display is not None else None
order_type = request.args.get('order_type')
with open(os.path.join('media', result_id), 'r') as rf:
content = list(csv.reader(rf, delimiter='\t'))
head = content[0]
content_dict = {h: [] for h in head}
if order_by is not None and order_by[:-1] in head:
sort_id = head.index(order_by[:-1])
if order_by is not None and order_by in head:
sort_id = head.index(order_by)
if order_type == 'asc':
# check if a number can be converted to float or int
ordered_content = sorted(content[1:], key=lambda x: -1 * float(x[sort_id]) if x[sort_id].isnumeric() or re.match(r'^-?\d+(?:\.\d+)$', x[sort_id]) is not None else x[sort_id], reverse=True)
@@ -120,11 +126,12 @@ def create_app():
for j, v in enumerate(row):
content_dict[head[j]].append(v)
# content.sort(key=lambda x: x[1])
a = request
print(result_id)
return render_template('result.html', head_row=head, content=content_dict)
displayed_head = [TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS[col] for col in head if col in TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS]
displayed_content_dict = {}
for column, v in content_dict.items():
if column in TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS:
displayed_content_dict[TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS[column]] = v
return render_template('result.html', head_row=displayed_head, content=displayed_content_dict)
@app.route('/', methods=['GET', 'POST'])
def index():
@@ -188,7 +195,7 @@ def create_app():
# TODO EXPAND NODE TYPE
node_type_options = {'upos', 'form', 'lemma', 'upos', 'xpos', 'feats', 'deprel'}
if len(node_type) == 0:
validation['node_type'] = 'Please provide information about node type.'
validation['node_type'] = 'Please select at least one node type.'
return False
for el in node_type:
@@ -219,6 +226,7 @@ def create_app():
configs['complete_tree_type'] = True
configs['dependency_type'] = 'labeled_trees' in form and form['labeled_trees'] == 'on'
configs['node_order'] = 'fixed_order' in form and form['fixed_order'] == 'on'
configs['association_measures'] = 'association_measures' in form and form['association_measures'] == 'on'
configs['label_whitelist'] = []
configs['root_whitelist'] = []
@@ -240,23 +248,19 @@ def create_app():
if configs['compare'] is not None:
configs['other_input_path'] = configs['compare']
########################################
#config = configparser.ConfigParser()
#config.read('config.ini')
# configs = read_configs(config, args)
configs['association_measures'] = False
configs['grew_match'] = 'grewmatch_patterns' in form and form['grewmatch_patterns'] == 'on'
configs['grew_match'] = True
configs['depsearch'] = False
name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=60))
configs['output'] = os.path.join('media', name)
run(configs)
# TODO DELETE STORED FILE AFTER PROCESSING
if len(validation) > 0:
return render_template('index.html', validation=validation)
try:
run(configs)
except Exception as e:
validation['general'] = 'Processing failed! Please recheck your settings.'
if len(validation) > 0:
return render_template('index.html', validation=validation)
return redirect(url_for('result', result_id=name))
# return send_file(configs['output'], as_attachment=True)
# return render_template('index.html')
return render_template('index.html')
return app