diff --git a/tei2imxml.py b/tei2imxml.py index 62c424b..8be6564 100755 --- a/tei2imxml.py +++ b/tei2imxml.py @@ -850,7 +850,7 @@ def assign_ids(xml_tree, data): return xml_tree, data # def assign_ids ends here -def update_ids(xml_tree): +def update_ids(xml_tree, ignore_ref_errors): """Update the references in EOAref to the id value assigned in assign_ids""" xmlReferences = xml_tree.findall(".//EOAref") @@ -870,16 +870,22 @@ def update_ids(xml_tree): logging.debug("The corresponding id element is %s", corresponding_eoa_id_element) # if corresponding_eoa_id_element is None: if len(corresponding_eoa_id_element) == 0: - logging.error("There seems to be no corresponding xml:id for %s. Exiting." % label_text) - sys.exit(1) + if ignore_ref_errors: + logging.warning(f"Found no corresponding xml:id for {label_text}. Ignoring it for now.") + eoa_reference.set("target", "??") + else: + logging.error("There seems to be no corresponding xml:id for %s. Exiting." % label_text) + sys.exit(1) elif len(corresponding_eoa_id_element) > 1: - logging.error("The xml:id %s has been assigned more than once. This is not allowed. Exiting." % corresponding_eoa_id_element) - sys.exit(1) + if ignore_ref_errors: + pass + else: + logging.error("The xml:id %s has been assigned more than once. This is not allowed. Exiting." % corresponding_eoa_id_element) + sys.exit(1) else: eoa_id_element = corresponding_eoa_id_element[0] - - eoa_id = eoa_id_element.get("id") - eoa_reference.set("target", eoa_id) + eoa_id = eoa_id_element.get("id") + eoa_reference.set("target", eoa_id) return xml_tree # def update_ids ends here @@ -962,7 +968,7 @@ def convert_bibliography_to_dict(bib_data): bibliography_dict = btb.entries_dict return bibliography_dict -# deef convert_bibliography_to_dict ends here +# def convert_bibliography_to_dict ends here def make_bibliography_pandoc(used_citekeys, bib_data, citations_json, output_file_root, CSL_FILE): @@ -1145,6 +1151,11 @@ def main(): default = "./output/imxml", help="where to dump all output files" ) + parser.add_argument( + "-i", "--ignore-ref-errors", + action="store_true", + help="Ignore warnings of missing or duplicate ids." + ) parser.add_argument("-d", "--pickleddata", default="./output/imxml/tmp_files/data.pickle", help="Pickled data file to be used.") parser.add_argument("-him", "--hyperimage", action="store_true") @@ -1152,7 +1163,6 @@ def main(): config_file = args.CONFIG_FILE print("The config file is ", config_file) - INPUT_DIR = Path( args.filename ).resolve().parent INPUT_PATH = Path( args.filename ) OUTPUT_DIR = Path( args.output_dir ) @@ -1254,7 +1264,7 @@ def main(): assigned_ids, data_to_pickle = assign_ids(xml_add_bib, data) - updated_xml_tree = update_ids(assigned_ids) + updated_xml_tree = update_ids(assigned_ids, args.ignore_ref_errors) # libeoaconvert.debug_xml_here(updated_xml_tree, "updated_tree") # nearly_final_tree = etree.ElementTree(updated_xml_tree) # xml_root = nearly_final_tree.getroot()