Skip to content

Commit

Permalink
Merge pull request #287 from linkml/fix-urn-usage
Browse files Browse the repository at this point in the history
fix: add support for urns to curie namespaces
  • Loading branch information
sierra-moxon authored Dec 13, 2023
2 parents 476d237 + dee0311 commit bfec27d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion linkml_runtime/utils/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from prefixmaps.io.parser import load_context

from linkml_runtime.utils.yamlutils import TypedNode
from linkml_runtime.utils.uri_validator import validate_uri

META_NS = "meta"
META_URI = "https://w3id.org/linkml/meta"
Expand Down Expand Up @@ -142,7 +143,7 @@ def curie_for(self, uri: Any, default_ok: bool = True, pythonform: bool = False)
@param default_ok: True means the default prefix is ok. Otherwise, we have to have a real prefix
@param pythonform: True means take the python/rdflib uppercase format
"""
if ':' in uri and ':/' not in uri:
if not validate_uri(uri):
raise ValueError(f"{TypedNode.yaml_loc(uri)}Not a valid URI: {uri}")

if pythonform:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_namespaces(self):
ns['l1'] = "http://example.org/subset/"
ns['l2'] = "http://example.org/subset/test/"
ns['l3'] = "http://example.org/subset/t"
ns['u1'] = "urn:example:"
# This is now a warning instead of a value error
# with self.assertRaises(ValueError):
# ns['OIO'] = URIRef("http://www.geneontology.org/formats/another")
Expand Down Expand Up @@ -59,6 +60,9 @@ def test_namespaces(self):
self.assertEqual('l1:foo', ns.curie_for("http://example.org/subset/foo"))
self.assertEqual('l2:foo', ns.curie_for("http://example.org/subset/test/foo"))
self.assertEqual('l3:able/foo', ns.curie_for("http://example.org/subset/table/foo"))
self.assertEqual('u1:foo', ns.curie_for("urn:example:foo"))
with self.assertRaises(ValueError):
ns.curie_for("1abc\junk")
#no comment in skos?
#self.assertEqual(SKOS.comment, ns.uri_for("skos:comment"))
self.assertEqual(URIRef('http://example.org/dc/table'), ns.uri_for("dc:table"))
Expand Down

0 comments on commit bfec27d

Please sign in to comment.