From 972bf74afd534aa2478e95efc8f9c58ae60e9614 Mon Sep 17 00:00:00 2001 From: Sheldon Douglas Date: Wed, 21 Aug 2024 15:36:57 -0400 Subject: [PATCH] Add UUID generator incorporating dictionary entry keys Reviewed-by: Alex Nelson Signed-off-by: Sheldon Douglas --- case_utils/inherent_uuid.py | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/case_utils/inherent_uuid.py b/case_utils/inherent_uuid.py index ad3f7c3..526d4bb 100644 --- a/case_utils/inherent_uuid.py +++ b/case_utils/inherent_uuid.py @@ -96,6 +96,15 @@ ) +def dictionary_entry_inherence_uuid( + uco_object_uuid_namespace: uuid.UUID, key_name: str, *args: Any, **kwargs: Any +) -> uuid.UUID: + """ + This function returns a UUIDv5 for dictionary entries, incorporating the key string's value. + """ + return uuid.uuid5(uco_object_uuid_namespace, key_name) + + def inherence_uuid(n_thing: URIRef, *args: Any, **kwargs: Any) -> uuid.UUID: """ This function returns a UUIDv5 for any OWL Thing, that can be used as a UUID Namespace in further `uuid.uuidv5` calls. @@ -152,6 +161,47 @@ def facet_inherence_uuid( return uuid.uuid5(uco_object_inherence_uuid, str(n_facet_class)) +def get_dictionary_entry_uriref( + n_dictionary: URIRef, + n_dictionary_entry_class: URIRef, + key_name: str, + *args: Any, + namespace: Namespace, + **kwargs: Any +) -> URIRef: + """ + :param namespace: An RDFLib Namespace object to use for prefixing the Dictionary IRI with a knowledge base prefix IRI. + :type namespace rdflib.Namespace: + + :param n_dictionary_entry_class: Assumed to be a "Proper Dictionary", as defined in UCO Issue 602. + + References + ========== + * https://github.com/ucoProject/UCO/issues/602 + + Examples + ======== + A dictionary has to have an entry with key "foo". What is the IRI of the dictionary entry? + + >>> from case_utils.namespace import NS_UCO_TYPES + >>> ns_kb = Namespace("http://example.org/kb/") + >>> n_dictionary = ns_kb["Dictionary-eb7e68d8-94db-4071-86fa-a51a33dc4a97"] + >>> n_dictionary_entry = get_dictionary_entry_uriref(n_dictionary, NS_UCO_TYPES.DictionaryEntry, "foo", namespace=ns_kb) + >>> n_dictionary_entry + rdflib.term.URIRef('http://example.org/kb/DictionaryEntry-6ce6b412-6a3a-5ebf-993a-9df2c80d2107') + """ + uco_object_uuid_namespace: uuid.UUID = inherence_uuid(n_dictionary) + dictionary_entry_uuid = dictionary_entry_inherence_uuid( + uco_object_uuid_namespace, key_name + ) + + dictionary_entry_class_local_name = str(n_dictionary_entry_class).rsplit("/")[-1] + + return namespace[ + dictionary_entry_class_local_name + "-" + str(dictionary_entry_uuid) + ] + + def get_facet_uriref( n_uco_object: URIRef, n_facet_class: URIRef,