",
-# r"uniquename=(.*?),hash=(.*?)",
-# r"hash=(.*?)",
-# ]
-# for strReplace in listReplace:
-# tmpContent = re.sub(strReplace, "", tmpContent)
-
-# # Put Back Underscore _
-# tmpContent = re.sub(r"", "_", tmpContent)
-
-# # Remove empty Lines
-# tmpContent = re.sub(r"\n\n", "\n", tmpContent)
-
-# # Put back Ampersand
-# tmpContent = re.sub(r"&", "&", tmpContent)
-# tmpFile = open((args.filename) + "bib.xml", "w")
-# tmpFile.write(tmpContent)
-# tmpFile.close()
-
-# # TeXML has been sanitized, now load xml-Tree
-# xmlParser2 = etree.XMLParser(no_network=False,load_dtd=False)
-# xmlBibTree = etree.parse((args.filename + "bib.xml"), xmlParser2)
-# xml_bib_entries = xmlBibTree.findall(".//entry")
-
-###########################
-# end of the old solution #
-###########################
-
make_bibchecker(bib_database, set_citations)
# If Bibliography-Type is monograph search for EOAbibliography and make it all
if bib_type == "monograph":
if xmlTree.find(".//EOAprintbibliography") is not None:
- # to insert here: with keywords we can have multiple bibliographies
- xmlBibliography = xmlTree.find(".//EOAprintbibliography")
- bibliography_keyword = xmlBibliography.get("keyword")
- if bibliography_keyword:
- logging.debug(f"Found bibliography keyword {bibliography_keyword}")
+ xmlBibliographies = xmlTree.findall(".//EOAprintbibliography")
+ logging.debug(f"Found {libeoaconvert.plural(len(xmlBibliographies), 'bibliography', plural='bibliographies')}.")
+ if len(xmlBibliographies) > 1:
+ for xmlBibliography in xmlBibliographies:
+ bibliography_keyword = xmlBibliography.get("keyword")
+ if bibliography_keyword:
+ logging.debug(f"Found bibliography keyword {bibliography_keyword}")
+ else:
+ logging.error(f"No bibliography keyword found. Since there is more than one bibliography, all bibliographies are required to have a keyword. Exiting ")
+ sys.exit()
else:
- logging.debug(f"No bibliography keyword found")
+ if xmlBibliographies[0].get("keyword"):
+ logging.warning("Found a keyword in bibliography although there is only one.")
+
+ # find all citekeys in publication
+ citekeys = xmlTree.xpath(".//citekey/text()")
+ nocite_elements = xmlTree.xpath(".//nocite")
+
+ if nocite_elements:
+ logging.debug(f"Found {libeoaconvert.plural(len(nocite_elements), 'nocite command')}.")
+ nocitekeys = []
+ for nocite in nocite_elements:
+ keys = [x.strip() for x in nocite.text.split(",")]
+ nocitekeys += keys
+ nocite.tag = "elementtobestripped"
+ logging.debug(f"Found {libeoaconvert.plural(len(set(nocitekeys)), 'nocite key')}.")
+ logging.debug(f"Adding nocite keys to the other cite keys.")
+ citekeys += nocitekeys
+
+ # create a formatted file for all references
+ tmp_citation_filename = f"used_citations-monograph"
+ citations_to_format = set(citekeys)
+ formatted_references = libeoaconvert.format_citations(citations_to_format, bib_database + ".bib", strLanguage, tmp_citation_filename)[0]
- xmlBibliography.clear()
- xmlBibliography.tag = "div"
+ # printbibliographydict = {}
- bib_parent = xmlBibliography.getparent()
- bib_parent.tag = "div"
+ for xmlBibliography in xmlBibliographies:
+ bibliography_keyword = xmlBibliography.get("keyword")
+ xmlBibliography.clear()
+ xmlBibliography.tag = "div"
+ if bibliography_keyword:
+ xmlBibliography.set("keyword", bibliography_keyword)
- xmlBibliographyDiv = etree.Element("div")
- xmlBibliography.addnext(xmlBibliographyDiv)
- ###############
- # new version #
- ###############
- tmp_citation_filename = "used_citations-monograph"
- citations_to_format = [x["id"] for x in citations_json if x["keyword"] == bibliography_keyword]
- formatted_references = libeoaconvert.format_citations(citations_to_format, bib_database + ".bib", strLanguage, tmp_citation_filename)[0]
- fixed_entries = libeoaconvert.fix_bib_entries(formatted_references)
- for entry in fixed_entries:
- xmlBibliographyDiv.append(entry)
- ######################
- # end of new version #
- ######################
+ bib_parent = xmlBibliography.getparent()
+ bib_parent.tag = "div"
- ###############
- # old version #
- ###############
- # xml_bib_entries = xmlBibTree.findall(".//entry")
- # intNumberOfEntry = 0
- # for xmlEntry in xml_bib_entries:
- # if intNumberOfEntry == 0:
- # # Don't check for previous author if first entry of the Bibliography
- # bibEntry = Bibitem(xmlEntry)
- # strNewentry = "" + createBibEntryAuthorYear(bibEntry, boolSameAuthor=False) + "
"
- # else:
- # bibEntry = Bibitem(xmlEntry)
- # # Check if author of previous Entry is the same
- # bibEntryPrevious = Bibitem(xml_bib_entries[intNumberOfEntry - 1])
- # if bibEntry.fullauthorlastfirst()[0] == bibEntryPrevious.fullauthorlastfirst()[0]:
- # strNewentry = "" + createBibEntryAuthorYear(bibEntry, boolSameAuthor=True) + "
"
- # elif bibEntryPrevious.fullauthorlastfirst()[0] == bibEntry.fullauthorlastfirst()[0]:
- # strNewentry = "" + createBibEntryAuthorYear(bibEntry, boolSameAuthor=True) + "
"
- # elif bibEntry.fullauthorlastfirst()[0] == bibEntryPrevious.fullauthorlastfirst()[0]:
- # strNewentry = "" + createBibEntryAuthorYear(bibEntry, boolSameAuthor=True) + "
"
- # else:
- # strNewentry = "" + createBibEntryAuthorYear(bibEntry, boolSameAuthor=False) + "
"
-
- # xmlNew = etree.fromstring(strNewentry)
- # next one writes the bibliography into the document
- # xmlBibliography.append(xmlNew)
-
- # intNumberOfEntry += 1
- ######################
- # end of old version #
- ######################
+ # xmlBibliographyDiv = etree.Element("divxbd")
+ # if bibliography_keyword:
+ # xmlBibliographyDiv.set("keyword", bibliography_keyword)
+ # xmlBibliography.addnext(xmlBibliographyDiv)
+ # create bibliographies per keyword
+ if bibliography_keyword:
+ tmp_citation_filename = f"used_citations-monograph_{bibliography_keyword}"
+ logging.info("We want to collect the entries matching the keywords from the database.")
+
+ citations_with_keyword = [x["id"] for x in citations_json if bibliography_keyword in x["keyword"]]
+ logging.debug(f"Found {libeoaconvert.plural(len(citations_with_keyword), 'citation')} with keyword {bibliography_keyword} in database.")
+
+ citations_to_format = [x for x in citations_with_keyword if x in citekeys]
+ logging.debug(f"Found {libeoaconvert.plural(len(citations_to_format), 'citation')} with keyword {bibliography_keyword} that are actually cited.")
+
+ formatted_references = libeoaconvert.format_citations(citations_to_format, bib_database + ".bib", strLanguage, tmp_citation_filename)[0]
+
+ fixed_entries = libeoaconvert.fix_bib_entries(formatted_references)
+ for entry in fixed_entries:
+ xmlBibliography.append(entry)
+ # printbibliographydict[bibliography_keyword] = xmlBibliographyDiv
# If Bibliography-Type is anthology search for EOAbibliography and make one per chapter
if bib_type == "anthology":
@@ -1400,45 +1328,6 @@ def cleanup():
###################
# If Bibliography-Type is monograph find all entries, forget about refsection
- ###############
- # old version #
- ###############
- """
- if bib_type == "monograph":
- xml_bib_entries = xmlBibTree.findall(".//entry")
- for xmlEntry in xml_bib_entries:
- bibEntry = Bibitem(xmlEntry)
- if bibEntry.citekey() == xmlCitation.find("./citekey").text:
- if xmlCitation.tag == "EOAciteauthoryear":
- strCitation = bibEntry.shortauthor() + " " + bibEntry.labelyear()
- if bibEntry.labelyearsuffix() is not None:
- strCitation = strCitation + bibEntry.labelyearsuffix()
- strTitle = bibEntry.title()
- if xmlCitation.tag == "EOAciteyear":
- strCitation = bibEntry.labelyear()
- if bibEntry.labelyearsuffix() is not None:
- strCitation = strCitation + bibEntry.labelyearsuffix()
- strTitle = bibEntry.title()
- if xmlCitation.tag == "EOAcitemanual":
- cite_text = xmlCitation.find("citetext")
- if cite_text.getchildren():
- tmp_string = xmlCitation.find("citetext")
- tmp_string = cite_text.getchildren()[0]
- strCitation = etree.tostring(tmp_string)
- # BAUSTELLE!!!!!
- # tmp_string2 = etree.tostring(tmp_string)
- # tmp_string3 = tmp_string2.decode()
- # strCitation = tmp_string3.replace("<", "<")
- else:
- strCitation = xmlCitation.find("citetext").text
- strTitle = bibEntry.title()
- if xmlCitation.find("./page") is not None and xmlCitation.find("./page").text is not None:
- strCitation = strCitation + ", " + xmlCitation.find("./page").text
- """
- ######################
- # end of old version #
- ######################
-
###############
# new version #
###############