|
|
|
@ -29,7 +29,7 @@ def strings_to_parse():
|
|
|
|
|
string_file.write(string + '\n')
|
|
|
|
|
string_file.close()
|
|
|
|
|
elif (request.method == 'POST'):
|
|
|
|
|
file_data = request.files['file']
|
|
|
|
|
file_data = request.files['strings']
|
|
|
|
|
file_data.save(string_file_name)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -49,19 +49,22 @@ def parse_to_dictionary():
|
|
|
|
|
tmp_directory = tempfile.mkdtemp()
|
|
|
|
|
parsed_file_name = tmp_directory + '/input_parsed.xml'
|
|
|
|
|
dictionary_file_name = tmp_directory + '/output_dictionary.xml'
|
|
|
|
|
structure_file_name = tmp_directory + '/output_structures.xml'
|
|
|
|
|
input_structure_file_name = tmp_directory + '/input_structures.xml'
|
|
|
|
|
output_structure_file_name = tmp_directory + '/output_structures.xml'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
file_data = request.files['file']
|
|
|
|
|
file_data.save(parsed_file_name)
|
|
|
|
|
parsed_file_data = request.files['parsed']
|
|
|
|
|
parsed_file_data.save(parsed_file_name)
|
|
|
|
|
structure_file_data = request.files['structures']
|
|
|
|
|
structure_file_data.save(input_structure_file_name)
|
|
|
|
|
|
|
|
|
|
runner.parse_to_dictionary(parsed_file_name, dictionary_file_name, structure_file_name)
|
|
|
|
|
runner.parse_to_dictionary(parsed_file_name, dictionary_file_name, input_structure_file_name, output_structure_file_name)
|
|
|
|
|
root = lxml.Element('response')
|
|
|
|
|
|
|
|
|
|
dictionary_root = lxml.parse(dictionary_file_name).getroot()
|
|
|
|
|
root.append(dictionary_root)
|
|
|
|
|
structure_root = lxml.parse(structure_file_name).getroot()
|
|
|
|
|
structure_root = lxml.parse(output_structure_file_name).getroot()
|
|
|
|
|
new_structure_count = len(structure_root.xpath('.//syntactic_structure[@tempId]'))
|
|
|
|
|
root.set('new_structures', str(new_structure_count))
|
|
|
|
|
structure_ids = set(dictionary_root.xpath('.//lexicalUnit/@structure_id'))
|
|
|
|
@ -79,30 +82,28 @@ def parse_to_dictionary():
|
|
|
|
|
return Response(message, mimetype='text/xml')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route(api_prefix + '/strings_to_dictionary', methods=['GET', 'POST'])
|
|
|
|
|
@app.route(api_prefix + '/strings_to_dictionary', methods=['POST'])
|
|
|
|
|
def strings_to_dictionary():
|
|
|
|
|
|
|
|
|
|
tmp_directory = tempfile.mkdtemp()
|
|
|
|
|
string_file_name = tmp_directory + '/input_string.txt'
|
|
|
|
|
dictionary_file_name = tmp_directory + '/output_dictionary.xml'
|
|
|
|
|
structure_file_name = tmp_directory + '/output_structures.xml'
|
|
|
|
|
input_structure_file_name = tmp_directory + '/input_structures.xml'
|
|
|
|
|
output_structure_file_name = tmp_directory + '/output_structures.xml'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
if (request.method == 'GET'):
|
|
|
|
|
string = request.args.get('string')
|
|
|
|
|
with open(string_file_name, 'w') as string_file:
|
|
|
|
|
string_file.write(string + '\n')
|
|
|
|
|
elif (request.method == 'POST'):
|
|
|
|
|
file_data = request.files['file']
|
|
|
|
|
file_data.save(string_file_name)
|
|
|
|
|
string_file_data = request.files['strings']
|
|
|
|
|
string_file_data.save(string_file_name)
|
|
|
|
|
structure_file_data = request.files['structures']
|
|
|
|
|
structure_file_data.save(input_structure_file_name)
|
|
|
|
|
|
|
|
|
|
runner.strings_to_dictionary(string_file_name, dictionary_file_name, structure_file_name)
|
|
|
|
|
runner.strings_to_dictionary(string_file_name, dictionary_file_name, input_structure_file_name, output_structure_file_name)
|
|
|
|
|
root = lxml.Element('response')
|
|
|
|
|
|
|
|
|
|
dictionary_root = lxml.parse(dictionary_file_name).getroot()
|
|
|
|
|
root.append(dictionary_root)
|
|
|
|
|
structure_root = lxml.parse(structure_file_name).getroot()
|
|
|
|
|
structure_root = lxml.parse(output_structure_file_name).getroot()
|
|
|
|
|
new_structure_count = len(structure_root.xpath('.//syntactic_structure[@tempId]'))
|
|
|
|
|
root.set('new_structures', str(new_structure_count))
|
|
|
|
|
structure_ids = set(dictionary_root.xpath('.//lexicalUnit/@structure_id'))
|
|
|
|
|