Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for urns to curie namespaces #287

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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