diff --git a/linkml_runtime/utils/metamodelcore.py b/linkml_runtime/utils/metamodelcore.py index 957a1269..e20a13f8 100644 --- a/linkml_runtime/utils/metamodelcore.py +++ b/linkml_runtime/utils/metamodelcore.py @@ -167,19 +167,17 @@ def __init__(self, v: str) -> None: @classmethod def ns_ln(cls, v: str) -> Optional[Tuple[str, str]]: - # See if this is indeed a valid CURIE, ie, it can be split by a colon + if not validate_curie(v): + return None + # assume the presence of a colon and try to split the CURIE curie_split = v.split(':', 1) if len(curie_split) == 1: - # there is no ':' character in the string, ie, it is not a valid CURIE - return None + # there is no ':' character in the string, it's only a reference + return '', v else: prefix = curie_split[0].lower() - if not NCName.is_valid(prefix): - return None reference = curie_split[1] - if not cls.term_name.match(reference): - return None - return prefix, reference + return prefix, reference @classmethod def is_valid(cls, v: str) -> bool: diff --git a/tests/test_utils/test_metamodelcore.py b/tests/test_utils/test_metamodelcore.py index ff2b5700..676cf91a 100644 --- a/tests/test_utils/test_metamodelcore.py +++ b/tests/test_utils/test_metamodelcore.py @@ -59,19 +59,17 @@ def test_uriorcuries(self): def test_curie(self): """ Test the CURIE type """ self.assertEqual("rdf:type", Curie("rdf:type")) - with self.assertRaises(ValueError): - Curie("type") - self.assertFalse(Curie.is_valid("type")) + self.assertTrue(Curie.is_valid("type")) self.assertEqual(":type", Curie(":type")) self.assertTrue(Curie.is_valid(':type')) + self.assertTrue(Curie.is_valid('_abc:123')) self.assertTrue(Curie.is_valid('WIKIDATA_PROPERTY:P854')) self.assertTrue(Curie.is_valid('WIKIDATA.PROPERTY:P854')) with self.assertRaises(ValueError): Curie("1df:type") self.assertFalse(Curie.is_valid('1df:type')) - with self.assertRaises(ValueError): - Curie("rdf:17") - self.assertFalse(Curie.is_valid('rdf:17')) + self.assertTrue(Curie.is_valid('rdf:17')) + self.assertTrue(Curie.is_valid('17')) nsm = Namespaces(Graph()) self.assertEqual(RDF.type, Curie("rdf:type").as_uri(nsm)) self.assertIsNone(Curie("ex:foo").as_uri(nsm))