Skip to content

Commit dbc0128

Browse files
authored
Merge pull request #94 from casework/issue-85
case_validate: Add SHACL shapes to set of CDO concepts
2 parents 4cf688a + 8534c13 commit dbc0128

File tree

7 files changed

+121
-2
lines changed

7 files changed

+121
-2
lines changed

case_utils/case_validate/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
NS_OWL = rdflib.OWL
5252
NS_RDF = rdflib.RDF
5353
NS_RDFS = rdflib.RDFS
54+
NS_SH = rdflib.SH
5455

5556
_logger = logging.getLogger(os.path.basename(__file__))
5657

@@ -189,6 +190,9 @@ def main() -> None:
189190
NS_OWL.DatatypeProperty,
190191
NS_OWL.ObjectProperty,
191192
NS_RDFS.Datatype,
193+
NS_SH.NodeShape,
194+
NS_SH.PropertyShape,
195+
NS_SH.Shape,
192196
]:
193197
for ontology_triple in ontology_graph.triples(
194198
(None, NS_RDF.type, n_structural_class)

tests/case_utils/case_validate/Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ tests_srcdir := $(top_srcdir)/tests
2727
all: \
2828
all-cli \
2929
all-case_test_examples \
30-
all-uco_test_examples
30+
all-uco_test_examples \
31+
all-shape_disabling
3132

3233
.PHONY: \
3334
all-case_test_examples \
3435
all-cli \
36+
all-shape_disabling \
3537
all-uco_test_examples \
3638
check-case_test_examples \
3739
check-cli \
40+
check-shape_disabling \
3841
check-uco_test_examples
3942

4043
all-case_test_examples:
@@ -45,14 +48,19 @@ all-cli:
4548
$(MAKE) \
4649
--directory cli
4750

51+
all-shape_disabling:
52+
$(MAKE) \
53+
--directory shape_disabling
54+
4855
all-uco_test_examples:
4956
$(MAKE) \
5057
--directory uco_test_examples
5158

5259
check: \
5360
check-cli \
5461
check-case_test_examples \
55-
check-uco_test_examples
62+
check-uco_test_examples \
63+
check-shape_disabling
5664

5765
check-case_test_examples:
5866
$(MAKE) \
@@ -64,13 +72,21 @@ check-cli:
6472
--directory cli \
6573
check
6674

75+
check-shape_disabling:
76+
$(MAKE) \
77+
--directory shape_disabling \
78+
check
79+
6780
check-uco_test_examples: \
6881
uco_monolithic.ttl
6982
$(MAKE) \
7083
--directory uco_test_examples \
7184
check
7285

7386
clean:
87+
@$(MAKE) \
88+
--directory shape_disabling \
89+
clean
7490
@$(MAKE) \
7591
--directory case_test_examples \
7692
clean
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/make -f
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
SHELL := /bin/bash
15+
16+
top_srcdir := $(shell cd ../../../.. ; pwd)
17+
18+
tests_srcdir := $(top_srcdir)/tests
19+
20+
all: \
21+
validation_with_uuid_shape_disabled.txt \
22+
validation_with_uuid_shape_enabled.txt
23+
24+
check: \
25+
validation_with_uuid_shape_disabled.txt \
26+
validation_with_uuid_shape_enabled.txt
27+
28+
clean:
29+
@rm -f \
30+
*.txt \
31+
_*
32+
33+
validation_with_uuid_shape_disabled.txt: \
34+
$(tests_srcdir)/.venv.done.log \
35+
disable_shape.ttl \
36+
example.ttl
37+
source $(tests_srcdir)/venv/bin/activate \
38+
&& case_validate \
39+
--ontology disable_shape.ttl \
40+
example.ttl \
41+
> _$@
42+
mv _$@ $@
43+
44+
validation_with_uuid_shape_enabled.txt: \
45+
$(tests_srcdir)/.venv.done.log \
46+
example.ttl
47+
source $(tests_srcdir)/venv/bin/activate \
48+
&& case_validate \
49+
--allow-infos \
50+
example.ttl \
51+
> _$@
52+
mv _$@ $@
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix uco-core: <https://ontology.unifiedcyberontology.org/uco/core/> .
6+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
7+
8+
uco-core:UcoThing-identifier-regex-shape
9+
sh:deactivated "true"^^xsd:boolean ;
10+
.
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix uco-core: <https://ontology.unifiedcyberontology.org/uco/core/> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
7+
<urn:example:thing-1>
8+
a uco-core:UcoThing ;
9+
rdfs:comment "This node's IRI is designed to trigger a UUID review shape."@en ;
10+
.
11+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Validation Report
2+
Conforms: True
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Validation Report
2+
Conforms: True
3+
Results (1):
4+
Validation Result in SPARQLConstraintComponent (http://www.w3.org/ns/shacl#SPARQLConstraintComponent):
5+
Severity: sh:Info
6+
Source Shape: core:UcoThing-identifier-regex-shape
7+
Focus Node: <urn:example:thing-1>
8+
Value Node: <urn:example:thing-1>
9+
Source Constraint: [ rdf:type sh:SPARQLConstraint ; rdfs:seeAlso <https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.3> ; sh:message Literal("UcoThings are suggested to end with a UUID.", lang=en) ; sh:select Literal("
10+
PREFIX uco-core: <https://ontology.unifiedcyberontology.org/uco/core/>
11+
SELECT $this
12+
WHERE {
13+
$this a/rdfs:subClassOf* uco-core:UcoThing .
14+
FILTER (
15+
! REGEX (
16+
STR($this),
17+
"[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$",
18+
"i"
19+
)
20+
)
21+
}
22+
") ]
23+
Message: UcoThings are suggested to end with a UUID.

0 commit comments

Comments
 (0)