Skip to content

Commit bf4da9a

Browse files
authored
Merge pull request #164 from sldouglas-nist/add_dictionary_entry_inherent_iri_generator
Add UUID generator incorporating dictionary entry keys
2 parents aad9813 + 972bf74 commit bf4da9a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

case_utils/inherent_uuid.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
)
9797

9898

99+
def dictionary_entry_inherence_uuid(
100+
uco_object_uuid_namespace: uuid.UUID, key_name: str, *args: Any, **kwargs: Any
101+
) -> uuid.UUID:
102+
"""
103+
This function returns a UUIDv5 for dictionary entries, incorporating the key string's value.
104+
"""
105+
return uuid.uuid5(uco_object_uuid_namespace, key_name)
106+
107+
99108
def inherence_uuid(n_thing: URIRef, *args: Any, **kwargs: Any) -> uuid.UUID:
100109
"""
101110
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(
152161
return uuid.uuid5(uco_object_inherence_uuid, str(n_facet_class))
153162

154163

164+
def get_dictionary_entry_uriref(
165+
n_dictionary: URIRef,
166+
n_dictionary_entry_class: URIRef,
167+
key_name: str,
168+
*args: Any,
169+
namespace: Namespace,
170+
**kwargs: Any
171+
) -> URIRef:
172+
"""
173+
:param namespace: An RDFLib Namespace object to use for prefixing the Dictionary IRI with a knowledge base prefix IRI.
174+
:type namespace rdflib.Namespace:
175+
176+
:param n_dictionary_entry_class: Assumed to be a "Proper Dictionary", as defined in UCO Issue 602.
177+
178+
References
179+
==========
180+
* https://github.com/ucoProject/UCO/issues/602
181+
182+
Examples
183+
========
184+
A dictionary has to have an entry with key "foo". What is the IRI of the dictionary entry?
185+
186+
>>> from case_utils.namespace import NS_UCO_TYPES
187+
>>> ns_kb = Namespace("http://example.org/kb/")
188+
>>> n_dictionary = ns_kb["Dictionary-eb7e68d8-94db-4071-86fa-a51a33dc4a97"]
189+
>>> n_dictionary_entry = get_dictionary_entry_uriref(n_dictionary, NS_UCO_TYPES.DictionaryEntry, "foo", namespace=ns_kb)
190+
>>> n_dictionary_entry
191+
rdflib.term.URIRef('http://example.org/kb/DictionaryEntry-6ce6b412-6a3a-5ebf-993a-9df2c80d2107')
192+
"""
193+
uco_object_uuid_namespace: uuid.UUID = inherence_uuid(n_dictionary)
194+
dictionary_entry_uuid = dictionary_entry_inherence_uuid(
195+
uco_object_uuid_namespace, key_name
196+
)
197+
198+
dictionary_entry_class_local_name = str(n_dictionary_entry_class).rsplit("/")[-1]
199+
200+
return namespace[
201+
dictionary_entry_class_local_name + "-" + str(dictionary_entry_uuid)
202+
]
203+
204+
155205
def get_facet_uriref(
156206
n_uco_object: URIRef,
157207
n_facet_class: URIRef,

0 commit comments

Comments
 (0)