Skip to content

Commit 6c1d0ab

Browse files
authored
Merge pull request #96 from eScienceLab/79-flatten-12_check_phasettl-files
Merged `12_check_phase.tll` files.
2 parents d17575d + 784cb0f commit 6c1d0ab

4 files changed

Lines changed: 128 additions & 151 deletions

File tree

rocrate_validator/profiles/five-safes-crate/should/12_check_phase.ttl renamed to rocrate_validator/profiles/five-safes-crate/12_check_phase.ttl

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,86 @@
2323
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
2424

2525

26+
#=== MUST shapes ===#
27+
28+
five-safes-crate:CheckValueObjectHasDescriptiveNameAndIsAssessAction
29+
a sh:NodeShape ;
30+
sh:name "CheckValue" ;
31+
sh:description "" ;
32+
33+
sh:target [
34+
a sh:SPARQLTarget ;
35+
sh:select """
36+
PREFIX schema: <http://schema.org/>
37+
PREFIX shp: <https://w3id.org/shp#>
38+
39+
SELECT ?this
40+
WHERE {
41+
?this schema:additionalType shp:CheckValue .
42+
}
43+
""" ;
44+
] ;
45+
46+
sh:property [
47+
sh:path rdf:type ;
48+
sh:minCount 1 ;
49+
sh:hasValue schema:AssessAction;
50+
sh:severity sh:Violation ;
51+
sh:message "CheckValue MUST be a `AssessAction`." ;
52+
] ;
53+
54+
sh:property [
55+
sh:a sh:PropertyShape ;
56+
sh:name "name" ;
57+
sh:description "CheckValue MUST have a human readable name string." ;
58+
sh:path schema:name ;
59+
sh:datatype xsd:string ;
60+
sh:severity sh:Violation ;
61+
sh:message "CheckValue MUST have a human readable name string." ;
62+
] .
63+
64+
five-safes-crate:CheckValueActionStatusMustHaveAllowedValues
65+
a sh:NodeShape ;
66+
sh:name "CheckValue" ;
67+
sh:description "" ;
68+
69+
sh:target [
70+
a sh:SPARQLTarget ;
71+
sh:select """
72+
PREFIX schema: <http://schema.org/>
73+
PREFIX shp: <https://w3id.org/shp#>
74+
75+
SELECT ?this
76+
WHERE {
77+
?this schema:additionalType shp:CheckValue ;
78+
schema:actionStatus ?status .
79+
}
80+
""" ;
81+
] ;
82+
83+
sh:property [
84+
a sh:PropertyShape ;
85+
sh:name "ActionStatus" ;
86+
sh:path schema:actionStatus ;
87+
sh:in (
88+
"http://schema.org/PotentialActionStatus"
89+
"http://schema.org/ActiveActionStatus"
90+
"http://schema.org/CompletedActionStatus"
91+
"http://schema.org/FailedActionStatus"
92+
) ;
93+
sh:severity sh:Violation ;
94+
sh:message "`CheckValue` --> `actionStatus` MUST have one of the allowed values." ;
95+
] .
96+
97+
98+
#=== SHOULD shapes ===#
99+
26100
five-safes-crate:RootDataEntityShouldMentionCheckValueObject
27101
a sh:NodeShape ;
28102
sh:name "RootDataEntity" ;
29103
sh:targetClass ro-crate:RootDataEntity ;
30104
sh:description "" ;
105+
sh:severity sh:Warning ;
31106

32107
sh:sparql [
33108
a sh:SPARQLConstraint ;
@@ -44,7 +119,6 @@ five-safes-crate:RootDataEntityShouldMentionCheckValueObject
44119
}
45120
}
46121
""" ;
47-
sh:severity sh:Warning ;
48122
sh:message "RootDataEntity SHOULD mention a check value object." ;
49123
] .
50124

@@ -188,3 +262,38 @@ five-safes-crate:CheckValueShouldHaveActionStatus
188262
sh:severity sh:Warning ;
189263
sh:message "CheckValue SHOULD have actionStatus property." ;
190264
] .
265+
266+
267+
#=== MAY shapes ===#
268+
269+
five-safes-crate:CheckValueMayHaveStartTime
270+
a sh:NodeShape ;
271+
sh:name "CheckValue" ;
272+
sh:description "" ;
273+
sh:target [
274+
a sh:SPARQLTarget ;
275+
sh:select """
276+
PREFIX schema: <http://schema.org/>
277+
PREFIX shp: <https://w3id.org/shp#>
278+
SELECT ?this
279+
WHERE {
280+
?this schema:additionalType shp:CheckValue ;
281+
schema:actionStatus ?status .
282+
FILTER(?status IN (
283+
"http://schema.org/CompletedActionStatus",
284+
"http://schema.org/FailedActionStatus",
285+
"http://schema.org/ActiveActionStatus"
286+
))
287+
}
288+
""" ;
289+
] ;
290+
291+
sh:property [
292+
a sh:PropertyShape ;
293+
sh:name "StartTime" ;
294+
sh:path schema:startTime ;
295+
sh:minCount 1 ;
296+
sh:maxCount 1 ;
297+
sh:severity sh:Info ;
298+
sh:message "`CheckValue` MAY have the `startTime` property." ;
299+
] .

rocrate_validator/profiles/five-safes-crate/may/12_check_phase.ttl

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

rocrate_validator/profiles/five-safes-crate/must/12_check_phase.ttl

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

tests/shared.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def replace_uri_in_graph(graph, old_uri_str, new_uri_str):
9797
return g
9898

9999

100+
def _uses_https_schema(graph: rdflib.Graph) -> bool:
101+
for s, p, o in graph.triples((None, None, None)):
102+
for term in (s, p, o):
103+
if isinstance(term, rdflib.URIRef) and str(term).startswith(
104+
"https://schema.org/"
105+
):
106+
return True
107+
return False
108+
109+
100110
def do_entity_test(
101111
rocrate_path: Union[Path, str],
102112
requirement_severity: models.Severity,
@@ -152,10 +162,17 @@ def do_entity_test(
152162
if rocrate_entity_mod_sparql is not None:
153163
rocrate_graph = load_graph_and_preserve_relative_ids(rocrate)
154164

165+
if _uses_https_schema(rocrate_graph):
166+
rocrate_entity_mod_sparql = rocrate_entity_mod_sparql.replace(
167+
"http://schema.org/",
168+
"https://schema.org/",
169+
)
170+
155171
rocrate_graph.update(rocrate_entity_mod_sparql)
156172

157173
# save the updated RO-Crate metadata
158-
context = "https://w3id.org/ro/crate/1.1/context"
174+
# preserve the original context to avoid forcing a downgrade
175+
context = rocrate.get("@context", "https://w3id.org/ro/crate/1.2/context")
159176
rocrate_graph.serialize(
160177
Path(temp_rocrate_path, "ro-crate-metadata.json"),
161178
format="json-ld",

0 commit comments

Comments
 (0)