Skip to content

Commit dee0311

Browse files
committed
fix: add support for urns to curie namespaces
Support for URNs added on version v1.6.1 (later fixed on v1.6.2) is missing support for proper CURIE conversion for URNs. This patch fixes it. It also provides a test-case. Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
1 parent 01838a0 commit dee0311

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

linkml_runtime/utils/namespaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from prefixmaps.io.parser import load_context
99

1010
from linkml_runtime.utils.yamlutils import TypedNode
11+
from linkml_runtime.utils.uri_validator import validate_uri
1112

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

148149
if pythonform:

tests/test_utils/test_namespaces.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_namespaces(self):
1818
ns['l1'] = "http://example.org/subset/"
1919
ns['l2'] = "http://example.org/subset/test/"
2020
ns['l3'] = "http://example.org/subset/t"
21+
ns['u1'] = "urn:example:"
2122
# This is now a warning instead of a value error
2223
# with self.assertRaises(ValueError):
2324
# ns['OIO'] = URIRef("http://www.geneontology.org/formats/another")
@@ -59,6 +60,9 @@ def test_namespaces(self):
5960
self.assertEqual('l1:foo', ns.curie_for("http://example.org/subset/foo"))
6061
self.assertEqual('l2:foo', ns.curie_for("http://example.org/subset/test/foo"))
6162
self.assertEqual('l3:able/foo', ns.curie_for("http://example.org/subset/table/foo"))
63+
self.assertEqual('u1:foo', ns.curie_for("urn:example:foo"))
64+
with self.assertRaises(ValueError):
65+
ns.curie_for("1abc\junk")
6266
#no comment in skos?
6367
#self.assertEqual(SKOS.comment, ns.uri_for("skos:comment"))
6468
self.assertEqual(URIRef('http://example.org/dc/table'), ns.uri_for("dc:table"))

0 commit comments

Comments
 (0)