Skip to content

Commit

Permalink
Merge pull request #231 from linkml/prefixmaps
Browse files Browse the repository at this point in the history
add the ability to declare "prefixmaps" contexts (including bioregistry contexts) in default_curie_maps.  fixes #604
  • Loading branch information
cmungall authored Dec 23, 2022
2 parents c30a999 + 9232cf2 commit dc2a25c
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 76 deletions.
42 changes: 40 additions & 2 deletions linkml_runtime/utils/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,38 @@
from rdflib import Namespace, URIRef, Graph, BNode
from rdflib.namespace import is_ncname
from requests.structures import CaseInsensitiveDict
from prefixmaps.io.parser import load_context

from linkml_runtime.utils.yamlutils import TypedNode

META_NS = "meta"
META_URI = "https://w3id.org/linkml/meta"
BIOCONTEXT_CONTEXTS = [
"biocaddie-context",
"commons_context",
"globi_context",
"go_context",
"go_obo_context",
"idot_context",
"idot_nr_context",
"minerva_context",
"monarch_context",
"obo_context",
"ro_vocab_context",
"semweb_context",
"semweb_vocab_context"
]
PREFIXMAPS_CONTEXTS = [
"bioportal",
"bioregistry",
"bioregistry.upper",
"go",
"linked_data",
"merged",
"merged.oak",
"obo",
"prefixcc"
]


class Namespaces(CaseInsensitiveDict):
Expand Down Expand Up @@ -230,13 +257,24 @@ def sfx(uri: str) -> str:

def add_prefixmap(self, map_name: str, include_defaults: bool = True) -> None:
"""
Add a prefixcommons map. Only prefixes that have not been previously defined are added.
Add a prefixcommons map or the merged map from prefixmaps repo.
Only prefixes that have not been previously defined are added.
:param map_name: prefixcommons map name
:param include_defaults: if True, take defaults from the map.
:return:
"""
for k, v in curie_util.read_biocontext(map_name).items():

if map_name in BIOCONTEXT_CONTEXTS:
prefix_map = curie_util.read_biocontext(map_name)
elif map_name in PREFIXMAPS_CONTEXTS:
context = load_context(map_name)
prefix_map = context.as_dict()
else:
raise ValueError(f"Unknown prefix map: {map_name}")

for k, v in prefix_map.items():
if not k:
if include_defaults and not self._default:
self._default = v
Expand Down
Loading

0 comments on commit dc2a25c

Please sign in to comment.