Skip to content

Commit

Permalink
Merge pull request #164 from sldouglas-nist/add_dictionary_entry_inhe…
Browse files Browse the repository at this point in the history
…rent_iri_generator

Add UUID generator incorporating dictionary entry keys
  • Loading branch information
kchason authored Aug 21, 2024
2 parents aad9813 + 972bf74 commit bf4da9a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions case_utils/inherent_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bf4da9a

Please sign in to comment.