diff --git a/scripts/process.py b/scripts/process.py index fcfb48a..f1e9f9a 100644 --- a/scripts/process.py +++ b/scripts/process.py @@ -1,24 +1,26 @@ import argparse import tempfile -import os +import shutil from structure_assignment.pipeline import Pipeline, create_nlp resource_directory = '../resources' def run_all(input_file_name, output_file_name, nlp, structure_file_name): - tmp_file_name = tempfile.mksfile() - string_to_parse(input_file_name, tmp_file_name, nlp) + tmp_directory = tempfile.mkdtemp() + tmp_file_name = tmp_directory + '/parsed.xml' + strings_to_parse(input_file_name, tmp_file_name, nlp) parse_to_dictionary(tmp_file_name, output_file_name, structure_file_name) - os.remove(tmp_file_name) + shutil.rmtree(tmp_directory) validate_structures(structure_file_name) validate_dictionary(output_file_name) def strings_to_dictionary(input_file_name, output_file_name, nlp, structure_file_name): - tmp_file_name = tempfile.mksfile() - string_to_parse(input_file_name, tmp_file_name, nlp) + tmp_directory = tempfile.mkdtemp() + tmp_file_name = tmp_directory + '/parsed.xml' + strings_to_parse(input_file_name, tmp_file_name, nlp) parse_to_dictionary(tmp_file_name, output_file_name, structure_file_name) - os.remove(tmp_file_name) + shutil.rmtree(tmp_directory) def strings_to_parse(input_file_name, output_file_name, nlp): pipeline = Pipeline(resource_directory, nlp)