def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be bigger than or equal to 30. This format element is an example of large element, which does all the formatting by itself @param width: the width (in number of characters) of the record """ out = "@" width = int(width) if width < 30: width = 30 name_width = 20 value_width = width-name_width recID = bfo.control_field('001') #Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" else: out += collection out += "{" #Print BibTeX key # #Try to have: author_name:recID #If author_name cannot be found, use primary_report_number #If primary_report_number cannot be found, use additional_report_number #If additional_report_number cannot be found, use title:recID #If title cannot be found, use only recID # #The construction of this key is inherited from old BibTeX format #written in EL, in old BibFormat. key = recID author = bfo.field("100__a") if author != "": key = get_name(author)+":"+recID else: author = bfo.field("700__a") if author != "": key = get_name(author)+":"+recID else: primary_report_number = bfo.field("037__a") if primary_report_number != "": key = primary_report_number else: additional_report_number = bfo.field("088__a") if additional_report_number != "": key = primary_report_number else: title = bfo.field("245__a") if title != "": key = get_name(title)+":"+recID out += key +"," #Print authors #If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_authors as bfe_authors authors = bfe_authors.format_element(bfo=bfo, limit="", separator=" and ", extension="", print_links="no") if authors == "": out += format_bibtex_field("key", recID, name_width, value_width) else: out += format_bibtex_field("author", authors, name_width, value_width) #Print editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="", separator=" and ", extension="", print_links="no") out += format_bibtex_field("editor", editors, name_width, value_width) #Print title import invenio.bibformat_elements.bfe_title as bfe_title title = bfe_title.format_element(bfo=bfo, separator = ". ") out += format_bibtex_field("title", '{' + title + '}', name_width, value_width) #Print institution if collection == "techreport": publication_name = bfo.field("269__b") out += format_bibtex_field("institution", publication_name, name_width, value_width) #Print organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += format_bibtex_field("organization", ". ".join(organization), name_width, value_width) #Print publisher if collection == "book" or \ collection == "inproceedings" \ or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += format_bibtex_field("publisher", ". ".join(publishers), name_width, value_width) #Print journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += format_bibtex_field("journal", ". ".join(journals), name_width, value_width) #Print school if collection == "phdthesis": university = bfo.field("502__b") out += format_bibtex_field("school", university, name_width, value_width) # Collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += format_bibtex_field("collaboration", ", ".join(collaborations), name_width, value_width) #Print address if collection == "book" or \ collection == "inproceedings" or \ collection == "proceedings" or \ collection == "phdthesis" or \ collection == "techreport": addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += format_bibtex_field("address", ". ".join(addresses), name_width, value_width) #Print number if collection == "techreport" or \ collection == "article": numbers = [] primary_report_number = bfo.field("037__a") if primary_report_number != "": numbers.append(primary_report_number) additional_report_numbers = bfo.fields("088__a") additional_report_numbers = ". ".join(additional_report_numbers) if additional_report_numbers != "": numbers.append(additional_report_numbers) host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += format_bibtex_field("number", ". ".join(numbers), name_width, value_width) #Print volume if collection == "article" or \ collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += format_bibtex_field("volume", ". ".join(volumes), name_width, value_width) #Print series if collection == "book": series = bfo.field("490__a") out += format_bibtex_field("series", series, name_width, value_width) #Print pages if collection == "article" or \ collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += format_bibtex_field("pages", ". ".join(pages), name_width, value_width) #Print month month = get_month(bfo.field("269__c")) if month == "": month = get_month(bfo.field("260__c")) if month == "": month = get_month(bfo.field("502__c")) out += format_bibtex_field("month", month, name_width, value_width) #Print year year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += format_bibtex_field("year", year, name_width, value_width) #Print note note = bfo.field("500__a") out += format_bibtex_field("note", note, name_width, value_width) out +="\n}" return out
def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be bigger than or equal to 30. This format element is an example of large element, which does all the formatting by itself @param width the width (in number of characters) of the record """ out = "@" width = int(width) if width < 30: width = 30 name_width = 21 value_width = width - name_width recID = bfo.control_field("001") # Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" collection = "article" else: out += collection out += "{" # Print BibTeX key # key = "" for external_keys in bfo.fields("035"): if external_keys["9"] == "SPIRESTeX" and external_keys["z"]: key = external_keys["z"] if not key: # contruct key in spires like way need to store an make unique ####FIXME key = ( bfo.field("100a").split(" ")[0].lower() + ":" + bfo.field("269c").split("-")[0] + chr((recID % 26) + 97) + chr(((recID / 26) % 26) + 97) ) out += key + "," # If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_INSPIRE_authors as bfe_authors authors = bfe_authors.format_element( bfo=bfo, limit="5", separator=" and ", extension=" and others", collaboration="no", print_links="no", name_last_first="yes", ) if authors == "": out += format_bibtex_field("key", recID, name_width, value_width) else: out += format_bibtex_field("author", authors, name_width, value_width) # Print editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="10", separator=" and ", extension="", print_links="no") out += format_bibtex_field("editor", editors, name_width, value_width) # Print title import invenio.bibformat_elements.bfe_INSPIRE_title as bfe_title title = bfe_title.format_element(bfo=bfo) out += format_bibtex_field("title", "{" + title + "}", name_width, value_width) # Print institution if collection == "techreport": publication_name = bfo.field("269__b") out += format_bibtex_field("institution", publication_name, name_width, value_width) # Print organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += format_bibtex_field("organization", ". ".join(organization), name_width, value_width) # Print publisher if collection == "book" or collection == "inproceedings" or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += format_bibtex_field("publisher", ". ".join(publishers), name_width, value_width) # Print collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += format_bibtex_field("collaboration", ", ".join(collaborations), name_width, value_width) # Print school if collection == "phdthesis": university = bfo.field("502__b") out += format_bibtex_field("school", university, name_width, value_width) # Print address if ( collection == "book" or collection == "inproceedings" or collection == "proceedings" or collection == "phdthesis" or collection == "techreport" ): addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += format_bibtex_field("address", ". ".join(addresses), name_width, value_width) # Print journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += format_bibtex_field("journal", ". ".join(journals), name_width, value_width) # Print number if collection == "techreport" or collection == "article": numbers = [] host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += format_bibtex_field("number", ". ".join(numbers), name_width, value_width) # Print volume if collection == "article" or collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += format_bibtex_field("volume", ". ".join(volumes), name_width, value_width) # Print series if collection == "book": series = bfo.field("490__a") out += format_bibtex_field("series", series, name_width, value_width) # Print pages if collection == "article" or collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += format_bibtex_field("pages", ". ".join(pages), name_width, value_width) # Print doi if collection == "article": dois = bfo.fields("773__a") out += format_bibtex_field("doi", ", ".join(dois), name_width, value_width) # Print year year = bfo.field("773__y") if year == "": year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += format_bibtex_field("year", year, name_width, value_width) # Print note note = bfo.field("500__a") out += format_bibtex_field("note", note, name_width, value_width) # Print eprint import invenio.bibformat_elements.bfe_INSPIRE_arxiv as bfe_arxiv eprints = bfe_arxiv.get_arxiv(bfo, category="no") if eprints: eprint = eprints[0] if eprint.upper().startswith("ARXIV:"): eprint = eprint[6:] out += format_bibtex_field("eprint", eprint, name_width, value_width) out += format_bibtex_field("archivePrefix", "arXiv", name_width, value_width) cats = bfe_arxiv.get_cats(bfo) if cats: out += format_bibtex_field("primaryClass", cats[0], name_width, value_width) # other report numbers numbers = [] primary_report_numbers = bfo.fields("037_a") additional_report_numbers = bfo.fields("088_a") report_numbers = primary_report_numbers report_numbers.extend(additional_report_numbers) for number in report_numbers: if number <> eprints[0]: numbers.append(number) if numbers: out += format_bibtex_field("reportNumber", ", ".join(numbers), name_width, value_width) out += "\n}" return out
def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be bigger than or equal to 30. This format element is an example of large element, which does all the formatting by itself @param width the width (in number of characters) of the record """ out = "@" width = int(width) if width < 30: width = 30 name_width = 21 value_width = width-name_width recID = bfo.control_field('001') #Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" collection = "article" else: out += collection out += "{" #Print BibTeX key # key = '' for external_keys in bfo.fields("035"): if external_keys['9'] == "SPIRESTeX" and external_keys['z']: key = external_keys['z'] if not key: #contruct key in spires like way need to store an make unique ####FIXME key = bfo.field("100a").split(' ')[0].lower() + ":" + \ bfo.field("269c").split('-')[0] + \ chr((recID % 26) + 97) + chr(((recID / 26) % 26) + 97) out += key + ',' #If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_INSPIRE_authors as bfe_authors authors = bfe_authors.format_element(bfo=bfo, limit="5", separator=" and ", extension=" and others", collaboration = "no", print_links="no", name_last_first = "yes") if authors == "": out += format_bibtex_field("key", recID, name_width, value_width) else: out += format_bibtex_field("author", authors, name_width, value_width) #Print editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="10", separator=" and ", extension="", print_links="no") out += format_bibtex_field("editor", editors, name_width, value_width) #Print title import invenio.bibformat_elements.bfe_INSPIRE_title as bfe_title title = bfe_title.format_element(bfo=bfo) out += format_bibtex_field("title", '{' + title + '}', name_width, value_width) #Print institution if collection == "techreport": publication_name = bfo.field("269__b") out += format_bibtex_field("institution", publication_name, name_width, value_width) #Print organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += format_bibtex_field("organization", ". ".join(organization), name_width, value_width) #Print publisher if collection == "book" or \ collection == "inproceedings" \ or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += format_bibtex_field("publisher", ". ".join(publishers), name_width, value_width) #Print collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += format_bibtex_field("collaboration", ", ".join(collaborations), name_width, value_width) #Print school if collection == "phdthesis": university = bfo.field("502__b") out += format_bibtex_field("school", university, name_width, value_width) #Print address if collection == "book" or \ collection == "inproceedings" or \ collection == "proceedings" or \ collection == "phdthesis" or \ collection == "techreport": addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += format_bibtex_field("address", ". ".join(addresses), name_width, value_width) #Print journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += format_bibtex_field("journal", ". ".join(journals), name_width, value_width) #Print number if collection == "techreport" or \ collection == "article": numbers = [] host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += format_bibtex_field("number", ". ".join(numbers), name_width, value_width) #Print volume if collection == "article" or \ collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += format_bibtex_field("volume", ". ".join(volumes), name_width, value_width) #Print series if collection == "book": series = bfo.field("490__a") out += format_bibtex_field("series", series, name_width, value_width) #Print pages if collection == "article" or \ collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += format_bibtex_field("pages", ". ".join(pages), name_width, value_width) #Print doi if collection == "article": dois = bfo.fields("773__a") out += format_bibtex_field("doi", ", ".join(dois), name_width, value_width) #Print year year = bfo.field("773__y") if year == "": year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += format_bibtex_field("year", year, name_width, value_width) #Print note note = bfo.field("500__a") out += format_bibtex_field("note", note, name_width, value_width) #Print eprint import invenio.bibformat_elements.bfe_INSPIRE_arxiv as bfe_arxiv eprints = bfe_arxiv.get_arxiv(bfo, category = "no") if eprints: eprint = eprints[0] if eprint.upper().startswith('ARXIV:'): eprint = eprint[6:] out += format_bibtex_field("eprint", eprint, name_width, value_width) out += format_bibtex_field("archivePrefix", "arXiv", name_width, value_width) cats = bfe_arxiv.get_cats(bfo) if cats: out += format_bibtex_field("primaryClass", cats[0], name_width, value_width) #other report numbers numbers=[] primary_report_numbers = bfo.fields('037_a') additional_report_numbers = bfo.fields('088_a') report_numbers = primary_report_numbers report_numbers.extend(additional_report_numbers) for number in report_numbers: if number <> eprints[0]: numbers.append(number) if numbers: out += format_bibtex_field("reportNumber", ", ".join(numbers), name_width, value_width) out +="\n}" return out
def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be >= 30. This format element is an example of a large element, which does all the formatting by itself @param width the width (in number of characters) of the record """ # Values of the note field which should not be displayed. # These are typically added programmatically, so stupid string matching is # ok. If this assumption changes, turn this into a list of regexps to apply # for a match test. note_values_skip = ["* Temporary entry *", "* Brief entry *"] width = int(width) if width < 30: width = 30 name_width = 21 value_width = width-name_width recID = bfo.control_field('001') # Initialize user output out = "@" def texified(name, value): """Closure of format_bibtex_field so we don't keep pasing static data Saves a little bit of boilerplate. """ return format_bibtex_field(name, value, name_width, value_width) #Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" collection = "article" else: out += collection out += "{" # BibTeX key import invenio.bibformat_elements.bfe_texkey as bfe_texkey key = bfe_texkey.format_element(bfo, harvmac=False) # key = '' # for external_keys in bfo.fields("035"): # if external_keys['9'] == "SPIRESTeX" and external_keys['z']: # key = external_keys['z'] # if not key: # #contruct key in spires like way need to store an make unique # ####FIXME # key = bfo.field("100a").split(' ')[0].lower() + ":" + \ # bfo.field("269c").split('-')[0] + \ # chr((recID % 26) + 97) + chr(((recID / 26) % 26) + 97) out += key + ',' #If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_INSPIRE_authors as bfe_authors authors = bfe_authors.format_element(bfo=bfo, limit="5", separator=" and ", extension=" and others", collaboration = "no", print_links="no", name_last_first = "yes") if authors: out += texified("author", authors) else: out += texified("key", recID) # Editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="10", separator=" and ", extension="", print_links="no") out += texified("editor", editors) # Title import invenio.bibformat_elements.bfe_INSPIRE_title_brief as bfe_title title = bfe_title.format_element(bfo=bfo, brief="yes") out += texified("title", '{' + title + '}') # Institution if collection == "techreport": publication_name = bfo.field("269__b") out += texified("institution", publication_name) # Organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += texified("organization", ". ".join(organization)) # Publisher if collection == "book" or \ collection == "inproceedings" \ or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += texified("publisher", ". ".join(publishers)) # Collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += texified("collaboration", ", ".join(collaborations)) # School if collection == "phdthesis": university = bfo.field("502__b") out += texified("school", university) # Address if collection == "book" or \ collection == "inproceedings" or \ collection == "proceedings" or \ collection == "phdthesis" or \ collection == "techreport": addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += texified("address", ". ".join(addresses)) # Journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += texified("journal", ". ".join(journals)) # Number if collection == "techreport" or \ collection == "article": numbers = [] host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += texified("number", ". ".join(numbers)) # Volume if collection == "article" or \ collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += texified("volume", ". ".join(volumes)) # Series if collection == "book": series = bfo.field("490__a") out += texified("series", series) # Pages if collection == "article" or \ collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += texified("pages", ". ".join(pages)) # DOI if collection == "article": dois = bfo.fields("773__a") out += texified("doi", ", ".join(dois)) # Year year = bfo.field("773__y") if year == "": year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += texified("year", year) # Note note = bfo.field("500__a") if note and note not in note_values_skip: out += texified("note", note) # Eprint (aka arxiv number) import invenio.bibformat_elements.bfe_INSPIRE_arxiv as bfe_arxiv eprints = bfe_arxiv.get_arxiv(bfo, category = "no") cats = bfe_arxiv.get_cats(bfo) if eprints: eprint = eprints[0] if eprint.upper().startswith('ARXIV:'): eprint = eprint[6:] out += texified("eprint", eprint) out += texified("archivePrefix", "arXiv") if cats: out += texified("primaryClass", cats[0]) else: # No eprints, but we don't want refs to eprints[0] to error out below # This makes everything work nicely without a lot of extra gating eprints=[''] # Other report numbers out += texified("reportNumber", bfe_repno.get_report_numbers_formatted(bfo, separator=', ', limit='1000', skip=eprints[0])) # Add %%CITATION line import invenio.bibformat_elements.bfe_INSPIRE_publi_info_latex as bfe_pil import invenio.bibformat_elements.bfe_INSPIRE_publi_coden as bfe_coden cite_as = bfe_pil.get_cite_line(arxiv=eprints[0], pubnote=bfe_coden.get_coden_formatted(bfo, ','), repno=bfe_repno.get_report_numbers_formatted(bfo, '', '1'), bfo=bfo) out += texified("SLACcitation", cite_as) out +="\n}" return out
def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be bigger than or equal to 30. This format element is an example of large element, which does all the formatting by itself @param width: the width (in number of characters) of the record """ out = "@" width = int(width) if width < 30: width = 30 name_width = 20 value_width = width - name_width recID = bfo.control_field('001') #Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" else: out += collection out += "{" #Print BibTeX key # #Try to have: author_name:recID #If author_name cannot be found, use primary_report_number #If primary_report_number cannot be found, use additional_report_number #If additional_report_number cannot be found, use title:recID #If title cannot be found, use only recID # #The construction of this key is inherited from old BibTeX format #written in EL, in old BibFormat. key = recID author = bfo.field("100__a") if author != "": key = get_name(author) + ":" + recID else: author = bfo.field("700__a") if author != "": key = get_name(author) + ":" + recID else: primary_report_number = bfo.field("037__a") if primary_report_number != "": key = primary_report_number else: additional_report_number = bfo.field("088__a") if additional_report_number != "": key = primary_report_number else: title = bfo.field("245__a") if title != "": key = get_name(title) + ":" + recID out += key + "," #Print authors #If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_authors as bfe_authors authors = bfe_authors.format_element(bfo=bfo, limit="", separator=" and ", extension="", print_links="no") if authors == "": out += format_bibtex_field("key", recID, name_width, value_width) else: out += format_bibtex_field("author", authors, name_width, value_width) #Print editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="", separator=" and ", extension="", print_links="no") out += format_bibtex_field("editor", editors, name_width, value_width) #Print title import invenio.bibformat_elements.bfe_title as bfe_title title = bfe_title.format_element(bfo=bfo, separator=". ") out += format_bibtex_field("title", '{' + title + '}', name_width, value_width) #Print institution if collection == "techreport": publication_name = bfo.field("269__b") out += format_bibtex_field("institution", publication_name, name_width, value_width) #Print organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += format_bibtex_field("organization", ". ".join(organization), name_width, value_width) #Print publisher if collection == "book" or \ collection == "inproceedings" \ or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += format_bibtex_field("publisher", ". ".join(publishers), name_width, value_width) #Print journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += format_bibtex_field("journal", ". ".join(journals), name_width, value_width) #Print school if collection == "phdthesis": university = bfo.field("502__b") out += format_bibtex_field("school", university, name_width, value_width) # Collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += format_bibtex_field("collaboration", ", ".join(collaborations), name_width, value_width) #Print address if collection == "book" or \ collection == "inproceedings" or \ collection == "proceedings" or \ collection == "phdthesis" or \ collection == "techreport": addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += format_bibtex_field("address", ". ".join(addresses), name_width, value_width) #Print number if collection == "techreport" or \ collection == "article": numbers = [] primary_report_number = bfo.field("037__a") if primary_report_number != "": numbers.append(primary_report_number) additional_report_numbers = bfo.fields("088__a") additional_report_numbers = ". ".join(additional_report_numbers) if additional_report_numbers != "": numbers.append(additional_report_numbers) host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += format_bibtex_field("number", ". ".join(numbers), name_width, value_width) #Print volume if collection == "article" or \ collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += format_bibtex_field("volume", ". ".join(volumes), name_width, value_width) #Print series if collection == "book": series = bfo.field("490__a") out += format_bibtex_field("series", series, name_width, value_width) #Print pages if collection == "article" or \ collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += format_bibtex_field("pages", ". ".join(pages), name_width, value_width) #Print month month = get_month(bfo.field("269__c")) if month == "": month = get_month(bfo.field("260__c")) if month == "": month = get_month(bfo.field("502__c")) out += format_bibtex_field("month", month, name_width, value_width) #Print year year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += format_bibtex_field("year", year, name_width, value_width) #Print note note = bfo.field("500__a") out += format_bibtex_field("note", note, name_width, value_width) out += "\n}" return out
def format_element(bfo, width="50"): """ Prints a full BibTeX record. 'width' must be >= 30. This format element is an example of a large element, which does all the formatting by itself @param width the width (in number of characters) of the record """ # Values of the note field which should not be displayed. # These are typically added programmatically, so stupid string matching is # ok. If this assumption changes, turn this into a list of regexps to apply # for a match test. note_values_skip = ["* Temporary entry *", "* Brief entry *"] width = int(width) if width < 30: width = 30 name_width = 21 value_width = width - name_width recID = bfo.control_field('001') # Initialize user output out = "@" def texified(name, value): """Closure of format_bibtex_field so we don't keep pasing static data Saves a little bit of boilerplate. """ return format_bibtex_field(name, value, name_width, value_width) #Print entry type import invenio.bibformat_elements.bfe_collection as bfe_collection collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX") if collection == "": out += "article" collection = "article" else: out += collection out += "{" # BibTeX key import invenio.bibformat_elements.bfe_texkey as bfe_texkey key = bfe_texkey.format_element(bfo, harvmac=False) # key = '' # for external_keys in bfo.fields("035"): # if external_keys['9'] == "SPIRESTeX" and external_keys['z']: # key = external_keys['z'] # if not key: # #contruct key in spires like way need to store an make unique # ####FIXME # key = bfo.field("100a").split(' ')[0].lower() + ":" + \ # bfo.field("269c").split('-')[0] + \ # chr((recID % 26) + 97) + chr(((recID / 26) % 26) + 97) out += key + ',' #If author cannot be found, print a field key=recID import invenio.bibformat_elements.bfe_INSPIRE_authors as bfe_authors authors = bfe_authors.format_element(bfo=bfo, limit="5", separator=" and ", extension=" and others", collaboration="no", print_links="no", name_last_first="yes") if authors: rx = re.compile('([A-Za-z\,\'\-\s]+?\.)([A-Z][a-z]+)') auspace = rx.sub(r'\1 \2', authors, count=0) out += texified("author", auspace) else: out += texified("key", recID) # Editors import invenio.bibformat_elements.bfe_editors as bfe_editors editors = bfe_editors.format_element(bfo=bfo, limit="10", separator=" and ", extension="", print_links="no") out += texified("editor", editors) # Title import invenio.bibformat_elements.bfe_INSPIRE_title_brief as bfe_title title = bfe_title.format_element(bfo=bfo, brief="yes") out += texified("title", '{' + title + '}') # Institution if collection == "techreport": publication_name = bfo.field("269__b") out += texified("institution", publication_name) # Organization if collection == "inproceedings" or collection == "proceedings": organization = [] organization_1 = bfo.field("260__b") if organization_1 != "": organization.append(organization_1) organization_2 = bfo.field("269__b") if organization_2 != "": organization.append(organization_2) out += texified("organization", ". ".join(organization)) # Publisher if collection == "book" or \ collection == "inproceedings" \ or collection == "proceedings": publishers = [] import invenio.bibformat_elements.bfe_publisher as bfe_publisher publisher = bfe_publisher.format_element(bfo=bfo) if publisher != "": publishers.append(publisher) publication_name = bfo.field("269__b") if publication_name != "": publishers.append(publication_name) imprint_publisher_name = bfo.field("933__b") if imprint_publisher_name != "": publishers.append(imprint_publisher_name) imprint_e_journal__publisher_name = bfo.field("934__b") if imprint_e_journal__publisher_name != "": publishers.append(imprint_e_journal__publisher_name) out += texified("publisher", ". ".join(publishers)) # Collaboration collaborations = [] for collaboration in bfo.fields("710__g"): if collaboration not in collaborations: collaborations.append(collaboration) out += texified("collaboration", ", ".join(collaborations)) # School if collection == "phdthesis": university = bfo.field("502__b") out += texified("school", university) # Address if collection == "book" or \ collection == "inproceedings" or \ collection == "proceedings" or \ collection == "phdthesis" or \ collection == "techreport": addresses = [] publication_place = bfo.field("260__a") if publication_place != "": addresses.append(publication_place) publication_place_2 = bfo.field("269__a") if publication_place_2 != "": addresses.append(publication_place_2) imprint_publisher_place = bfo.field("933__a") if imprint_publisher_place != "": addresses.append(imprint_publisher_place) imprint_e_journal__publisher_place = bfo.field("934__a") if imprint_e_journal__publisher_place != "": addresses.append(imprint_e_journal__publisher_place) out += texified("address", ". ".join(addresses)) # Journal if collection == "article": journals = [] host_title = bfo.field("773__p") if host_title != "": journals.append(host_title) journal = bfo.field("909C4p") if journal != "": journals.append(journal) out += texified("journal", ". ".join(journals)) # Number if collection == "techreport" or \ collection == "article": numbers = [] host_number = bfo.field("773__n") if host_number != "": numbers.append(host_number) number = bfo.field("909C4n") if number != "": numbers.append(number) out += texified("number", ". ".join(numbers)) # Volume if collection == "article" or \ collection == "book": volumes = [] host_volume = bfo.field("773__v") if host_volume != "": volumes.append(host_volume) volume = bfo.field("909C4v") if volume != "": volumes.append(volume) out += texified("volume", ". ".join(volumes)) # Series if collection == "book": series = bfo.field("490__a") out += texified("series", series) # Pages if collection == "article" or \ collection == "inproceedings": pages = [] host_pages = bfo.field("773c") if host_pages != "": pages.append(host_pages) nb_pages = bfo.field("909C4c") if nb_pages != "": pages.append(nb_pages) phys_pagination = bfo.field("300__a") if phys_pagination != "": pages.append(phys_pagination) out += texified("pages", ". ".join(pages)) # DOI if collection == "article" or \ collection == "data": if bfo.field("0247_2") == 'DOI': dois = bfo.fields("0247_a") + bfo.fields("773__a") out += texified("doi", ", ".join(set(dois))) elif bfo.field("0247_2") == 'HDL': handles = bfo.fields("0247_a") + bfo.fields("773__a") out += texified("handle", ", ".join(set(handles))) # Year year = bfo.field("773__y") if year == "": year = get_year(bfo.field("269__c")) if year == "": year = get_year(bfo.field("260__c")) if year == "": year = get_year(bfo.field("502__c")) if year == "": year = get_year(bfo.field("909C0y")) out += texified("year", year) # Eprint (aka arxiv number) import invenio.bibformat_elements.bfe_INSPIRE_arxiv as bfe_arxiv eprints = bfe_arxiv.get_arxiv(bfo, category="no") cats = bfe_arxiv.get_cats(bfo) if eprints: eprint = eprints[0] if eprint.upper().startswith('ARXIV:'): eprint = eprint[6:] out += texified("eprint", eprint) out += texified("archivePrefix", "arXiv") if cats: out += texified("primaryClass", cats[0]) else: # No eprints, but we don't want refs to eprints[0] to error out below # This makes everything work nicely without a lot of extra gating eprints = [None] # Other report numbers out += texified( "reportNumber", bfe_repno.get_report_numbers_formatted(bfo, separator=', ', limit='1000', skip=eprints[0])) # Add %%CITATION line import invenio.bibformat_elements.bfe_INSPIRE_publi_info_latex as bfe_pil import invenio.bibformat_elements.bfe_INSPIRE_publi_coden as bfe_coden cite_as = bfe_pil.get_cite_line( arxiv=eprints[0], pubnote=bfe_coden.get_coden_formatted(bfo, ','), repno=bfe_repno.get_report_numbers_formatted(bfo, '', '1'), bfo=bfo) out += texified("SLACcitation", cite_as) out += "\n}" return out