Hitri popravki in navodila

This commit is contained in:
Marko Ferme
2022-08-31 06:52:47 +02:00
parent fedb72f1d7
commit 5a87193490
4 changed files with 72 additions and 27 deletions
+5
View File
@@ -11,3 +11,8 @@ services:
- ./swagger_server/classla/classla_resources:/root/classla_resources
environment:
- PYTHONUNBUFFERED=1
tika:
image: apache/tika
restart: always
ports:
- 9998:9998
+2 -1
View File
@@ -10,4 +10,5 @@ python-decouple==3.6
pandas==1.3.3
python-docx==0.8.11
lxml==4.8.0
PyPDF2==2.10.4
PyPDF2==2.10.4
requests
@@ -1,6 +1,7 @@
import connexion
import six
# import tika
import requests
from swagger_server import util
import pandas as pd
@@ -20,37 +21,25 @@ def datoteka_v_besedilo_post(file=None): # noqa: E501
:rtype: str
"""
#zakaj ? tika server se požene zraven v dodatnem containerju in se datoteka samo pošlje tja, nazaj pa se dobi čisto besedilo...
#tika ima rest api
if file is None:
return "No file provided", 400
elif "openxmlformats-officedocument.wordprocessingml.document" in file.content_type:
content = [p.text for p in docx.Document(file).paragraphs]
elif "text/plain" in file.content_type:
content = file.read().decode('utf-8')
elif "application/pdf" in file.content_type:
reader = PdfReader(file)
content = '\n'.join([p.extract_text() for p in reader.pages])
content = "ZACASNO UPORABLJEN DRUGI BRALEC KOT TIKA, TA BO SE DODANA KASNEJE...\n\n" + content
elif "text/xml" in file.content_type:
root = ET.parse(file).getroot()
plainText = root.findall('PlainText')
if len(plainText) == 0:
return "Didn't find anything in PlainText", 400
content = '\n'.join([pt.text for pt in plainText])
else:
return "Currently supporing only docx, txt/plain, pdf, xml*... more will be added later", 501
return content, 200
tika_server="http://tika:9998/tika"
response=requests.post(tika_server, data=file)
return response.text, 200
def get_text_ocr(file=None): # noqa: E501
"""Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v besedilo s pomočjo ocr razpoznavanja
# noqa: E501
if file is None:
return "No file provided", 400
tika_server="http://tika:9998/tika"
#za ocr se zraven samo doda header
response=requests.post(tika_server, data=file,headers={"X-Tika-PDFOcrStrategy":"ocr_only","X-Tika-OCRLanguage":"slv+eng"})
return response.text, 200
:param file:
:type file: strstr
:rtype: str
"""
return 'Not yet implemented'
@@ -18,4 +18,54 @@ def get_candidates(body): # noqa: E501
"""
if connexion.request.is_json:
body = IzlusciBody.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!3'
data={
terminoloski_kandidati:[
{
"POSoznake": "Ncmsn",
"kandidat": "vpliv",
"kanonicnaoblika": "vpliv",
"nosilnautez": 0.8008282,
"podporneutezi": [
6.0274563,
6.0274563
],
"pogostostpojavljanja": [101,71]
},
{
"POSoznake": "Agpnsg Ncnsg",
"kandidat": "bivalen okolje",
"kanonicnaoblika": "bivalno okolje",
"nosilnautez": 0.60254,
"podporneutezi": [
3.263,
2.134
],
"pogostostpojavljanja": [27,11]
},
{
"POSoznake": "Agpmsny Ncmsn Ncmpg",
"kandidat": "motorični status otrok",
"kanonicnaoblika": "motorični status otrok",
"nosilnautez": 0.3324,
"podporneutezi": [
1.221,
3.323
],
"pogostostpojavljanja": [31,51]
},
{
"POSoznake": "Agpnsn Ncnsn",
"kandidat": "diplomsko delo",
"kanonicnaoblika": "diplomsko delo",
"nosilnautez": 0.2008282,
"podporneutezi": [
0.883,
1.02
],
"pogostostpojavljanja": [1241,111]
}
]
}
return data