parse_iri
- parse_iri(iri, *, prefix_map=None)[source]
Parse a compact identifier from an IRI.
- Parameters
iri (
str
) – A valid IRIprefix_map (
Union
[Mapping
[str
,str
],List
[Tuple
[str
,str
]],None
]) – If None, will use the default prefix map. If a mapping, will convert into a sorted list usingensure_prefix_list()
. If you plan to use this function in a loop, pre-compute this and pass it instead. If a list of pairs is passed, will use it directly.
- Return type
- Returns
A pair of prefix/identifier, if can be parsed
IRI from an OBO PURL:
>>> parse_iri("http://purl.obolibrary.org/obo/DRON_00023232") ('dron', '00023232')
IRI from the OLS:
>>> parse_iri("https://www.ebi.ac.uk/ols/ontologies/ecao/terms?iri=http://purl.obolibrary.org/obo/ECAO_0107180") ('ecao', '0107180')
IRI from native provider
>>> parse_iri("https://www.alzforum.org/mutations/1234") ('alzforum.mutation', '1234')
Dog food:
>>> parse_iri("https://bioregistry.io/DRON:00023232") ('dron', '00023232')
IRIs from Identifiers.org (https and http, colon and slash):
>>> parse_iri("https://identifiers.org/aop.relationships:5") ('aop.relationships', '5') >>> parse_iri("http://identifiers.org/aop.relationships:5") ('aop.relationships', '5') >>> parse_iri("https://identifiers.org/aop.relationships/5") ('aop.relationships', '5') >>> parse_iri("http://identifiers.org/aop.relationships/5") ('aop.relationships', '5')
IRI from N2T >>> parse_iri(”https://n2t.net/aop.relationships:5”) (‘aop.relationships’, ‘5’)
Handle either HTTP or HTTPS: >>> parse_iri(”http://braininfo.rprc.washington.edu/centraldirectory.aspx?ID=268”) (‘neuronames’, ‘268’) >>> parse_iri(”https://braininfo.rprc.washington.edu/centraldirectory.aspx?ID=268”) (‘neuronames’, ‘268’)
Provide your own prefix map for one-off parsing (i.e., not in bulk): >>> prefix_map = {“chebi”: “https://example.org/chebi:”} >>> parse_iri(”https://example.org/chebi:1234”, prefix_map=prefix_map) (‘chebi’, ‘1234’)
If you provide your own prefix map but want to do parsing in bulk, you should pre-process the prefix map with:
>>> from bioregistry import ensure_prefix_list >>> prefix_map = {"chebi": "https://example.org/chebi:"} >>> prefix_list = ensure_prefix_list(prefix_map) >>> parse_iri("https://example.org/chebi:1234", prefix_map=prefix_list) ('chebi', '1234')