From eeb3dc26116be7d0b45a59804d88d3f19c8d7180 Mon Sep 17 00:00:00 2001 From: Silvano Cirujano Cuesta Date: Wed, 8 Nov 2023 01:57:45 +0100 Subject: [PATCH 1/4] test: fix tests according curie specification According the CURIE syntax specification [1] "The prefix is separated from the reference by a colon (:). It is possible to omit both the prefix and the colon [...]." But a test case existed expecting a CURIE omitting both prefix and colon to be invalid. This patch fixes this wrong expectation. [1]: https://www.w3.org/TR/curie/#s_syntax Signed-off-by: Silvano Cirujano Cuesta --- tests/test_utils/test_metamodelcore.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_utils/test_metamodelcore.py b/tests/test_utils/test_metamodelcore.py index ff2b5700..07744906 100644 --- a/tests/test_utils/test_metamodelcore.py +++ b/tests/test_utils/test_metamodelcore.py @@ -59,9 +59,7 @@ 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('WIKIDATA_PROPERTY:P854')) From 255e24d548cc9f02ea7ffc40bd1ab7c583d3826f Mon Sep 17 00:00:00 2001 From: Silvano Cirujano Cuesta Date: Wed, 8 Nov 2023 02:04:19 +0100 Subject: [PATCH 2/4] test: fix wrong expectation on curies CURIE relative_ref part can perfectly be a number. Fixing wrong expectation rejecting number only relative_refs. Signed-off-by: Silvano Cirujano Cuesta --- tests/test_utils/test_metamodelcore.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_utils/test_metamodelcore.py b/tests/test_utils/test_metamodelcore.py index 07744906..7a286ba5 100644 --- a/tests/test_utils/test_metamodelcore.py +++ b/tests/test_utils/test_metamodelcore.py @@ -67,9 +67,8 @@ def test_curie(self): 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)) From fc22ceeee7f919ffde8678b16cec2b3044863ecc Mon Sep 17 00:00:00 2001 From: Silvano Cirujano Cuesta Date: Wed, 8 Nov 2023 02:05:10 +0100 Subject: [PATCH 3/4] test: fixing wrong curie prefix expectation CURIE prefixes can start with an underscore ('_'). This patch adds a test case to validate it. Signed-off-by: Silvano Cirujano Cuesta --- tests/test_utils/test_metamodelcore.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_utils/test_metamodelcore.py b/tests/test_utils/test_metamodelcore.py index 7a286ba5..676cf91a 100644 --- a/tests/test_utils/test_metamodelcore.py +++ b/tests/test_utils/test_metamodelcore.py @@ -62,6 +62,7 @@ def test_curie(self): 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): From cf960f02195c12bf58e26cd97611311f00864b71 Mon Sep 17 00:00:00 2001 From: Silvano Cirujano Cuesta Date: Wed, 8 Nov 2023 02:08:51 +0100 Subject: [PATCH 4/4] fix: curie validation in metamodelcore erroneous CURIE validation in metamodelcore was erroneous and rejecting valid CURIEs like those missing a prefix and a colon. This patch fixes it. Signed-off-by: Silvano Cirujano Cuesta --- linkml_runtime/utils/metamodelcore.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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: