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 = 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
-
contract(uri: str, fallback: bool = True) → str | None[source]
Contract a given URI to a CURIE, based on mappings from prefix_map.
- Parameters:
-
- 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:
-
- Returns:
A URI corresponding to the CURIE
- Return type:
str
-
static get_prefix(curie: str) → str | None[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) → str | None[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
-
update_prefix_map(m: Dict[str, str]) → None[source]
Update prefix maps with new mappings.
- Parameters:
m (Dict) – New prefix to IRI mappings
-
update_reverse_prefix_map(m: Dict[str, str]) → None[source]
Update reverse prefix maps with new mappings.
- Parameters:
m (Dict) – New IRI to prefix mappings