Working fix pre merge
This commit is contained in:
@@ -8,21 +8,25 @@ from swagger_server.models.izlusci_async_body import IzlusciAsyncBody # noqa: E
|
||||
from swagger_server.models.izlusci_sync_body import IzlusciSyncBody # noqa: E501
|
||||
from swagger_server.requets_db.models.vrsta import JobManager
|
||||
from swagger_server.utils import cl_utils
|
||||
from swagger_server.utils import txt_utils
|
||||
from swagger_server.util import get_random_filename, create_random_file_in_tmp_folder
|
||||
import requests
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
ATEapi_endpoint = "http://ate-api:5000/predict"
|
||||
|
||||
|
||||
# endpoint below to be used only for development purposes (don't need to run docker)
|
||||
# ATEapi_endpoint = "http://localhost:5000/predict"
|
||||
|
||||
|
||||
def do_izlusci(conllus, prepovedane_besede):
|
||||
def do_izlusci(conllus, prepovedane_besede,definicije=False):
|
||||
tmp_file_path = ""
|
||||
print(definicije);
|
||||
try:
|
||||
big_conllu = cl_utils.multipla_conllus_to_one_from_conllus_arr(conllus)
|
||||
tmp_file_path = create_random_file_in_tmp_folder(big_conllu, ".conllu")
|
||||
|
||||
fp = open(tmp_file_path, 'rb')
|
||||
try:
|
||||
files = [
|
||||
@@ -30,26 +34,38 @@ def do_izlusci(conllus, prepovedane_besede):
|
||||
]
|
||||
res = requests.post(ATEapi_endpoint, files=files)
|
||||
data = json.loads(res.text)
|
||||
|
||||
|
||||
ret = {'terminoloski_kandidati': [
|
||||
{
|
||||
'POSoznake': tk['term_example_pos'],
|
||||
'kandidat': tk['lemma'], # more to bit lemma al terms?
|
||||
'kanonicnaoblika': tk['canonical'],
|
||||
'ranking': tk['ranking'],
|
||||
'podporneutezi': [
|
||||
0.0, # ????????
|
||||
0.0 # ??????
|
||||
],
|
||||
'pogostostpojavljanja': [tk['frequency'], 0] # ???????
|
||||
}
|
||||
for tk in data if tk['canonical'] not in prepovedane_besede
|
||||
]}
|
||||
|
||||
|
||||
|
||||
|
||||
if definicije:
|
||||
print("grem po definicije!!!")
|
||||
ret = txt_utils.extract_definition_sentences(tmp_file_path,ret);
|
||||
|
||||
except Exception as e: print(e)
|
||||
finally:
|
||||
fp.close()
|
||||
os.remove(tmp_file_path)
|
||||
|
||||
ret = {'terminoloski_kandidati': [
|
||||
{
|
||||
'POSoznake': tk['msd'],
|
||||
'kandidat': tk['terms'], # more to bit lemma al terms?
|
||||
'kanonicnaoblika': tk['canonical'],
|
||||
'ranking': tk['ranking'],
|
||||
'podporneutezi': [
|
||||
0.0, # ????????
|
||||
0.0 # ??????
|
||||
],
|
||||
'pogostostpojavljanja': [0, 0] # ???????
|
||||
}
|
||||
for tk in data if tk['terms'] not in prepovedane_besede
|
||||
]}
|
||||
return ret, 200
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return str(e), 500
|
||||
|
||||
|
||||
@@ -84,5 +100,5 @@ def get_candidates_sync(body): # noqa: E501
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = IzlusciSyncBody.from_dict(connexion.request.get_json()) # noqa: E501
|
||||
|
||||
return do_izlusci(body.conllus, body.prepovedane_besede)
|
||||
print(body)
|
||||
return do_izlusci(body.conllus, body.prepovedane_besede,body.definicije)
|
||||
|
||||
Reference in New Issue
Block a user