Skip to content
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

(Do not merge) Draft OC-191 #321

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Add test demonstrating SHACL validation issue with specified vocabula…
…ries

This patch is known to trigger three unit test failures.

The added tests need design discussion.  This patch might not be
preserved in UCO's development history, but its approximate effect is
expected to be added as a unit test as a solution is identified.

References:
* [OC-12] UCO's idea of "Open vocabulary" does not agree with its
  implementation with owl:oneOf

Signed-off-by: Alex Nelson <[email protected]>
ajnelson-nist committed Dec 3, 2021
commit 764ccbf8e0241ae400116c6532c36cbdff726bcb
83 changes: 79 additions & 4 deletions tests/examples/Makefile
Original file line number Diff line number Diff line change
@@ -22,10 +22,19 @@ all: \
action_inheritance_XFAIL_validation.ttl \
action_result_PASS_validation.ttl \
location_PASS_validation.ttl \
location_XFAIL_validation.ttl
location_XFAIL_validation.ttl \
relationship_PASS_validation.ttl \
relationship_PASS_via_rdflib_validation_after_translation.ttl \
relationship_PASS_via_rdf_toolkit_validation_after_translation.ttl \
relationship_XFAIL_validation.ttl

.PHONY: \
check-context

.PRECIOUS: \
%_validation.ttl
%_validation.ttl \
relationship_PASS_via_rdflib.ttl \
relationship_PASS_via_rdf_toolkit.ttl

# NOTE - this recipe makes an allowance for a certain failure type
# reported by pyshacl. Pyshacl will exit status 1 in the case where
@@ -62,16 +71,82 @@ all: \
rm __$@
mv _$@ $@

%_validation_after_translation.ttl: \
%.ttl \
$(tests_srcdir)/.venv.done.log \
$(tests_srcdir)/uco_monolithic.ttl
source $(tests_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
--inference none \
--ont-file-format turtle \
--ont-graph $(tests_srcdir)/uco_monolithic.ttl \
--shacl $(tests_srcdir)/uco_monolithic.ttl \
--shacl-file-format turtle \
--output __$@ \
$< \
; rc=$$? ; test 0 -eq $$rc -o 1 -eq $$rc
java -jar $(top_srcdir)/lib/rdf-toolkit.jar \
--infer-base-iri \
--inline-blank-nodes \
--source __$@ \
--source-format turtle \
--target _$@ \
--target-format turtle
rm __$@
mv _$@ $@

check: \
action_inheritance_PASS_validation.ttl \
action_inheritance_XFAIL_validation.ttl \
action_result_PASS_validation.ttl \
check-context \
location_PASS_validation.ttl \
location_XFAIL_validation.ttl
location_XFAIL_validation.ttl \
relationship_PASS_validation.ttl \
relationship_PASS_via_rdflib_validation_after_translation.ttl \
relationship_PASS_via_rdf_toolkit_validation_after_translation.ttl \
relationship_XFAIL_validation.ttl
source $(tests_srcdir)/venv/bin/activate \
&& pytest \
--log-level=DEBUG

# These Turtle renders of the JSON file are for confirming data characteristics are preserved when consumed by multiple RDF applications.
check-context: \
relationship_PASS_via_rdflib.ttl \
relationship_PASS_via_rdf_toolkit.ttl
diff $^

clean:
@rm -f \
*_validation.ttl
*_validation*.ttl

relationship_PASS_via_rdf_toolkit.ttl: \
relationship_PASS.json
java -jar $(top_srcdir)/lib/rdf-toolkit.jar \
--infer-base-iri \
--inline-blank-nodes \
--source $< \
--source-format json-ld \
--target _$@ \
--target-format turtle
mv _$@ $@

relationship_PASS_via_rdflib.ttl: \
relationship_PASS.json \
$(tests_srcdir)/.venv.done.log \
$(tests_srcdir)/src/glom_graph.py
source $(tests_srcdir)/venv/bin/activate \
&& python3 $(tests_srcdir)/src/glom_graph.py \
__$@ \
$<
java -jar $(top_srcdir)/lib/rdf-toolkit.jar \
--infer-base-iri \
--inline-blank-nodes \
--source __$@ \
--source-format turtle \
--target _$@ \
--target-format turtle
rm __$@
mv _$@ $@
70 changes: 70 additions & 0 deletions tests/examples/relationship_PASS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"@context": {
"action": "https://unifiedcyberontology.org/ontology/uco/action#",
"core": "https://unifiedcyberontology.org/ontology/uco/core#",
"kb": "http://example.org/kb/",
"observable": "https://unifiedcyberontology.org/ontology/uco/observable#",
"vocabulary": "https://unifiedcyberontology.org/ontology/uco/vocabulary#",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@graph": [
{
"@id": "kb:relationship1",
"@type": "core:Relationship",
"core:isDirectional": true,
"core:kindOfRelationship": "CUSTOM_Influenced",
"core:source": {
"@id": "kb:file1"
},
"core:target": {
"@id": "kb:zipfile1"
}
},
{
"@id": "kb:relationship2",
"@type": "observable:ObservableRelationship",
"core:isDirectional": true,
"core:kindOfRelationship": {
"@type": "vocabulary:ObservableObjectRelationshipVocab",
"@value": "Contained_Within"
},
"core:source": {
"@id": "kb:file1"
},
"core:target": {
"@id": "kb:zipfile1"
}
},
{
"@id": "kb:relationship3",
"@type": "core:Relationship",
"core:isDirectional": true,
"core:kindOfRelationship": {
"@type": "vocabulary:ActionRelationshipVocab",
"@value": "Initiated"
},
"core:source": {
"@id": "kb:action1"
},
"core:target": {
"@id": "kb:action2"
}
},
{
"@id": "kb:action1",
"@type": "action:Action"
},
{
"@id": "kb:action2",
"@type": "action:Action"
},
{
"@id": "kb:file1",
"@type": "observable:File"
},
{
"@id": "kb:zipfile1",
"@type": "observable:ArchiveFile"
}
]
}
45 changes: 45 additions & 0 deletions tests/examples/relationship_PASS_validation.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@prefix core: <https://unifiedcyberontology.org/ontology/uco/core#> .
@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 vocabulary: <https://unifiedcyberontology.org/ontology/uco/vocabulary#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

[]
a sh:ValidationReport ;
sh:conforms "false"^^xsd:boolean ;
sh:result
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/relationship2> ;
sh:resultMessage "Value is not Literal with datatype xsd:string" ;
sh:resultPath core:kindOfRelationship ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:kindOfRelationship ;
] ;
sh:value "Contained_Within"^^vocabulary:ObservableObjectRelationshipVocab ;
] ,
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/relationship3> ;
sh:resultMessage "Value is not Literal with datatype xsd:string" ;
sh:resultPath core:kindOfRelationship ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:kindOfRelationship ;
] ;
sh:value "Initiated"^^vocabulary:ActionRelationshipVocab ;
]
;
.

50 changes: 50 additions & 0 deletions tests/examples/relationship_PASS_via_rdf_toolkit.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@prefix action: <https://unifiedcyberontology.org/ontology/uco/action#> .
@prefix core: <https://unifiedcyberontology.org/ontology/uco/core#> .
@prefix kb: <http://example.org/kb/> .
@prefix observable: <https://unifiedcyberontology.org/ontology/uco/observable#> .
@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 vocabulary: <https://unifiedcyberontology.org/ontology/uco/vocabulary#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

kb:action1
a action:Action ;
.

kb:action2
a action:Action ;
.

kb:file1
a observable:File ;
.

kb:relationship1
a core:Relationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "CUSTOM_Influenced" ;
core:source kb:file1 ;
core:target kb:zipfile1 ;
.

kb:relationship2
a observable:ObservableRelationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "Contained_Within"^^vocabulary:ObservableObjectRelationshipVocab ;
core:source kb:file1 ;
core:target kb:zipfile1 ;
.

kb:relationship3
a core:Relationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "Initiated"^^vocabulary:ActionRelationshipVocab ;
core:source kb:action1 ;
core:target kb:action2 ;
.

kb:zipfile1
a observable:ArchiveFile ;
.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@prefix core: <https://unifiedcyberontology.org/ontology/uco/core#> .
@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 vocabulary: <https://unifiedcyberontology.org/ontology/uco/vocabulary#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

[]
a sh:ValidationReport ;
sh:conforms "false"^^xsd:boolean ;
sh:result
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/relationship2> ;
sh:resultMessage "Value is not Literal with datatype xsd:string" ;
sh:resultPath core:kindOfRelationship ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:kindOfRelationship ;
] ;
sh:value "Contained_Within"^^vocabulary:ObservableObjectRelationshipVocab ;
] ,
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/relationship3> ;
sh:resultMessage "Value is not Literal with datatype xsd:string" ;
sh:resultPath core:kindOfRelationship ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:kindOfRelationship ;
] ;
sh:value "Initiated"^^vocabulary:ActionRelationshipVocab ;
]
;
.

50 changes: 50 additions & 0 deletions tests/examples/relationship_PASS_via_rdflib.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@prefix action: <https://unifiedcyberontology.org/ontology/uco/action#> .
@prefix core: <https://unifiedcyberontology.org/ontology/uco/core#> .
@prefix kb: <http://example.org/kb/> .
@prefix observable: <https://unifiedcyberontology.org/ontology/uco/observable#> .
@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 vocabulary: <https://unifiedcyberontology.org/ontology/uco/vocabulary#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

kb:action1
a action:Action ;
.

kb:action2
a action:Action ;
.

kb:file1
a observable:File ;
.

kb:relationship1
a core:Relationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "CUSTOM_Influenced" ;
core:source kb:file1 ;
core:target kb:zipfile1 ;
.

kb:relationship2
a observable:ObservableRelationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "Contained_Within"^^vocabulary:ObservableObjectRelationshipVocab ;
core:source kb:file1 ;
core:target kb:zipfile1 ;
.

kb:relationship3
a core:Relationship ;
core:isDirectional "true"^^xsd:boolean ;
core:kindOfRelationship "Initiated"^^vocabulary:ActionRelationshipVocab ;
core:source kb:action1 ;
core:target kb:action2 ;
.

kb:zipfile1
a observable:ArchiveFile ;
.

Loading