Skip to content

Commit a1dd141

Browse files
authored
Merge pull request #13 from eScienceLab/11-responsible-agent
Added checks for rules about Requesting Agent.
2 parents cce4652 + 8d569e9 commit a1dd141

File tree

7 files changed

+255
-170
lines changed

7 files changed

+255
-170
lines changed

rocrate_validator/profiles/five-safes-crate/must/1_funder.ttl

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
26+
five-safes-crate:CreateActionHasAgent
27+
a sh:NodeShape ;
28+
sh:name "CreateAction" ;
29+
sh:targetClass schema:CreateAction ;
30+
sh:description "Checks that a CreateAction has an agent and that each agent is a schema:Person." ;
31+
32+
# CreateAction entity MUST have an agent (IRI)
33+
sh:property [
34+
a sh:PropertyShape ;
35+
sh:name "Has Agent" ;
36+
sh:path schema:agent ;
37+
sh:minCount 1 ;
38+
sh:nodeKind sh:IRI ;
39+
sh:severity sh:Violation ;
40+
sh:message "CreateAction MUST have at least one schema:agent that is a contextual entity." ;
41+
] ;
42+
43+
# The agent of a CreateAction entity MUST be a Person
44+
sh:property [
45+
a sh:PropertyShape ;
46+
sh:name "Agent is a Person" ;
47+
sh:path schema:agent ;
48+
sh:nodeKind sh:IRI ;
49+
sh:class schema:Person ;
50+
sh:severity sh:Violation ;
51+
sh:message "Each CreateAction agent MUST be typed as schema:Person." ;
52+
] ;
53+
54+
# If any agent affiliation exists, it MUST be an Organization (IRI)
55+
sh:property [
56+
a sh:PropertyShape ;
57+
sh:name "Affiliation is an Organization" ;
58+
sh:path ( schema:agent schema:affiliation ) ;
59+
sh:class schema:Organization ;
60+
sh:nodeKind sh:IRI ;
61+
sh:severity sh:Violation ;
62+
sh:message "The affiliation of a CreateAction's agent MUST be a contextual entity with type schema:Organization." ;
63+
] .

rocrate_validator/profiles/five-safes-crate/must/1_root_data_entity_metadata.ttl renamed to rocrate_validator/profiles/five-safes-crate/should/2_requesting_agent.ttl

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024-2025 CRS4
1+
# Copyright (c) 2025 eScience Lab, The University of Manchester
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,23 +16,34 @@
1616
@prefix ro-crate: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> .
1717
@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> .
1818
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
19-
@prefix schema_org: <http://schema.org/> .
19+
@prefix schema: <http://schema.org/> .
2020
@prefix sh: <http://www.w3.org/ns/shacl#> .
2121
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
2222
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
2323

24-
five-safes-crate:RootDataEntityRequiredProperties
24+
25+
# Person who is the agent of a CreateAction SHOULD have an affiliation
26+
five-safes-crate:PersonAgentHasAffiliation
2527
a sh:NodeShape ;
26-
sh:name "Five Safes Crate Root Data Entity REQUIRED properties" ;
27-
sh:description "The Root Data Entity MUST have a `sourceOrganisation`" ;
28-
sh:targetClass ro-crate:RootDataEntity ;
28+
sh:name "Agent of CreateAction" ;
29+
sh:description "The agent of a CreateAction entity" ;
30+
sh:target [
31+
a sh:SPARQLTarget ;
32+
sh:prefixes ro-crate:sparqlPrefixes ;
33+
sh:select """
34+
SELECT DISTINCT ?this WHERE {
35+
?action a schema:CreateAction ;
36+
schema:agent ?this .
37+
}
38+
"""
39+
] ;
40+
41+
# The agent of a CreateAction entity SHOULD have an affiliation
2942
sh:property [
3043
a sh:PropertyShape ;
31-
sh:name "Root Data Entity: `sourceOrganization` property" ;
32-
sh:description """Check if the Root Data Entity includes a `sourceOrganization` (as specified by schema.org).""" ;
33-
sh:path schema_org:sourceOrganization;
44+
sh:name "Presence of affiliations" ;
45+
sh:path schema:affiliation ;
3446
sh:minCount 1 ;
35-
sh:nodeKind sh:IRI;
36-
sh:message """The Root Data Entity MUST have a `sourceOrganization` property (as specified by schema.org).
37-
SHOULD link to a Contextual Entity in the RO-Crate Metadata File with a name.""" ;
38-
] .
47+
sh:severity sh:Warning ;
48+
sh:message "The agent of a CreateAction entity SHOULD have an affiliation" ;
49+
] .
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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_createaction_does_not_have_agent():
29+
"""
30+
Test a Five Safes Crate where CreateAction does not have the property agent.
31+
(We remove the property agent from the CreateAction entity)
32+
"""
33+
sparql = (
34+
SPARQL_PREFIXES
35+
+ """
36+
DELETE {
37+
?action schema:agent ?agent .
38+
}
39+
WHERE {
40+
?action schema:agent ?agent ;
41+
a schema:CreateAction .
42+
?agent a schema:Person .
43+
}
44+
"""
45+
)
46+
47+
do_entity_test(
48+
rocrate_path=ValidROC().five_safes_crate_request,
49+
requirement_severity=Severity.REQUIRED,
50+
expected_validation_result=False,
51+
expected_triggered_requirements=["CreateAction"],
52+
expected_triggered_issues=[
53+
"CreateAction MUST have at least one schema:agent that is a contextual entity."
54+
],
55+
profile_identifier="five-safes-crate",
56+
rocrate_entity_mod_sparql=sparql,
57+
)
58+
59+
60+
def test_createaction_agent_is_not_person():
61+
"""
62+
Test a Five Safes Crate where CreateAction has an agent that is not of type schema:Person.
63+
(We replace the CreateAction's agent with an entity that has no type).
64+
"""
65+
sparql = (
66+
SPARQL_PREFIXES
67+
+ """
68+
DELETE {
69+
?action schema:agent ?agent .
70+
}
71+
INSERT {
72+
?action schema:agent <#not-a-person> .
73+
}
74+
WHERE {
75+
?action schema:agent ?agent ;
76+
a schema:CreateAction .
77+
?agent a schema:Person .
78+
}
79+
"""
80+
)
81+
82+
do_entity_test(
83+
rocrate_path=ValidROC().five_safes_crate_request,
84+
requirement_severity=Severity.REQUIRED,
85+
expected_validation_result=False,
86+
expected_triggered_requirements=["CreateAction"],
87+
expected_triggered_issues=[
88+
"Each CreateAction agent MUST be typed as schema:Person."
89+
],
90+
profile_identifier="five-safes-crate",
91+
rocrate_entity_mod_sparql=sparql,
92+
)
93+
94+
95+
def test_agent_affiliation_not_organization():
96+
"""
97+
Test a Five Safes Crate where the agent of CreateAction has an affiliation
98+
that is not of type schema:Organization.
99+
(We rereplace the agent's affiliation with an entity that has no type)
100+
"""
101+
sparql = (
102+
SPARQL_PREFIXES
103+
+ """
104+
DELETE {
105+
?agent schema:affiliation ?aff .
106+
}
107+
INSERT {
108+
?agent schema:affiliation <#not-an-organization> .
109+
}
110+
WHERE {
111+
?agent schema:affiliation ?aff ;
112+
a schema:Person .
113+
?aff a schema:Organization .
114+
?action a schema:CreateAction ;
115+
schema:agent ?agent .
116+
}
117+
"""
118+
)
119+
120+
do_entity_test(
121+
rocrate_path=ValidROC().five_safes_crate_request,
122+
requirement_severity=Severity.REQUIRED,
123+
expected_validation_result=False,
124+
expected_triggered_requirements=["CreateAction"],
125+
expected_triggered_issues=[
126+
"The affiliation of a CreateAction's agent MUST be a contextual entity with type schema:Organization."
127+
],
128+
profile_identifier="five-safes-crate",
129+
rocrate_entity_mod_sparql=sparql,
130+
)
131+
132+
133+
# ----- SHOULD warning tests
134+
135+
136+
def test_5src_agent_does_not_have_affiliation():
137+
"""
138+
Test a Five Safes Crate where the agent of CreteAction does not have an affiliatin.
139+
(We remove the triplet ?agent schema:affiliation ?org from the RO-Crate graph)
140+
"""
141+
sparql = (
142+
SPARQL_PREFIXES
143+
+ """
144+
DELETE {
145+
?agent schema:affiliation ?org .
146+
}
147+
WHERE {
148+
?agent schema:affiliation ?org ;
149+
a schema:Person .
150+
?action a schema:CreateAction ;
151+
schema:agent ?agent .
152+
}
153+
"""
154+
)
155+
156+
do_entity_test(
157+
rocrate_path=ValidROC().five_safes_crate_request,
158+
requirement_severity=Severity.RECOMMENDED,
159+
expected_validation_result=False,
160+
expected_triggered_requirements=["Agent of CreateAction"],
161+
expected_triggered_issues=[
162+
"The agent of a CreateAction entity SHOULD have an affiliation"
163+
],
164+
profile_identifier="five-safes-crate",
165+
rocrate_entity_mod_sparql=sparql,
166+
)

tests/integration/profiles/five-safes-crate/test_5src_funding.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)