Utils Docs

Public api for methods and functions to handle/verify the jsonschemas.

class inspire_schemas.utils.LocalRefResolver(base_uri, referrer, store=(), cache_remote=True, handlers=(), urljoin_cache=None, remote_cache=None)[source]

Bases: jsonschema.validators.RefResolver

Simple resolver to handle non-uri relative paths.

resolve_remote(uri)[source]

Resolve a uri or relative path to a schema.

inspire_schemas.utils.build_pubnote(title, volume, page_start, page_end, artid)[source]

Build pubnote string from parts (reverse of split_pubnote).

inspire_schemas.utils.classify_field(value)[source]

Translate an arXiv category to the corresponding INSPIRE category.

Parameters:value – arXiv category to translate
Returns:
None if value is not a string containing a valid arXiv
category, otherwise the corresponding INSPIRE category.
Return type:str
inspire_schemas.utils.get_license_from_url(url)[source]

Get the license abbreviation from an URL.

Parameters:url (str) – canonical url of the license.
Returns:the corresponding license abbreviation.
Return type:str
Raises:ValueError – when the url is not recognized
inspire_schemas.utils.get_schema_path(schema)[source]

Retrieve the installed path for the given schema.

Parameters:schema (str) – String with the (relative or absolute) url of the schema to validate, for example, ‘records/authors.json’ or ‘jobs.json’, or by just the name like ‘jobs’.
Returns:The path or the given schema name.
Return type:str
inspire_schemas.utils.load_schema(schema_name)[source]

Load the given schema from wherever it’s installed.

Parameters:schema_name – Name of the schema to load, for example ‘authors’.
inspire_schemas.utils.normalize_arxiv_category(category)[source]

Normalize arXiv category to be schema compliant.

This properly capitalizes the category and replaces the dash by a dot if needed. If the category is obsolete, it also gets converted it to its current equivalent.

Example

>>> from inspire_schemas.utils import normalize_arxiv_category
>>> normalize_arxiv_category('funct-an')
u'math.FA'
inspire_schemas.utils.normalize_author_name(author)[source]

Normalize author name.

Parameters:author (string) – author name
Return name:the name of the author normilized
inspire_schemas.utils.normalize_collaboration(collaboration)[source]

Normalize collaboration string.

Parameters:collaboration – a string containing collaboration(s) or None
Returns:List of extracted and normalized collaborations
Return type:list

Examples

>>> from inspire_schemas.utils import normalize_collaboration
>>> normalize_collaboration('for the CMS and ATLAS Collaborations')
['CMS', 'ATLAS']
inspire_schemas.utils.split_page_artid(page_artid)[source]

Split page_artid into page_start/end and artid.

inspire_schemas.utils.split_pubnote(pubnote_str)[source]

Split pubnote into journal information.

inspire_schemas.utils.valid_arxiv_categories()[source]

List of all arXiv categories that ever existed.

Example

>>> from inspire_schemas.utils import valid_arxiv_categories
>>> 'funct-an' in valid_arxiv_categories()
True
inspire_schemas.utils.validate(data, schema=None)[source]

Validate the given dictionary against the given schema.

Parameters:
  • data (dict) – record to validate.
  • schema (Union[dict, str]) – schema to validate against. If it is a string, it is intepreted as the name of the schema to load (e.g. authors or jobs). If it is None, the schema is taken from data['$schema']. If it is a dictionary, it is used directly.
Raises:
  • SchemaNotFound – if the given schema was not found.
  • SchemaKeyNotFound – if schema is None and no $schema key was found in data.
  • jsonschema.SchemaError – if the schema is invalid.
  • jsonschema.ValidationError – if the data is invalid.