load_extended_prefix_map

load_extended_prefix_map(records: str | Path | Iterable[Record | Dict[str, Any]], **kwargs: Any) Converter[source]

Get a converter from a list of dictionaries by creating records out of them.

Parameters:
  • records

    One of the following:

    • An iterable of curies.Record objects or dictionaries that will get converted into record objects that together constitute an extended prefix map

    • A string containing a remote location of a JSON file containg an extended prefix map

    • A string or pathlib.Path object corresponding to a local file path to a JSON file containing an extended prefix map

  • kwargs – Keyword arguments to pass to curies.Converter.__init__()

Returns:

A converter

An extended prefix map is a list of dictionaries containing four keys:

  1. A prefix string

  2. A uri_prefix string

  3. An optional list of strings prefix_synonyms

  4. An optional list of strings uri_prefix_synonyms

Across the whole list of dictionaries, there should be uniqueness within the union of all prefix and prefix_synonyms as well as uniqueness within the union of all uri_prefix and uri_prefix_synonyms.

>>> import curies
>>> epm = [
...     {
...         "prefix": "CHEBI",
...         "prefix_synonyms": ["chebi", "ChEBI"],
...         "uri_prefix": "http://purl.obolibrary.org/obo/CHEBI_",
...         "uri_prefix_synonyms": ["https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:"],
...     },
...     {
...         "prefix": "GO",
...         "uri_prefix": "http://purl.obolibrary.org/obo/GO_",
...     },
... ]
>>> converter = curies.load_extended_prefix_map(epm)

Expand using the preferred/canonical prefix:

>>> converter.expand("CHEBI:138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'

Expand using a prefix synonym:

>>> converter.expand("chebi:138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'

Compress using the preferred/canonical URI prefix:

>>> converter.compress("http://purl.obolibrary.org/obo/CHEBI_138488")
'CHEBI:138488'

Compressing using a URI prefix synonym:

>>> converter.compress("https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:138488")
'CHEBI:138488'

Example from a remote source:

>>> url = "https://github.com/biopragmatics/bioregistry/raw/main/exports/contexts/bioregistry.epm.json"
>>> converter = curies.load_extended_prefix_map(url)