Multiple visual adaptations.
This commit is contained in:
@@ -15,40 +15,12 @@ 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()}
|
||||
DEFAULT_LANGUAGE = 'en'
|
||||
LANGUAGES = ['en', 'sl']
|
||||
|
||||
_translations = {
|
||||
'en': {
|
||||
'hello': 'Hello',
|
||||
'welcome': 'Welcome',
|
||||
'greeting': 'How are you?',
|
||||
'name': 'Your name:',
|
||||
'code': 'en',
|
||||
'switch_code': 'SL',
|
||||
'switch_link': '?lang=sl',
|
||||
},
|
||||
'sl': {
|
||||
'hello': 'Hola',
|
||||
'welcome': 'Bienvenido',
|
||||
'greeting': '¿Cómo estás?',
|
||||
'name': 'Tu nombre:',
|
||||
'code': 'sl',
|
||||
'switch_code': 'EN',
|
||||
'switch_link': '?lang=en',
|
||||
},
|
||||
'en': {},
|
||||
'sl': {},
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +87,7 @@ def create_app():
|
||||
@app.route('/stark/result/<result_id>', methods=['GET', 'POST'])
|
||||
def result(result_id):
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
for filename in os.listdir('media'):
|
||||
file_path = os.path.join('media', filename)
|
||||
@@ -125,14 +98,37 @@ def create_app():
|
||||
os.remove(file_path)
|
||||
return send_file(os.path.join('media', result_id), as_attachment=True, download_name='results.tsv')
|
||||
|
||||
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}
|
||||
table_columns2displayed_table_columns = {
|
||||
'Tree': gettext('Tree'),
|
||||
'Absolute frequency': gettext('Frequency'),
|
||||
'Number of nodes': gettext('Number of nodes'),
|
||||
'Head node': gettext('Head node'),
|
||||
'Grew-match URL': gettext('Grew-match URL'),
|
||||
'Order': gettext('Order'),
|
||||
'MI': gettext('MI'),
|
||||
'logDice': gettext('logDice'),
|
||||
't-score': gettext('t-score')
|
||||
}
|
||||
if 'Absolute frequency in second treebank' in head:
|
||||
table_columns2displayed_table_columns['Absolute frequency'] = gettext('Frequency in A')
|
||||
table_columns2displayed_table_columns['Absolute frequency in second treebank'] = gettext('Frequency in B')
|
||||
if 'MI' in table_columns2displayed_table_columns:
|
||||
del table_columns2displayed_table_columns['MI']
|
||||
if 'logDice' in table_columns2displayed_table_columns:
|
||||
del table_columns2displayed_table_columns['logDice']
|
||||
if 't-score' in table_columns2displayed_table_columns:
|
||||
del table_columns2displayed_table_columns['t-score']
|
||||
displayed_table_columns2table_columns = {v: k for k, v in table_columns2displayed_table_columns.items()}
|
||||
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')
|
||||
if order_by is not None and order_by in head:
|
||||
sort_id = head.index(order_by)
|
||||
if order_type == 'asc':
|
||||
@@ -147,11 +143,11 @@ def create_app():
|
||||
for j, v in enumerate(row):
|
||||
content_dict[head[j]].append(v)
|
||||
|
||||
displayed_head = [TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS[col] for col in head if col in TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS]
|
||||
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
|
||||
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('/stark/', methods=['GET', 'POST'])
|
||||
@@ -328,7 +324,8 @@ def create_app():
|
||||
if len(content) == 1:
|
||||
validation['results'] = False
|
||||
return render_template('index.html', validation=validation, translations=translations)
|
||||
return redirect(url_for('result', result_id=name, order_by='Frequency ', order_type='desc', lang=gettext('code')))
|
||||
order_by = gettext('Frequency ') if not configs['compare'] else gettext('Frequency in A ')
|
||||
return redirect(url_for('result', result_id=name, order_by=order_by, order_type='desc', lang=gettext('code')))
|
||||
return render_template('index.html', translations=translations)
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user