@@ -75,11 +75,36 @@ def get_invalid_cdo_concepts(
75
75
data_graph : rdflib .Graph , ontology_graph : rdflib .Graph
76
76
) -> Set [rdflib .URIRef ]:
77
77
"""
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 .
79
79
80
80
:param data_graph: The data graph to validate.
81
81
:param ontology_graph: The ontology graph to use for validation.
82
82
: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
83
108
"""
84
109
# Construct set of CDO concepts for data graph concept-existence review.
85
110
cdo_concepts : Set [rdflib .URIRef ] = set ()
0 commit comments