inspirehep.modules.records.serializers package

Subpackages

Submodules

inspirehep.modules.records.serializers.config module

inspirehep.modules.records.serializers.config.COMMON_FIELDS_FOR_ENTRIES = ['key', 'SLACcitation', 'archivePrefix', 'doi', 'eprint', 'month', 'note', 'primaryClass', 'title', 'url', 'year']

BibTeX fields shared among all bibtex entries.

inspirehep.modules.records.serializers.config.FIELDS_FOR_ENTRY_TYPE = {'inbook': ['chapter', 'publisher', 'author', 'series', 'number', 'volume', 'edition', 'editor', 'reportNumber', 'address', 'type', 'pages'], 'proceedings': ['publisher', 'series', 'number', 'volume', 'reportNumber', 'editor', 'address', 'organization', 'pages'], 'book': ['publisher', 'isbn', 'author', 'series', 'number', 'volume', 'edition', 'editor', 'reportNumber', 'address'], 'techreport': ['author', 'collaboration', 'number', 'address', 'type', 'institution'], 'phdthesis': ['reportNumber', 'school', 'address', 'type', 'author'], 'inproceedings': ['publisher', 'author', 'series', 'booktitle', 'number', 'volume', 'reportNumber', 'editor', 'address', 'organization', 'pages'], 'mastersthesis': ['reportNumber', 'school', 'address', 'type', 'author'], 'article': ['author', 'journal', 'collaboration', 'number', 'volume', 'reportNumber', 'pages'], 'misc': ['howpublished', 'reportNumber', 'author']}

Specific fields for a given bibtex entry.

Note

Since we’re trying to match as many as possible it doesn’t matter whether they’re mandatory or optional

inspirehep.modules.records.serializers.config.MAX_AUTHORS_BEFORE_ET_AL = 10

Maximum number of authors to be displayed without truncation.

Note

For more than MAX_AUTHORS_BEFORE_ET_AL only the first author should be displayed and a suitable truncation method is applied.

inspirehep.modules.records.serializers.fields_export module

inspirehep.modules.records.serializers.fields_export.bibtex_document_type(doc_type, obj)[source]

Return the BibTeX entry type.

Maps the INSPIRE document_type to a BibTeX entry type. Also checks thesis_info.degree_type in case it’s a thesis, as it stores the information on which kind of thesis we’re dealing with.

Parameters:
  • doc_type (text_type) – INSPIRE document type.
  • obj (dict) – literature record.
Returns:

bibtex document type for the given INSPIRE entry.

Return type:

text_type

inspirehep.modules.records.serializers.fields_export.bibtex_type_and_fields(data)[source]

Return a BibTeX doc type and fields needed to be included in a BibTeX record.

Parameters:data (dict) – inspire record
Returns:bibtex document type and fields
Return type:tuple
inspirehep.modules.records.serializers.fields_export.extractor(field)
inspirehep.modules.records.serializers.fields_export.get_address(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_arxiv_prefix(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_author(data, doc_type)[source]

Get corporate author of a record.

Note

Only used to generate author field if corporate_author is the author.

inspirehep.modules.records.serializers.fields_export.get_authors_with_role(authors, role)[source]

Extract names of people from an authors field given their roles.

Parameters:
  • authors – authors field of the record.
  • role – string specifying the role ‘author’, ‘editor’, etc.
Returns:

of names of people

Return type:

list of text_type

inspirehep.modules.records.serializers.fields_export.get_best_publication_info(data)[source]

Return the most comprehensive publication_info entry.

Parameters:data (dict) – inspire record
Returns:a publication_info entry or default if not found any
Return type:dict
inspirehep.modules.records.serializers.fields_export.get_booktitle(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_collaboration(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_country_name_by_code(code, default=None)[source]

Return a country name string from a country code.

Parameters:
  • code (str) – country code in INSPIRE 2 letter format based on ISO 3166-1 alpha-2
  • default – value to be returned if no country of a given code exists
Returns:

name of a country, or default if no such country.

Return type:

text_type

inspirehep.modules.records.serializers.fields_export.get_date(data, doc_type)[source]

Return a publication/thesis/imprint date.

Parameters:
  • data (dict) – INSPIRE literature record to be serialized
  • doc_type (text_type) – BibTeX document type, as reported by bibtex_document_type
Returns:

publication date for a record.

Return type:

PartialDate

inspirehep.modules.records.serializers.fields_export.get_doi(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_edition(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_eprint(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_isbn(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_journal(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_month(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_note(data, doc_type)[source]

Write and addendum/errata information to the BibTeX note field.

Traverse publication_info looking for erratum and addendum in publication_info.material field and build a string of references to those publication entries.

Returns:formatted list of the errata and addenda available for a given record
Return type:string
inspirehep.modules.records.serializers.fields_export.get_number(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_pages(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_primary_class(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_publisher(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_report_number(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_school(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_series(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_title(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_type(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_url(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_volume(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.get_year(data, doc_type)[source]
inspirehep.modules.records.serializers.fields_export.make_extractor()[source]

Create a function store decorator.

Creates a decorator function that is used to collect extractor functions. They are put in a dictionary with the field they extract as keys. An extractor function is a function which returns a BibTeX field value given an inspire record and a document type.

Returns:a decorator with a store for pre-processing/extracting functions.
Return type:function

inspirehep.modules.records.serializers.json_literature module

Marshmallow based JSON serializer for records.

class inspirehep.modules.records.serializers.json_literature.FacetsJSONUISerializer(schema_class=<class 'invenio_records_rest.schemas.json.RecordSchemaJSONV1'>, **kwargs)[source]

Bases: invenio_records_rest.serializers.json.JSONSerializer

JSON brief format serializer.

serialize_facets(query_results, **kwargs)[source]
class inspirehep.modules.records.serializers.json_literature.LiteratureCitationsJSONSerializer(schema_class=<class 'invenio_records_rest.schemas.json.RecordSchemaJSONV1'>, **kwargs)[source]

Bases: invenio_records_rest.serializers.json.JSONSerializer

preprocess_record(pid, record, links_factory=None, **kwargs)[source]

Prepare a record and persistent identifier for serialization.

serialize(pid, data, links_factory=None, **kwargs)[source]
class inspirehep.modules.records.serializers.json_literature.LiteratureJSONUISerializer(schema_class=<class 'invenio_records_rest.schemas.json.RecordSchemaJSONV1'>, **kwargs)[source]

Bases: invenio_records_rest.serializers.json.JSONSerializer

JSON brief format serializer.

preprocess_record(pid, record, links_factory=None, **kwargs)[source]
preprocess_search_hit(pid, record_hit, links_factory=None, **kwargs)[source]
inspirehep.modules.records.serializers.json_literature.get_citations_count(original_record)[source]

Try to get citations

inspirehep.modules.records.serializers.latex module

Latex serializer for records.

class inspirehep.modules.records.serializers.latex.LatexSerializer(format, **kwargs)[source]

Bases: invenio_records_rest.serializers.marshmallow.MarshmallowMixin, invenio_records_rest.serializers.base.PreprocessorMixin

Latex serializer for records.

latex_template()[source]
preprocess_record(pid, record, links_factory=None, **kwargs)[source]

Prepare a record and persistent identifier for serialization.

serialize(pid, record, links_factory=None, **kwargs)[source]

Serialize a single record and persistent identifier.

Parameters:
  • pid – Persistent identifier instance.
  • record – Record instance.
  • links_factory – Factory function for record links.

Serialize search result(s).

Parameters:
  • pid_fetcher – Persistent identifier fetcher.
  • search_result – Elasticsearch search result.
  • links – Dictionary of links to add to response.
Returns:

serialized search result(s)

Return type:

str

inspirehep.modules.records.serializers.marcxml module

MARCXML serializer.

class inspirehep.modules.records.serializers.marcxml.MARCXMLSerializer[source]

Bases: object

MARCXML serializer.

serialize(pid, record, links_factory=None)[source]

Serialize a single record as MARCXML.

Serialize a search result as MARCXML.

inspirehep.modules.records.serializers.pybtex_serializer_base module

BibTex serializer for records.

class inspirehep.modules.records.serializers.pybtex_serializer_base.PybtexSerializerBase(schema, writer)[source]

Bases: object

Pybtex serializer for records.

create_bibliography(record_list)[source]

Create a pybtex bibliography from individual entries.

Parameters:record_list – A list of records of the bibliography.
Returns:a serialized bibliography.
Return type:str
create_bibliography_entry(record)[source]

Get a texkey and bibliography entry for an inspire record.

Use the schema in self.schema to create a Pybtex bibliography entry and retrieve respective texkey from a record.

Parameters:record – A literature record.
Returns:bibliography entry as a (texkey, pybtex_entry) tuple.
Return type:tuple
serialize(pid, record, links_factory=None)[source]

Serialize a single Bibtex record.

Parameters:
  • pid – Persistent identifier instance.
  • record – Record instance.
  • links_factory – Factory function for the link generation, which are added to the response.
Returns:

single serialized Bibtex record

Return type:

str

Serialize search result(s).

Parameters:
  • pid_fetcher – Persistent identifier fetcher.
  • search_result – Elasticsearch search result.
  • links – Dictionary of links to add to response.
Returns:

serialized search result(s)

Return type:

str

inspirehep.modules.records.serializers.response module

Serialization response factories.

Responsible for creating a HTTP response given the output of a serializer.

inspirehep.modules.records.serializers.response.facets_responsify(serializer, mimetype)[source]

Create a Facets serializer

As aggregations were removed from search query, now second call to the server is required to acquire data for Facets

Parameters:
  • serializer – Serializer instance.
  • mimetype – MIME type of response.
inspirehep.modules.records.serializers.response.record_responsify_nocache(serializer, mimetype)[source]

Create a Records-REST response serializer with no cache.

This is useful for formats such as bibtex where the code that generates the format might change so we don’t want to use caching

Parameters:
  • serializer – Serializer instance.
  • mimetype – MIME type of response.

Module contents

Record serialization.