IssueID #1487: removed redundant reliance on original list file

This commit is contained in:
Cyprian Laskowski 2020-11-19 17:03:44 +01:00
parent 8e4133d45e
commit 9d8bd3f43e

View File

@ -6,27 +6,24 @@ import lxml.etree as lxml
from constants import * from constants import *
arg_parser = argparse.ArgumentParser(description='Assign parsed Slovene strings to structures and generate lexicon.') arg_parser = argparse.ArgumentParser(description='Assign parsed Slovene strings to structures and generate lexicon.')
arg_parser.add_argument('-inlist', type=str, help='Original input list file')
arg_parser.add_argument('-intei', type=str, help='Parsed and manually edited TEI file') arg_parser.add_argument('-intei', type=str, help='Parsed and manually edited TEI file')
arg_parser.add_argument('-outstructures', type=str, help='Output structure file') arg_parser.add_argument('-outstructures', type=str, help='Output structure file')
arg_parser.add_argument('-outlexicon', type=str, help='Output lexicon file') arg_parser.add_argument('-outlexicon', type=str, help='Output lexicon file')
arguments = arg_parser.parse_args() arguments = arg_parser.parse_args()
input_list_file_name = arguments.inlist
input_tei_file_name = arguments.intei input_tei_file_name = arguments.intei
output_structure_file_name = arguments.outstructures output_structure_file_name = arguments.outstructures
output_lexicon_file_name = arguments.outlexicon output_lexicon_file_name = arguments.outlexicon
def run_pipeline(input_list_file_name, input_tei_file_name, output_lexicon_file_name, output_structure_file_name): def run_pipeline(input_tei_file_name, output_lexicon_file_name, output_structure_file_name):
shutil.rmtree(TMP_DIRECTORY, True) shutil.rmtree(TMP_DIRECTORY, True)
os.makedirs(TMP_DIRECTORY, exist_ok=True) os.makedirs(TMP_DIRECTORY, exist_ok=True)
shutil.copyfile(input_list_file_name, STRING_LIST_FILE_NAME)
shutil.copyfile(input_tei_file_name, TEI_INIT_FILE_NAME) shutil.copyfile(input_tei_file_name, TEI_INIT_FILE_NAME)
run_mwe_extraction(STRUCTURE_CURRENT_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_1_FILE_NAME) run_mwe_extraction(STRUCTURE_CURRENT_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_1_FILE_NAME)
run_structure_assignment(STRING_LIST_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_1_FILE_NAME, TEI_STRUCTURE_1_FILE_NAME) run_structure_assignment(TEI_INIT_FILE_NAME, MWE_CSV_1_FILE_NAME, TEI_STRUCTURE_1_FILE_NAME)
run_structure_creation(STRUCTURE_CURRENT_FILE_NAME, TEI_STRUCTURE_1_FILE_NAME, STRUCTURE_NEW_FILE_NAME) run_structure_creation(STRUCTURE_CURRENT_FILE_NAME, TEI_STRUCTURE_1_FILE_NAME, STRUCTURE_NEW_FILE_NAME)
validate_structures(STRUCTURE_NEW_FILE_NAME) validate_structures(STRUCTURE_NEW_FILE_NAME)
run_mwe_extraction(STRUCTURE_NEW_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_2_FILE_NAME) run_mwe_extraction(STRUCTURE_NEW_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_2_FILE_NAME)
run_structure_assignment(STRING_LIST_FILE_NAME, TEI_INIT_FILE_NAME, MWE_CSV_2_FILE_NAME, TEI_STRUCTURE_2_FILE_NAME) run_structure_assignment(TEI_INIT_FILE_NAME, MWE_CSV_2_FILE_NAME, TEI_STRUCTURE_2_FILE_NAME)
run_dictionary_conversion(TEI_STRUCTURE_2_FILE_NAME, DICTIONARY_XML_FILE_NAME) run_dictionary_conversion(TEI_STRUCTURE_2_FILE_NAME, DICTIONARY_XML_FILE_NAME)
validate_dictionary(DICTIONARY_XML_FILE_NAME) validate_dictionary(DICTIONARY_XML_FILE_NAME)
shutil.copyfile(DICTIONARY_XML_FILE_NAME, output_lexicon_file_name) shutil.copyfile(DICTIONARY_XML_FILE_NAME, output_lexicon_file_name)
@ -44,9 +41,9 @@ def validate_structures(structure_file_name):
xml_tree = lxml.parse(structure_file_name) xml_tree = lxml.parse(structure_file_name)
xml_schema.assertValid(xml_tree) xml_schema.assertValid(xml_tree)
def run_structure_assignment(input_file_name, tei_file_name, mwe_csv_file_name, output_file_name): def run_structure_assignment(tei_file_name, mwe_csv_file_name, output_file_name):
print('Assigning structure ids ...') print('Assigning structure ids ...')
assignment_command = ' '.join(['python', STRUCTURE_ASSIGNMENT_SCRIPT_NAME, input_file_name, tei_file_name, mwe_csv_file_name, output_file_name]) assignment_command = ' '.join(['python', STRUCTURE_ASSIGNMENT_SCRIPT_NAME, tei_file_name, mwe_csv_file_name, output_file_name])
os.system(assignment_command) os.system(assignment_command)
def run_structure_creation(input_file_name, tei_file_name, output_file_name): def run_structure_creation(input_file_name, tei_file_name, output_file_name):
@ -65,4 +62,4 @@ def validate_dictionary(dictionary_file_name):
xml_tree = lxml.parse(dictionary_file_name) xml_tree = lxml.parse(dictionary_file_name)
xml_schema.assertValid(xml_tree) xml_schema.assertValid(xml_tree)
run_pipeline(input_list_file_name, input_tei_file_name, output_lexicon_file_name, output_structure_file_name) run_pipeline(input_tei_file_name, output_lexicon_file_name, output_structure_file_name)