Exemple #1
0
def get_latest_deposits():
	NUMBER_OF_RECORDS = 4;

	ids = perform_request_search(of="id", rg=NUMBER_OF_RECORDS, sf="005", so="a")
	limit_ids = ids[:NUMBER_OF_RECORDS]
	bfo_list = [bibformat_engine.BibFormatObject(id) for id in limit_ids]
	recs = [{
		"id": bfo.recID,
		"date": bfe_creation_date.format_element(bfo),
		"author": bfe_authors.format_element(bfo, "1"),
		"title": bfe_title.format_element(bfo),
		"description": bfe_abstract.format_element(bfo,
			prefix_en="", prefix_fr="", suffix_en="", suffix_fr="",
			limit="", max_chars="72", extension_en="...", extension_fr="..."),
		"category": bfo.field("980__a"),
	} for bfo in bfo_list]
	return recs
Exemple #2
0
def get_latest_deposits():
	NUMBER_OF_RECORDS = 4;

	ids = perform_request_search(of="id", rg=NUMBER_OF_RECORDS, sf="005", so="d")
	limit_ids = ids[:NUMBER_OF_RECORDS]
	bfo_list = [bibformat_engine.BibFormatObject(id) for id in limit_ids]
	recs = [{
		"id": bfo.recID,
		"date": bfe_creation_date.format_element(bfo),
		"author": bfe_authors.format_element(bfo, "1"),
		"title": bfe_title.format_element(bfo),
		"description": bfe_abstract.format_element(bfo,
			prefix_en="", prefix_fr="", suffix_en="", suffix_fr="",
			limit="", max_chars="72", extension_en="...", extension_fr="..."),
		"category": bfo.field("980__a"),
	} for bfo in bfo_list]
	return recs
Exemple #3
0
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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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
Exemple #4
0
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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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.modules.formatter.format_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)

    #Print doi
    fields = bfo.fields("0247_")
    for field in fields:
        if field.get('2', 'DOI') == 'DOI' and 'a' in field:
            out += format_bibtex_field("doi", "{%s}" % field['a'], name_width,
                                       value_width)
            out += format_bibtex_field("url",
                                       "{http://dx.doi.org/%s}" % field['a'],
                                       name_width, value_width)

    out += "\n}"

    return out