Skip to content

Commit 43289a5

Browse files
committed
Added CHACL code and corresponding tests about RootDataEntity conforming to the appropriate ro-crate profile.
1 parent 6a6f98d commit 43289a5

2 files changed

Lines changed: 177 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright (c) 2025 eScience Lab, The University of Manchester
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
@prefix ro: <./> .
16+
@prefix ro-crate: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> .
17+
@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> .
18+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
19+
@prefix schema: <http://schema.org/> .
20+
@prefix dct: <http://purl.org/dc/terms/> .
21+
@prefix sh: <http://www.w3.org/ns/shacl#> .
22+
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
23+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
24+
@prefix shp: <https://w3id.org/shp#> .
25+
26+
27+
# Root Dataset SHOULD declare conformsTo Five Safes profile
28+
five-safes-crate:RootDatasetConformsToFiveSafes
29+
a sh:NodeShape ;
30+
sh:name "RootDataEntity" ;
31+
sh:targetClass ro-crate:RootDataEntity ;
32+
33+
sh:property [
34+
a sh:PropertyShape ;
35+
sh:name "conformsTo Five Safes profile" ;
36+
sh:path dct:conformsTo ;
37+
sh:hasValue <https://w3id.org/5s-crate/0.4> ;
38+
sh:severity sh:Warning ;
39+
sh:message "Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4" ;
40+
] .
41+
42+
# five-safes-crate:RootDatasetDatePublishedWhenPublished
43+
# a sh:NodeShape ;
44+
# sh:name "datePublished present on published crates" ;
45+
# sh:description "If the root dataset is published (has schema:publisher), it SHOULD have schema:datePublished." ;
46+
# sh:targetNode ro: ;
47+
# sh:severity sh:Warning ;
48+
# sh:message "Published crates SHOULD include schema:datePublished." ;
49+
# sh:or (
50+
# # datePublished not required if no publisher:
51+
# [ sh:not [ sh:property [
52+
# sh:path schema:publisher ;
53+
# sh:minCount 1 ;
54+
# ]]]
55+
# # datePublished required if publisher present:
56+
# [ sh:property [
57+
# sh:path schema:datePublished ;
58+
# sh:minCount 1 ;
59+
# ]]
60+
# ) .
61+
62+
# five-safes-crate:RootDatasetLicenseWhenPublished
63+
# a sh:NodeShape ;
64+
# sh:name "License present on published crates" ;
65+
# sh:description "If the root dataset is published (has schema:publisher), it SHOULD declare a license." ;
66+
# sh:targetNode ro: ;
67+
# sh:severity sh:Warning ;
68+
# sh:message "Profile Conformance: Published crates SHOULD include a license." ;
69+
# sh:or (
70+
# # license not required if no publisher:
71+
# [ sh:not [ sh:property [
72+
# sh:path schema:publisher ;
73+
# sh:minCount 1 ;
74+
# ]]]
75+
# # license required if publisher present:
76+
# [ sh:property [
77+
# sh:path schema:license ;
78+
# sh:minCount 1 ;
79+
# ]]
80+
# ) .
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) 2024-2025 CRS4
2+
# Copyright (c) 2025-2026 eScience Lab, The University of Manchester
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import logging
17+
18+
from rocrate_validator.models import Severity
19+
from tests.ro_crates import ValidROC
20+
from tests.shared import do_entity_test, SPARQL_PREFIXES
21+
22+
# set up logging
23+
logger = logging.getLogger(__name__)
24+
25+
26+
# ----- MUST fails tests
27+
28+
29+
# ----- SHOULD fails tests
30+
31+
32+
def test_5src_root_data_entity_missing_conformsto_property():
33+
"""
34+
Test a Five Safes Crate where the RootDataEntity does not have the conformsTo property.
35+
"""
36+
sparql = (
37+
SPARQL_PREFIXES
38+
+ """
39+
DELETE {
40+
?rootdataentity dct:conformsTo ?profile .
41+
}
42+
WHERE {
43+
?metadatafile a schema:CreativeWork ;
44+
schema:about ?rootdataentity .
45+
?rootdataentity dct:conformsTo ?profile .
46+
}
47+
"""
48+
)
49+
50+
do_entity_test(
51+
rocrate_path=ValidROC().five_safes_crate_request,
52+
requirement_severity=Severity.RECOMMENDED,
53+
expected_validation_result=False,
54+
expected_triggered_requirements=["RootDataEntity"],
55+
expected_triggered_issues=[
56+
"Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4"
57+
],
58+
profile_identifier="five-safes-crate",
59+
rocrate_entity_mod_sparql=sparql,
60+
)
61+
62+
63+
def test_5src_root_data_entity_conforms_to_wrong_profile():
64+
"""
65+
Test a Five Safes Crate where the RootDataEntity does not conform to the expected profile.
66+
"""
67+
sparql = (
68+
SPARQL_PREFIXES
69+
+ """
70+
DELETE {
71+
?rootdataentity dct:conformsTo ?profile .
72+
}
73+
INSERT {
74+
?rootdataentity dct:conformsTo "This is not the IRI to the 5sc profile"
75+
}
76+
WHERE {
77+
?metadatafile a schema:CreativeWork ;
78+
schema:about ?rootdataentity .
79+
?rootdataentity dct:conformsTo ?profile .
80+
}
81+
"""
82+
)
83+
84+
do_entity_test(
85+
rocrate_path=ValidROC().five_safes_crate_request,
86+
requirement_severity=Severity.RECOMMENDED,
87+
expected_validation_result=False,
88+
expected_triggered_requirements=["RootDataEntity"],
89+
expected_triggered_issues=[
90+
"Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4"
91+
],
92+
profile_identifier="five-safes-crate",
93+
rocrate_entity_mod_sparql=sparql,
94+
)
95+
96+
97+
# ----- MAY fails tests

0 commit comments

Comments
 (0)