Prefix Manager¶
In KGX, the PrefixManager
acts as a central resource for,
CURIE to IRI expansion
IRI to CURIE contraction
Under the hood, PrefixManager
makes use of prefixcommons-py.
Each time the PrefixManager
class is initialized, it makes use of the Biolink Model
JSON-LD context for a default set of prefix to IRI mappings.
These defaults can be overridden by using update_prefix_map
and providing your custom
mappings.
kgx.prefix_manager¶
-
class
kgx.prefix_manager.
PrefixManager
(url: str = None)[source]¶ Bases:
object
Manages prefix mappings.
These include mappings for CURIEs such as GO:0008150, as well as shortforms such as biolink types such as Disease
-
__init__
(url: str = None)[source]¶ Initialize an instance of PrefixManager.
- Parameters
url (str) – The URL from which to read a JSON-LD context for prefix mappings
-
contract
(uri: str, fallback: bool = True) → Optional[str][source]¶ Contract a given URI to a CURIE, based on mappings from prefix_map.
- Parameters
uri (str) – A URI
fallback (bool) – Determines whether to fallback to default prefix mappings, as determined by prefixcommons.curie_util, when URI prefix is not found in reverse_prefix_map.
- Returns
A CURIE corresponding to the URI
- Return type
Optional[str]
-
expand
(curie: str, fallback: bool = True) → str[source]¶ Expand a given CURIE to an URI, based on mappings from prefix_map.
- Parameters
curie (str) – A CURIE
fallback (bool) – Determines whether to fallback to default prefix mappings, as determined by prefixcommons.curie_util, when CURIE prefix is not found in prefix_map.
- Returns
A URI corresponding to the CURIE
- Return type
str
-
static
get_prefix
(curie: str) → Optional[str][source]¶ Get the prefix from a given CURIE.
- Parameters
curie (str) – The CURIE
- Returns
The CURIE prefix
- Return type
str
-
static
get_reference
(curie: str) → Optional[str][source]¶ Get the reference of a given CURIE.
- Parameters
curie (str) – The CURIE
- Returns
The reference of a CURIE
- Return type
Optional[str]
-
static
is_curie
(s: str) → bool[source]¶ Check if a given string is a CURIE.
- Parameters
s (str) – A string
- Returns
Whether or not the given string is a CURIE
- Return type
bool
-
static
is_iri
(s: str) → bool[source]¶ Check if a given string as an IRI.
- Parameters
s (str) – A string
- Returns
Whether or not the given string is an IRI.
- Return type
bool
-
set_prefix_map
(m: Dict) → None[source]¶ Populate prefix_map with contents from a JSON-LD context from self.url
- Parameters
m (dict) – Dictionary of prefix to URI mappings
-