You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
import os
|
|
|
|
|
|
import lxml.etree as lxml
|
|
|
|
from flask import Flask, Response
|
|
from flask_httpauth import HTTPBasicAuth
|
|
|
|
from structure_assignment.pipeline import Pipeline, create_nlp
|
|
|
|
app = Flask(__name__)
|
|
api_prefix = os.environ['API_PREFIX']
|
|
resource_directory = os.environ['API_RESOURCE_DIR']
|
|
|
|
nlp = create_nlp(resource_directory)
|
|
|
|
@app.route(api_prefix + '/test/<string:string>', methods=['GET'])
|
|
def test(string):
|
|
|
|
string_file_name = '/tmp/string.txt'
|
|
parse_file_name = '/tmp/parse.xml'
|
|
|
|
with open(string_file_name, 'w') as string_file:
|
|
string_file.write(string + '\n')
|
|
|
|
try:
|
|
# pipeline = Pipeline(nlp)
|
|
# pipeline.import_file(string_file_name, 'strings-list')
|
|
# pipeline.do_tokenise()
|
|
# pipeline.do_tweak_conllu()
|
|
# pipeline.do_parse()
|
|
# pipeline.do_translate_jos()
|
|
# pipeline.do_conllu_to_tei()
|
|
# pipeline.export_file(parse_file_name, 'tei-initial')
|
|
# pipeline.cleanup()
|
|
import sys
|
|
sys.path.insert(0, resource_directory)
|
|
print(sys.path)
|
|
import wani
|
|
tei = lxml.parse(parse_file_name).getroot()
|
|
message = lxml.tostring(tei, encoding='UTF-8', pretty_print=True).decode()
|
|
except Exception as e:
|
|
message = lxml.tostring('<error>' + str(e) + '</error>').decode()
|
|
return Response(message, mimetype='text/xml')
|