diff --git a/app.py b/app.py index b38e9a1..96941d9 100755 --- a/app.py +++ b/app.py @@ -7,8 +7,10 @@ import random import re import shutil import string +import sys import time from pathlib import Path +from conllu import parse import requests from flask import Flask, render_template, request, send_file, redirect, url_for @@ -131,7 +133,14 @@ def create_app(): for subtree_id in subtree_ids: annodoc += f'# visual-style {subtree_id} bgColor:lightgreen\n' with open(os.path.join('media', result_id, 'annodoc', sentence_id), 'r') as rf: - annodoc += rf.read() + '\n\n' + read_annodoc = rf.read() + sentences = parse(read_annodoc) + + # delete `deps` column + for token in sentences[0]: + token['deps'] = None + annodoc += sentences[0].serialize() + return {'annodoc': annodoc} @app.route('/stark/result//', methods=['GET']) @@ -200,9 +209,13 @@ def create_app(): file_path = os.path.join('media', filename, 'result.tsv') else: file_path = path - f_t = os.path.getmtime(file_path) - c_t = time.time() - file_age_seconds = c_t - f_t + if os.path.exists(file_path): + f_t = os.path.getmtime(file_path) + c_t = time.time() + file_age_seconds = c_t - f_t + else: + # delete empty folders + file_age_seconds = 10000000 if file_age_seconds > DAYS_BEFORE_DELETION * 86400: if os.path.isdir(path): shutil.rmtree(os.path.join('media', filename), ignore_errors=True) @@ -245,10 +258,20 @@ def create_app(): 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 and order_by != 'Ratio' else x[sort_id], reverse=True) + def sort_func(x): + if x[sort_id] == 'NaN': + return float('-inf') + return -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] + ordered_content = sorted(content[1:], key=sort_func, reverse=True) + else: - 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 and order_by != 'Ratio' else x[sort_id]) + def sort_func(x): + if x[sort_id] == 'NaN': + return float('inf') + return -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] + ordered_content = sorted(content[1:], key=sort_func) else: ordered_content = content[1:] diff --git a/requirements.txt b/requirements.txt index 04e1df4..2edd9ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Flask==3.0.0 requests==2.31.0 flask-babel==4.0.0 stark @ git+https://github.com/clarinsi/STARK@master +conllu==6.0.0 \ No newline at end of file diff --git a/static/js/result.js b/static/js/result.js index 36b0a02..7b6b1f3 100644 --- a/static/js/result.js +++ b/static/js/result.js @@ -47,12 +47,12 @@ $(document).ready(function() { if (grew_url == 'unknown') { $(".grew-link").html("/"); } else { - $(".grew-link").html("" + grew_link_text + ""); + $(".grew-link").html("" + grew_link_text + ""); } if (other_examples == 'unknown') { $(".other-examples").html("/"); } else { - $(".other-examples").html("" + other_examples_text + ""); + $(".other-examples").html("" + other_examples_text + ""); } }); $(".close-visualization").click(function() { diff --git a/templates/result.html b/templates/result.html index d0ccba1..3db4c28 100644 --- a/templates/result.html +++ b/templates/result.html @@ -26,7 +26,7 @@
- + diff --git a/translations/en/LC_MESSAGES/messages.mo b/translations/en/LC_MESSAGES/messages.mo index c776d45..7aeb47a 100644 Binary files a/translations/en/LC_MESSAGES/messages.mo and b/translations/en/LC_MESSAGES/messages.mo differ diff --git a/translations/en/LC_MESSAGES/messages.po b/translations/en/LC_MESSAGES/messages.po index 30f3253..b5cd922 100644 --- a/translations/en/LC_MESSAGES/messages.po +++ b/translations/en/LC_MESSAGES/messages.po @@ -412,7 +412,7 @@ msgstr "Download complete results" #: templates/result.html:29 msgid "Close" -msgstr "" +msgstr "Close Visualization" #: templates/result.html:33 msgid "Visualization" diff --git a/translations/sl/LC_MESSAGES/messages.mo b/translations/sl/LC_MESSAGES/messages.mo index 4f5392e..c5eddc1 100644 Binary files a/translations/sl/LC_MESSAGES/messages.mo and b/translations/sl/LC_MESSAGES/messages.mo differ diff --git a/translations/sl/LC_MESSAGES/messages.po b/translations/sl/LC_MESSAGES/messages.po index 7106adc..7e17aa0 100644 --- a/translations/sl/LC_MESSAGES/messages.po +++ b/translations/sl/LC_MESSAGES/messages.po @@ -413,7 +413,7 @@ msgstr "Prenesi datoteko s celotnimi rezultati" #: templates/result.html:29 msgid "Close" -msgstr "Zapri" +msgstr "Zapri vizualizacijo" #: templates/result.html:33 msgid "Visualization"