Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ignore chapters without citations
  • Loading branch information
kthoden committed Jul 18, 2019
1 parent c0f3e4c commit bc4e42c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions tei2imxml.py
Expand Up @@ -1207,6 +1207,7 @@ def main():
# citations_json = convert_bibliography_to_json(bib_data, TEMP_DIR)
citations_dict = convert_bibliography_to_dict(bib_data)

logging.debug("Creating bibliographies.")
if bib_data["type"] == "monograph":
used_citekeys = get_all_citations(xml_tree)
citations_filename_root = Path(TEMP_DIR, "formatted_citations_monograph")
Expand All @@ -1224,20 +1225,24 @@ def main():
for chapter_id in all_chapter_ids:
used_citekeys_per_chapter = citations_per_chapter[chapter_id]
logging.debug(f"{len(used_citekeys_per_chapter)} citations in this chapter")
citations_filename_root = Path(TEMP_DIR, f"formatted_citations_{chapter_id}")
# citations_filename_html_per_chapter = make_bibliography_pandoc(used_citekeys_per_chapter, bib_data, citations_json, citations_filename_root, CSL_FILE)
citations_filename_html_per_chapter = make_bibliography_tex4ht(used_citekeys_per_chapter, bib_data, citations_filename_root, publication_language, TEMP_DIR, LOG_DIR)

logging.info("Formatting citations now.")
cited_dict_per_chapter = format_citations(used_citekeys_per_chapter, citations_dict, citations_filename_html_per_chapter)
# Merge dictionaries
cited_dict = {**cited_dict, **cited_dict_per_chapter}

refs_for_bib_chapter = format_reference_list(used_citekeys_per_chapter, citations_filename_html_per_chapter)
tmp_dict_key = "dict_" + chapter_id
# create a dictionary entry containing the formatted references
formatted_references_dict[tmp_dict_key] = refs_for_bib_chapter
logging.debug(f"cited_dict now has {libeoaconvert.plural(len(cited_dict), 'entry', plural='entries')}.")
if not used_citekeys_per_chapter:
logging.debug("No citations found, advancing to next chapter.")
continue
else:
citations_filename_root = Path(TEMP_DIR, f"formatted_citations_{chapter_id}")
# citations_filename_html_per_chapter = make_bibliography_pandoc(used_citekeys_per_chapter, bib_data, citations_json, citations_filename_root, CSL_FILE)
citations_filename_html_per_chapter = make_bibliography_tex4ht(used_citekeys_per_chapter, bib_data, citations_filename_root, publication_language, TEMP_DIR, LOG_DIR)

logging.info("Formatting citations now.")
cited_dict_per_chapter = format_citations(used_citekeys_per_chapter, citations_dict, citations_filename_html_per_chapter)
# Merge dictionaries
cited_dict = {**cited_dict, **cited_dict_per_chapter}

refs_for_bib_chapter = format_reference_list(used_citekeys_per_chapter, citations_filename_html_per_chapter)
tmp_dict_key = "dict_" + chapter_id
# create a dictionary entry containing the formatted references
formatted_references_dict[tmp_dict_key] = refs_for_bib_chapter
logging.debug(f"cited_dict now has {libeoaconvert.plural(len(cited_dict), 'entry', plural='entries')}.")

tei_body = xml_tree.xpath("//t:body", namespaces=NS_MAP)[0]
if args.hyperimage:
Expand Down

0 comments on commit bc4e42c

Please sign in to comment.