Skip to content

Commit 62ecfa4

Browse files
Merge pull request #3 from casework/correct_demonstration_results
Correct demonstration results
2 parents 7c8e35e + 398a1fb commit 62ecfa4

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

case_example_mapping/dict_to_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main() -> None:
3434
sys.exit(1)
3535
output_path: str = sys.argv[1]
3636

37-
# Add an uco-observable:ObservableObject to the graph
37+
# Add a uco-identity:Organization to the graph
3838
case["@graph"].append(
3939
{
4040
"@id": "kb:organization-2b3b98e2-aea2-4270-876a-7f9917623cb6",

case_example_mapping/rdf_to_case.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

33
from rdflib import Graph, Literal, Namespace, URIRef
4-
from rdflib.namespace import XSD
4+
from rdflib.namespace import RDF, XSD
55

66

77
def main() -> None:
@@ -22,11 +22,28 @@ def main() -> None:
2222
"https://ontology.unifiedcyberontology.org/uco/core/"
2323
)
2424

25+
ns_kb: Namespace = Namespace("http://example.org/kb/")
26+
27+
# Define an individual.
28+
# RDFLib Namespace provides two ways to create a URIRef of the
29+
# namespace as a string-prefix concatenated with an argument:
30+
# * The . operator.
31+
# * The [] operator.
32+
iri_my_organization = ns_kb["organization-b1534f63-b1c3-4b5c-a937-cbe7077571f2"]
33+
2534
g.add(
2635
(
36+
iri_my_organization,
37+
RDF.type,
2738
URIRef(
2839
"https://ontology.unifiedcyberontology.org/uco/identity/Organization"
2940
),
41+
)
42+
)
43+
44+
g.add(
45+
(
46+
iri_my_organization,
3047
ns_core.name,
3148
Literal("Cyber Domain Ontology", datatype=XSD.string),
3249
)

tests/case_output_test.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
22
import unittest
3+
from typing import Set
34

4-
from rdflib import Graph
5+
from rdflib import Graph, URIRef
56

67

78
class CASEOutputTests(unittest.TestCase):
@@ -35,3 +36,43 @@ def test_triples_exist(self) -> None:
3536
self.assertGreaterEqual(
3637
len(g), 1, f"There were no triples found in file: {file}"
3738
)
39+
40+
def test_organization_iri_found(self) -> None:
41+
"""
42+
Identifies all CASE graph files within the ./output directory and ensures they contain a graph individual that:
43+
44+
* Is, by RDF class-membership, a UCO organization; and
45+
* Has the UCO name "Cyber Domain Ontology".
46+
47+
When adapting this template repository, this test should be replaced.
48+
"""
49+
files_tested: int = 0
50+
source_directory: str = "./output"
51+
query = """\
52+
PREFIX uco-core: <https://ontology.unifiedcyberontology.org/uco/core/>
53+
PREFIX uco-identity: <https://ontology.unifiedcyberontology.org/uco/identity/>
54+
SELECT ?nOrganization
55+
WHERE {
56+
?nOrganization
57+
a uco-identity:Organization ;
58+
uco-core:name "Cyber Domain Ontology" ;
59+
.
60+
}
61+
"""
62+
for file in os.listdir(source_directory):
63+
if not (file.endswith(".json") or file.endswith(".jsonld")):
64+
continue
65+
files_tested += 1
66+
67+
computed: Set[URIRef] = set()
68+
69+
g: Graph = Graph()
70+
g.parse(os.path.join(source_directory, file))
71+
for result in g.query(query):
72+
# Graph.query for a SELECT query returns a tuple, with
73+
# member count as long as the number of bound variables.
74+
computed.add(result[0])
75+
self.assertEqual(
76+
1, len(computed), f"Organization was not found in file: {file}"
77+
)
78+
self.assertGreaterEqual(files_tested, 0, "No output files were tested.")

0 commit comments

Comments
 (0)