Skip to content

Commit 6d8c458

Browse files
authored
Merge pull request #31 from eScienceLab/30-requested-workflow-run
Requested workflow run
2 parents 03da5f8 + 830d4e3 commit 6d8c458

4 files changed

Lines changed: 379 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 sh: <http://www.w3.org/ns/shacl#> .
21+
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
22+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
23+
24+
25+
five-safes-crate:RootDataEntityMentionsCreateAction
26+
a sh:NodeShape ;
27+
sh:name "RootDataEntity" ;
28+
sh:targetClass ro-crate:RootDataEntity ;
29+
sh:description "" ;
30+
31+
sh:property [
32+
a sh:PropertyShape ;
33+
sh:name "mentions" ;
34+
sh:path schema:mentions;
35+
sh:qualifiedValueShape [
36+
sh:class schema:CreateAction ;
37+
] ;
38+
sh:qualifiedMinCount 1 ;
39+
sh:severity sh:Violation ;
40+
sh:message "`RootDataEntity` MUST reference at least one `CreateAction` through `mentions`" ;
41+
] .
42+
43+
44+
five-safes-crate:CreateActionInstrumentAndStatus
45+
a sh:NodeShape ;
46+
sh:name "CreateAction" ;
47+
sh:targetClass schema:CreateAction ;
48+
sh:description "" ;
49+
50+
sh:property [
51+
a sh:PropertyShape ;
52+
sh:name "instrument" ;
53+
sh:path schema:instrument;
54+
sh:minCount 1 ;
55+
sh:severity sh:Violation ;
56+
sh:message "`CreateAction` MUST have the `schema:instrument` property" ;
57+
] ;
58+
sh:sparql [
59+
a sh:SPARQLConstraint ;
60+
sh:name "instrument" ;
61+
sh:prefixes ro-crate:sparqlPrefixes ;
62+
sh:select """
63+
SELECT $this ?main ?instrument
64+
WHERE {
65+
?root schema:mainEntity ?main .
66+
$this schema:instrument ?instrument .
67+
FILTER (?instrument != ?main)
68+
}
69+
""" ;
70+
sh:severity sh:Violation ;
71+
sh:message "`CreateAction` --> `instrument` MUST reference the same entity as `Root Data Entity` --> `mainEntity`" ;
72+
] ;
73+
sh:sparql [
74+
a sh:SPARQLConstraint ;
75+
sh:prefixes ro-crate:sparqlPrefixes ;
76+
sh:name "object" ;
77+
sh:select """
78+
SELECT $this ?object
79+
WHERE {
80+
$this schema:object ?object .
81+
FILTER NOT EXISTS { ?object a ?type . }
82+
}
83+
""" ;
84+
sh:severity sh:Violation ;
85+
sh:message "Each `object` in `CreateAction` MUST reference an existing entity." ;
86+
] .
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 sh: <http://www.w3.org/ns/shacl#> .
21+
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
22+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
23+
24+
25+
# CreateAction SHOULD have object property with minimum cardinality 1
26+
five-safes-crate:CreateActionShouldHaveObjectProperty
27+
a sh:NodeShape ;
28+
sh:targetClass schema:CreateAction ;
29+
sh:name "CreateAction" ;
30+
sh:property [
31+
sh:path schema:object ;
32+
sh:minCount 1 ;
33+
sh:nodeKind sh:IRI ;
34+
sh:severity sh:Warning ;
35+
sh:message "`CreateAction` SHOULD have the property `object` with IRI values." ;
36+
] .

tests/data/crates/valid/five-safes-crate-result/ro-crate-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"@type": "PropertyValue",
161161
"name": "tre72",
162162
"value": "project81"
163-
},
163+
},
164164
{
165165
"@id": "input1.txt",
166166
"@type": "File",
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# Copyright (c) 2024-2025 CRS4
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+
import logging
16+
17+
from rocrate_validator.models import Severity
18+
from tests.ro_crates import ValidROC
19+
from tests.shared import do_entity_test, SPARQL_PREFIXES
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
# ----- MUST fails tests
26+
27+
28+
def test_rocrate_does_not_have_createaction():
29+
"""
30+
Test a Five Safes Crate where no `CreateAction` entity exists.
31+
(We remove the entire CreateAction entity from the RO-Crate)
32+
"""
33+
sparql = (
34+
SPARQL_PREFIXES
35+
+ """
36+
DELETE {
37+
?action ?p ?o .
38+
?s ?p2 ?action .
39+
}
40+
WHERE {
41+
?action a schema:CreateAction .
42+
?action ?p ?o .
43+
OPTIONAL { ?s ?p2 ?action . }
44+
}
45+
"""
46+
)
47+
48+
do_entity_test(
49+
rocrate_path=ValidROC().five_safes_crate_request,
50+
requirement_severity=Severity.REQUIRED,
51+
expected_validation_result=False,
52+
expected_triggered_requirements=["RootDataEntity"],
53+
expected_triggered_issues=[
54+
"`RootDataEntity` MUST reference at least one `CreateAction` through `mentions`"
55+
],
56+
profile_identifier="five-safes-crate",
57+
rocrate_entity_mod_sparql=sparql,
58+
)
59+
60+
61+
def test_rootdataentity_does_not_have_mentions_property():
62+
"""
63+
Test a Five Safes Crate where RootDataEntity does not have the property mentions.
64+
(We remove the property mentions from the RootDataEntity entity)
65+
"""
66+
sparql = (
67+
SPARQL_PREFIXES
68+
+ """
69+
DELETE {
70+
<./> schema:mentions ?o .
71+
}
72+
WHERE {
73+
<./> schema:mentions ?o .
74+
}
75+
"""
76+
)
77+
78+
do_entity_test(
79+
rocrate_path=ValidROC().five_safes_crate_request,
80+
requirement_severity=Severity.REQUIRED,
81+
expected_validation_result=False,
82+
expected_triggered_requirements=["RootDataEntity"],
83+
expected_triggered_issues=[
84+
"`RootDataEntity` MUST reference at least one `CreateAction` through `mentions`"
85+
],
86+
profile_identifier="five-safes-crate",
87+
rocrate_entity_mod_sparql=sparql,
88+
)
89+
90+
91+
def test_rootdataentity_does_not_mention_create_action():
92+
"""
93+
Test a Five Safes Crate where `RootDataEntity` does not `mention` a `CreateAction` entity.
94+
(We replace the object of RooDataEntity --> mentions with a string literal).
95+
"""
96+
sparql = (
97+
SPARQL_PREFIXES
98+
+ """
99+
DELETE {
100+
<./> schema:mentions ?o .
101+
}
102+
INSERT {
103+
<./> schema:mentions "This is not a CreateAction entity" .
104+
}
105+
WHERE {
106+
<./> schema:mentions ?o .
107+
}
108+
"""
109+
)
110+
111+
do_entity_test(
112+
rocrate_path=ValidROC().five_safes_crate_request,
113+
requirement_severity=Severity.REQUIRED,
114+
expected_validation_result=False,
115+
expected_triggered_requirements=["RootDataEntity"],
116+
expected_triggered_issues=[
117+
"`RootDataEntity` MUST reference at least one `CreateAction` through `mentions`"
118+
],
119+
profile_identifier="five-safes-crate",
120+
rocrate_entity_mod_sparql=sparql,
121+
)
122+
123+
124+
def test_createaction_does_not_have_instrument_property():
125+
"""
126+
Test a Five Safes Crate where `CreateAction` does not have the property `instrument`.
127+
(We remove the property `instrument` from the `CreateAction` entity)
128+
"""
129+
sparql = (
130+
SPARQL_PREFIXES
131+
+ """
132+
DELETE {
133+
?action schema:instrument ?o .
134+
}
135+
WHERE {
136+
?action schema:instrument ?o ;
137+
a schema:CreateAction .
138+
}
139+
"""
140+
)
141+
142+
do_entity_test(
143+
rocrate_path=ValidROC().five_safes_crate_request,
144+
requirement_severity=Severity.REQUIRED,
145+
expected_validation_result=False,
146+
expected_triggered_requirements=["CreateAction"],
147+
expected_triggered_issues=[
148+
"`CreateAction` MUST have the `schema:instrument` property"
149+
],
150+
profile_identifier="five-safes-crate",
151+
rocrate_entity_mod_sparql=sparql,
152+
)
153+
154+
155+
def test_createaction_does_not_reference_mainentity_via_instrument():
156+
"""
157+
Test a Five Safes Crate where `CreateAction` --> `instrument` does not
158+
reference `mainEntity`.
159+
(We replace `mainEntity` with a literal as the object of `CreateAction` --> `instrument`)
160+
"""
161+
sparql = (
162+
SPARQL_PREFIXES
163+
+ """
164+
DELETE {
165+
?action schema:instrument ?o .
166+
}
167+
INSERT {
168+
?action schema:instrument "This is not the mainEntity" .
169+
}
170+
WHERE {
171+
?action schema:instrument ?o ;
172+
a schema:CreateAction .
173+
}
174+
"""
175+
)
176+
177+
do_entity_test(
178+
rocrate_path=ValidROC().five_safes_crate_request,
179+
requirement_severity=Severity.REQUIRED,
180+
expected_validation_result=False,
181+
expected_triggered_requirements=["CreateAction"],
182+
expected_triggered_issues=[
183+
"`CreateAction` --> `instrument` MUST reference the same entity as `Root Data Entity` --> `mainEntity`"
184+
],
185+
profile_identifier="five-safes-crate",
186+
rocrate_entity_mod_sparql=sparql,
187+
)
188+
189+
190+
def test_createaction_object_does_not_reference_existing_entities():
191+
"""
192+
Test a Five Safes Crate where `CreateAction` --> `object` does not
193+
reference an existing entity in the RO-Crate.
194+
(We replace the objects of `CreateAction` --> `object` with a literal.`)
195+
"""
196+
sparql = (
197+
SPARQL_PREFIXES
198+
+ """
199+
DELETE {
200+
?action schema:object ?o .
201+
}
202+
INSERT {
203+
?action schema:object "This is not an entity in the RO-Crate" .
204+
}
205+
WHERE {
206+
?action schema:object ?o ;
207+
a schema:CreateAction .
208+
}
209+
"""
210+
)
211+
212+
do_entity_test(
213+
rocrate_path=ValidROC().five_safes_crate_request,
214+
requirement_severity=Severity.REQUIRED,
215+
expected_validation_result=False,
216+
expected_triggered_requirements=["CreateAction"],
217+
expected_triggered_issues=[
218+
"Each `object` in `CreateAction` MUST reference an existing entity."
219+
],
220+
profile_identifier="five-safes-crate",
221+
rocrate_entity_mod_sparql=sparql,
222+
)
223+
224+
225+
# ----- SHOULD fails tests
226+
227+
228+
def test_createaction_does_not_have_object_property():
229+
"""
230+
Test a Five Safes Crate where `CreateAction` does not have the property `object`.
231+
(We remove the property `object` from `CreateAction`)
232+
"""
233+
sparql = (
234+
SPARQL_PREFIXES
235+
+ """
236+
DELETE {
237+
?action schema:object ?o .
238+
}
239+
WHERE {
240+
?action schema:object ?o ;
241+
a schema:CreateAction .
242+
}
243+
"""
244+
)
245+
246+
do_entity_test(
247+
rocrate_path=ValidROC().five_safes_crate_request,
248+
requirement_severity=Severity.RECOMMENDED,
249+
expected_validation_result=False,
250+
expected_triggered_requirements=["CreateAction"],
251+
expected_triggered_issues=[
252+
"`CreateAction` SHOULD have the property `object` with IRI values."
253+
],
254+
profile_identifier="five-safes-crate",
255+
rocrate_entity_mod_sparql=sparql,
256+
)

0 commit comments

Comments
 (0)