Skip to content

case_validate: Add SHACL shapes to set of CDO concepts #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions case_utils/case_validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
NS_OWL = rdflib.OWL
NS_RDF = rdflib.RDF
NS_RDFS = rdflib.RDFS
NS_SH = rdflib.SH

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

Expand Down Expand Up @@ -189,6 +190,9 @@ def main() -> None:
NS_OWL.DatatypeProperty,
NS_OWL.ObjectProperty,
NS_RDFS.Datatype,
NS_SH.NodeShape,
NS_SH.PropertyShape,
NS_SH.Shape,
]:
for ontology_triple in ontology_graph.triples(
(None, NS_RDF.type, n_structural_class)
Expand Down
20 changes: 18 additions & 2 deletions tests/case_utils/case_validate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ tests_srcdir := $(top_srcdir)/tests
all: \
all-cli \
all-case_test_examples \
all-uco_test_examples
all-uco_test_examples \
all-shape_disabling

.PHONY: \
all-case_test_examples \
all-cli \
all-shape_disabling \
all-uco_test_examples \
check-case_test_examples \
check-cli \
check-shape_disabling \
check-uco_test_examples

all-case_test_examples:
Expand All @@ -45,14 +48,19 @@ all-cli:
$(MAKE) \
--directory cli

all-shape_disabling:
$(MAKE) \
--directory shape_disabling

all-uco_test_examples:
$(MAKE) \
--directory uco_test_examples

check: \
check-cli \
check-case_test_examples \
check-uco_test_examples
check-uco_test_examples \
check-shape_disabling

check-case_test_examples:
$(MAKE) \
Expand All @@ -64,13 +72,21 @@ check-cli:
--directory cli \
check

check-shape_disabling:
$(MAKE) \
--directory shape_disabling \
check

check-uco_test_examples: \
uco_monolithic.ttl
$(MAKE) \
--directory uco_test_examples \
check

clean:
@$(MAKE) \
--directory shape_disabling \
clean
@$(MAKE) \
--directory case_test_examples \
clean
Expand Down
52 changes: 52 additions & 0 deletions tests/case_utils/case_validate/shape_disabling/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/make -f

# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.

SHELL := /bin/bash

top_srcdir := $(shell cd ../../../.. ; pwd)

tests_srcdir := $(top_srcdir)/tests

all: \
validation_with_uuid_shape_disabled.txt \
validation_with_uuid_shape_enabled.txt

check: \
validation_with_uuid_shape_disabled.txt \
validation_with_uuid_shape_enabled.txt

clean:
@rm -f \
*.txt \
_*

validation_with_uuid_shape_disabled.txt: \
$(tests_srcdir)/.venv.done.log \
disable_shape.ttl \
example.ttl
source $(tests_srcdir)/venv/bin/activate \
&& case_validate \
--ontology disable_shape.ttl \
example.ttl \
> _$@
mv _$@ $@

validation_with_uuid_shape_enabled.txt: \
$(tests_srcdir)/.venv.done.log \
example.ttl
source $(tests_srcdir)/venv/bin/activate \
&& case_validate \
--allow-infos \
example.ttl \
> _$@
mv _$@ $@
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix uco-core: <https://ontology.unifiedcyberontology.org/uco/core/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

uco-core:UcoThing-identifier-regex-shape
sh:deactivated "true"^^xsd:boolean ;
.

11 changes: 11 additions & 0 deletions tests/case_utils/case_validate/shape_disabling/example.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix uco-core: <https://ontology.unifiedcyberontology.org/uco/core/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<urn:example:thing-1>
a uco-core:UcoThing ;
rdfs:comment "This node's IRI is designed to trigger a UUID review shape."@en ;
.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Validation Report
Conforms: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Validation Report
Conforms: True
Results (1):
Validation Result in SPARQLConstraintComponent (http://www.w3.org/ns/shacl#SPARQLConstraintComponent):
Severity: sh:Info
Source Shape: core:UcoThing-identifier-regex-shape
Focus Node: <urn:example:thing-1>
Value Node: <urn:example:thing-1>
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("
PREFIX uco-core: <https://ontology.unifiedcyberontology.org/uco/core/>
SELECT $this
WHERE {
$this a/rdfs:subClassOf* uco-core:UcoThing .
FILTER (
! REGEX (
STR($this),
"[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$",
"i"
)
)
}
") ]
Message: UcoThings are suggested to end with a UUID.