Dodana endpointa za sync pridobivanje connlu-jev, ali preprosto file -> text, ali file -> ocr -> text.

This commit is contained in:
Kikimanox
2022-08-31 15:37:04 +02:00
parent c30b014a68
commit f16c78bbdc
6 changed files with 323 additions and 26 deletions
+80 -2
View File
@@ -135,6 +135,44 @@
} }
} }
}, },
"/datotekaVBesedilo": {
"post": {
"tags": [
"doc-2text"
],
"summary": "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca besedilo",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"file"
],
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/datotekaVBesedilo/ocr": { "/datotekaVBesedilo/ocr": {
"post": { "post": {
"tags": [ "tags": [
@@ -174,12 +212,52 @@
} }
} }
}, },
"/datotekaVBesedilo/": { "/datotekaVConlluSync": {
"post": { "post": {
"tags": [ "tags": [
"doc-2text" "doc-2text"
], ],
"summary": "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca besedilo", "summary": "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca conllu",
"operationId": "datotekaVBesediloInClassla",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"file"
],
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/datotekaVConlluSync/ocr": {
"post": {
"tags": [
"doc-2text"
],
"summary": "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v conllu s pomočjo ocr razpoznavanja",
"operationId": "getConlluOcr",
"requestBody": { "requestBody": {
"content": { "content": {
"multipart/form-data": { "multipart/form-data": {
@@ -2,7 +2,6 @@ from tempfile import TemporaryFile
import connexion import connexion
import six import six
# import tika
import requests import requests
import json import json
from swagger_server import util from swagger_server import util
@@ -11,15 +10,16 @@ import docx
import codecs import codecs
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from PyPDF2 import PdfReader from PyPDF2 import PdfReader
from swagger_server.classla import cl_utils
tika_server = "http://tika:9998/tika" tika_server = "http://tika:9998/tika"
# endpoint below to be used only for development purposes (don't need to run docker)
tika_server = "http://rsdo.lhrs.feri.um.si:9998/tika" # tika_server = "http://rsdo.lhrs.feri.um.si:9998/tika"
def datoteka_v_besedilo_post(file=None): # noqa: E501 def datoteka_v_besedilo_post(file=None): # noqa: E501
"""Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v besedilo """Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca besedilo
# noqa: E501 # noqa: E501
@@ -37,10 +37,9 @@ def datoteka_v_besedilo_post(file=None): # noqa: E501
return str(e), 500 return str(e), 500
def get_text_ocr(file=None): def get_text_ocr(file=None): # noqa: E501
"""Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v besedilo s pomočjo ocr razpoznavanja """Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v besedilo s pomočjo ocr razpoznavanja
# noqa: E501 # noqa: E501
:param file: :param file:
@@ -48,13 +47,54 @@ def get_text_ocr(file=None):
:rtype: str :rtype: str
""" """
if file is None: if file is None:
return "No file provided", 400 return "No file provided", 400
try: try:
response = requests.put(tika_server, data=file, response = requests.put(tika_server, data=file,
headers={"X-Tika-PDFOcrStrategy": "ocr_only", "X-Tika-OCRLanguage": "slv+eng"}) headers={"X-Tika-PDFOcrStrategy": "ocr_only", "X-Tika-OCRLanguage": "slv+eng"})
return response.text, 200 return response.text, 200
except Exception as e: except Exception as e:
return str(e), 500 return str(e), 500
def datoteka_v_besedilo_in_classla(file=None): # noqa: E501
"""Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca conllu
# noqa: E501
:param file:
:type file: strstr
:rtype: str
"""
if not cl_utils.nlp_loaded:
return "NLP Models still loading up since server restart, please retry later.", 500
if file is None:
return "No file provided", 400
try:
response = requests.put(tika_server, data=file)
return cl_utils.raw_text_to_conllu(response.text)
except Exception as e:
return str(e), 500
def get_conllu_ocr(file=None): # noqa: E501
"""Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v conllu s pomočjo ocr razpoznavanja
# noqa: E501
:param file:
:type file: strstr
:rtype: str
"""
if not cl_utils.nlp_loaded:
return "NLP Models still loading up since server restart, please retry later.", 500
if file is None:
return "No file provided", 400
try:
response = requests.put(tika_server, data=file,
headers={"X-Tika-PDFOcrStrategy": "ocr_only", "X-Tika-OCRLanguage": "slv+eng"})
return cl_utils.raw_text_to_conllu(response.text)
except Exception as e:
return str(e), 500
+4 -2
View File
@@ -3,9 +3,11 @@
# flake8: noqa # flake8: noqa
from __future__ import absolute_import from __future__ import absolute_import
# import models into model package # import models into model package
from swagger_server.models.datoteka_v_besedilo_body import DatotekaVBesediloBody
from swagger_server.models.datoteka_v_besedilo_ocr_body import DatotekaVBesediloOcrBody
from swagger_server.models.izlusci_body import IzlusciBody from swagger_server.models.izlusci_body import IzlusciBody
from swagger_server.models.oznaci_besedilo_body import OznaciBesediloBody from swagger_server.models.oznaci_besedilo_body import OznaciBesediloBody
from swagger_server.models.terminoloski_kandidat import TerminoloskiKandidat from swagger_server.models.terminoloski_kandidat import TerminoloskiKandidat
from swagger_server.models.job_response import JobResponse from swagger_server.models.job_response import JobResponse
from swagger_server.models.datoteka_v_besedilo_body import DatotekaVBesediloBody
from swagger_server.models.datoteka_v_besedilo_ocr_body import DatotekaVBesediloOcrBody
from swagger_server.models.datoteka_v_conllu_sync_body import DatotekaVConlluSyncBody
from swagger_server.models.datoteka_v_conllu_sync_ocr_body import DatotekaVConlluSyncOcrBody
@@ -0,0 +1,64 @@
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from swagger_server.models.base_model_ import Model
from swagger_server import util
class DatotekaVConlluSyncBody(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, file: str=None): # noqa: E501
"""DatotekaVConlluSyncBody - a model defined in Swagger
:param file: The file of this DatotekaVConlluSyncBody. # noqa: E501
:type file: str
"""
self.swagger_types = {
'file': str
}
self.attribute_map = {
'file': 'file'
}
self._file = file
@classmethod
def from_dict(cls, dikt) -> 'DatotekaVConlluSyncBody':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The datotekaVConlluSync_body of this DatotekaVConlluSyncBody. # noqa: E501
:rtype: DatotekaVConlluSyncBody
"""
return util.deserialize_model(dikt, cls)
@property
def file(self) -> str:
"""Gets the file of this DatotekaVConlluSyncBody.
:return: The file of this DatotekaVConlluSyncBody.
:rtype: str
"""
return self._file
@file.setter
def file(self, file: str):
"""Sets the file of this DatotekaVConlluSyncBody.
:param file: The file of this DatotekaVConlluSyncBody.
:type file: str
"""
if file is None:
raise ValueError("Invalid value for `file`, must not be `None`") # noqa: E501
self._file = file
@@ -0,0 +1,64 @@
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from swagger_server.models.base_model_ import Model
from swagger_server import util
class DatotekaVConlluSyncOcrBody(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, file: str=None): # noqa: E501
"""DatotekaVConlluSyncOcrBody - a model defined in Swagger
:param file: The file of this DatotekaVConlluSyncOcrBody. # noqa: E501
:type file: str
"""
self.swagger_types = {
'file': str
}
self.attribute_map = {
'file': 'file'
}
self._file = file
@classmethod
def from_dict(cls, dikt) -> 'DatotekaVConlluSyncOcrBody':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The datotekaVConlluSync_ocr_body of this DatotekaVConlluSyncOcrBody. # noqa: E501
:rtype: DatotekaVConlluSyncOcrBody
"""
return util.deserialize_model(dikt, cls)
@property
def file(self) -> str:
"""Gets the file of this DatotekaVConlluSyncOcrBody.
:return: The file of this DatotekaVConlluSyncOcrBody.
:rtype: str
"""
return self._file
@file.setter
def file(self, file: str):
"""Sets the file of this DatotekaVConlluSyncOcrBody.
:param file: The file of this DatotekaVConlluSyncOcrBody.
:type file: str
"""
if file is None:
raise ValueError("Invalid value for `file`, must not be `None`") # noqa: E501
self._file = file
+62 -13
View File
@@ -83,6 +83,26 @@ paths:
$ref: '#/components/schemas/TerminoloskiKandidat' $ref: '#/components/schemas/TerminoloskiKandidat'
x-content-type: '*/*' x-content-type: '*/*'
x-openapi-router-controller: swagger_server.controllers.extract_controller x-openapi-router-controller: swagger_server.controllers.extract_controller
/datotekaVBesedilo:
post:
tags:
- doc-2text
summary: "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca besedilo"
operationId: datoteka_v_besedilo_post
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/datotekaVBesedilo_body'
responses:
"200":
description: OK
content:
'*/*':
schema:
type: string
x-content-type: '*/*'
x-openapi-router-controller: swagger_server.controllers.doc2text_controller
/datotekaVBesedilo/ocr: /datotekaVBesedilo/ocr:
post: post:
tags: tags:
@@ -104,17 +124,38 @@ paths:
type: string type: string
x-content-type: '*/*' x-content-type: '*/*'
x-openapi-router-controller: swagger_server.controllers.doc2text_controller x-openapi-router-controller: swagger_server.controllers.doc2text_controller
/datotekaVBesedilo/: /datotekaVConlluSync:
post: post:
tags: tags:
- doc-2text - doc-2text
summary: "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v besedilo" summary: "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... vraca conllu"
operationId: datoteka_v_besedilo_post operationId: datoteka_v_besedilo_in_classla
requestBody: requestBody:
content: content:
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/datotekaVBesedilo_body' $ref: '#/components/schemas/datotekaVConlluSync_body'
responses:
"200":
description: OK
content:
'*/*':
schema:
type: string
x-content-type: '*/*'
x-openapi-router-controller: swagger_server.controllers.doc2text_controller
/datotekaVConlluSync/ocr:
post:
tags:
- doc-2text
summary: "Pretvori datoteko formata pdf, doc, docx, ppt, xls,... v conllu s\
\ pomočjo ocr razpoznavanja"
operationId: get_conllu_ocr
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/datotekaVConlluSync_ocr_body'
responses: responses:
"200": "200":
description: OK description: OK
@@ -553,14 +594,6 @@ components:
type: array type: array
items: items:
type: string type: string
datotekaVBesedilo_ocr_body:
required:
- file
type: object
properties:
file:
type: string
format: binary
datotekaVBesedilo_body: datotekaVBesedilo_body:
required: required:
- file - file
@@ -569,7 +602,23 @@ components:
file: file:
type: string type: string
format: binary format: binary
datotekaVBesediloSync_body: datotekaVBesedilo_ocr_body:
required:
- file
type: object
properties:
file:
type: string
format: binary
datotekaVConlluSync_body:
required:
- file
type: object
properties:
file:
type: string
format: binary
datotekaVConlluSync_ocr_body:
required: required:
- file - file
type: object type: object