Skip to content

Commit 1c636e0

Browse files
committed
Add doctest for get_invalid_cdo_concepts
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent cfe4064 commit 1c636e0

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

case_utils/case_validate/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,36 @@ def get_invalid_cdo_concepts(
7575
data_graph: rdflib.Graph, ontology_graph: rdflib.Graph
7676
) -> Set[rdflib.URIRef]:
7777
"""
78-
Get the set of concepts in the data graph that are not part of the CDO ontology.
78+
Get the set of concepts in the data graph that are not part of the CDO ontologies as specified with the ontology_graph argument.
7979
8080
:param data_graph: The data graph to validate.
8181
:param ontology_graph: The ontology graph to use for validation.
8282
:return: The list of concepts in the data graph that are not part of the CDO ontology.
83+
84+
>>> from case_utils.namespace import NS_RDF, NS_OWL, NS_UCO_CORE
85+
>>> from rdflib import Graph, Literal, Namespace, URIRef
86+
>>> # Define a namespace for a knowledge base, and a namespace for custom extensions.
87+
>>> ns_kb = Namespace("http://example.org/kb/")
88+
>>> ns_ex = Namespace("http://example.org/ontology/")
89+
>>> dg = Graph()
90+
>>> og = Graph()
91+
>>> # Use an ontology graph in review that includes only a single class and a single property excerpted from UCO, but also a single custom property.
92+
>>> _ = og.add((NS_UCO_CORE.UcoObject, NS_RDF.type, NS_OWL.Class))
93+
>>> _ = og.add((NS_UCO_CORE.name, NS_RDF.type, NS_OWL.DatatypeProperty))
94+
>>> _ = og.add((ns_ex.ourCustomProperty, NS_RDF.type, NS_OWL.DatatypeProperty))
95+
>>> # Define an individual.
96+
>>> n_uco_object = ns_kb["UcoObject-f494d239-d9fd-48da-bc07-461ba86d8c6c"]
97+
>>> n_uco_object
98+
rdflib.term.URIRef('http://example.org/kb/UcoObject-f494d239-d9fd-48da-bc07-461ba86d8c6c')
99+
>>> # Review a data graph that includes only the single individual, class typo'd (capitalized incorrectly), but property OK.
100+
>>> _ = dg.add((n_uco_object, NS_RDF.type, NS_UCO_CORE.UCOObject))
101+
>>> _ = dg.add((n_uco_object, NS_UCO_CORE.name, Literal("Test")))
102+
>>> _ = dg.add((n_uco_object, ns_ex.customProperty, Literal("Custom Value")))
103+
>>> invalid_cdo_concepts = get_invalid_cdo_concepts(dg, og)
104+
>>> invalid_cdo_concepts
105+
{rdflib.term.URIRef('https://ontology.unifiedcyberontology.org/uco/core/UCOObject')}
106+
>>> # Note that the property "ourCustomProperty" was typo'd in the data graph, but this was not reported.
107+
>>> assert ns_ex.ourCustomProperty not in invalid_cdo_concepts
83108
"""
84109
# Construct set of CDO concepts for data graph concept-existence review.
85110
cdo_concepts: Set[rdflib.URIRef] = set()

0 commit comments

Comments
 (0)