diff --git a/rocrate_validator/profiles/five-safes-crate/should/12_check_phase.ttl b/rocrate_validator/profiles/five-safes-crate/12_check_phase.ttl similarity index 65% rename from rocrate_validator/profiles/five-safes-crate/should/12_check_phase.ttl rename to rocrate_validator/profiles/five-safes-crate/12_check_phase.ttl index faf74459..d352d170 100644 --- a/rocrate_validator/profiles/five-safes-crate/should/12_check_phase.ttl +++ b/rocrate_validator/profiles/five-safes-crate/12_check_phase.ttl @@ -23,11 +23,87 @@ @prefix xsd: . +#=== MUST shapes ===# + +five-safes-crate:CheckValueObjectHasDescriptiveNameAndIsAssessAction + a sh:NodeShape ; + sh:name "CheckValue" ; + sh:description "" ; + + sh:target [ + a sh:SPARQLTarget ; + sh:select """ + PREFIX schema: + PREFIX shp: + + SELECT ?this + WHERE { + ?this schema:additionalType shp:CheckValue . + } + """ ; + ] ; + + sh:property [ + sh:path rdf:type ; + sh:minCount 1 ; + sh:hasValue schema:AssessAction; + sh:severity sh:Violation ; + sh:message "CheckValue MUST be a `AssessAction`." ; + ] ; + + sh:property [ + sh:a sh:PropertyShape ; + sh:name "name" ; + sh:description "CheckValue MUST have a human readable name string." ; + sh:path schema:name ; + sh:datatype xsd:string ; + sh:severity sh:Violation ; + sh:message "CheckValue MUST have a human readable name string." ; + ] . + + +five-safes-crate:CheckValueActionStatusMustHaveAllowedValues + a sh:NodeShape ; + sh:name "CheckValue" ; + sh:description "" ; + + sh:target [ + a sh:SPARQLTarget ; + sh:select """ + PREFIX schema: + PREFIX shp: + + SELECT ?this + WHERE { + ?this schema:additionalType shp:CheckValue ; + schema:actionStatus ?status . + } + """ ; + ] ; + + sh:property [ + a sh:PropertyShape ; + sh:name "ActionStatus" ; + sh:path schema:actionStatus ; + sh:in ( + "http://schema.org/PotentialActionStatus" + "http://schema.org/ActiveActionStatus" + "http://schema.org/CompletedActionStatus" + "http://schema.org/FailedActionStatus" + ) ; + sh:severity sh:Violation ; + sh:message "`CheckValue` --> `actionStatus` MUST have one of the allowed values." ; + ] . + + +#=== SHOULD shapes ===# + five-safes-crate:RootDataEntityShouldMentionCheckValueObject a sh:NodeShape ; sh:name "RootDataEntity" ; sh:targetClass ro-crate:RootDataEntity ; sh:description "" ; + sh:severity sh:Warning ; sh:sparql [ a sh:SPARQLConstraint ; @@ -44,7 +120,6 @@ five-safes-crate:RootDataEntityShouldMentionCheckValueObject } } """ ; - sh:severity sh:Warning ; sh:message "RootDataEntity SHOULD mention a check value object." ; ] . @@ -188,3 +263,38 @@ five-safes-crate:CheckValueShouldHaveActionStatus sh:severity sh:Warning ; sh:message "CheckValue SHOULD have actionStatus property." ; ] . + + +#=== MAY shapes ===# + +five-safes-crate:CheckValueMayHaveStartTime + a sh:NodeShape ; + sh:name "CheckValue" ; + sh:description "" ; + sh:target [ + a sh:SPARQLTarget ; + sh:select """ + PREFIX schema: + PREFIX shp: + SELECT ?this + WHERE { + ?this schema:additionalType shp:CheckValue ; + schema:actionStatus ?status . + FILTER(?status IN ( + "http://schema.org/CompletedActionStatus", + "http://schema.org/FailedActionStatus", + "http://schema.org/ActiveActionStatus" + )) + } + """ ; + ] ; + + sh:property [ + a sh:PropertyShape ; + sh:name "StartTime" ; + sh:path schema:startTime ; + sh:minCount 1 ; + sh:maxCount 1 ; + sh:severity sh:Info ; + sh:message "`CheckValue` MAY have the `startTime` property." ; + ] . diff --git a/rocrate_validator/profiles/five-safes-crate/may/12_check_phase.ttl b/rocrate_validator/profiles/five-safes-crate/may/12_check_phase.ttl deleted file mode 100644 index 0e741f6c..00000000 --- a/rocrate_validator/profiles/five-safes-crate/may/12_check_phase.ttl +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) 2025 eScience Lab, The University of Manchester -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -@prefix ro: <./> . -@prefix ro-crate: . -@prefix five-safes-crate: . -@prefix rdf: . -@prefix schema: . -@prefix purl: . -@prefix sh: . -@prefix validator: . -@prefix xsd: . - - -five-safes-crate:CheckValueMayHaveStartTime - a sh:NodeShape ; - sh:name "CheckValue" ; - sh:description "" ; - sh:target [ - a sh:SPARQLTarget ; - sh:select """ - PREFIX schema: - PREFIX shp: - SELECT ?this - WHERE { - ?this schema:additionalType shp:CheckValue ; - schema:actionStatus ?status . - FILTER(?status IN ( - "http://schema.org/CompletedActionStatus", - "http://schema.org/FailedActionStatus", - "http://schema.org/ActiveActionStatus" - )) - } - """ ; - ] ; - - sh:property [ - a sh:PropertyShape ; - sh:name "StartTime" ; - sh:path schema:startTime ; - sh:minCount 1 ; - sh:maxCount 1 ; - sh:severity sh:Info ; - sh:message "`CheckValue` MAY have the `startTime` property." ; - ] . diff --git a/rocrate_validator/profiles/five-safes-crate/must/12_check_phase.ttl b/rocrate_validator/profiles/five-safes-crate/must/12_check_phase.ttl deleted file mode 100644 index caecb165..00000000 --- a/rocrate_validator/profiles/five-safes-crate/must/12_check_phase.ttl +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (c) 2025 eScience Lab, The University of Manchester -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -@prefix ro: <./> . -@prefix ro-crate: . -@prefix five-safes-crate: . -@prefix rdf: . -@prefix schema: . -@prefix purl: . -@prefix sh: . -@prefix validator: . -@prefix xsd: . - - -five-safes-crate:CheckValueObjectHasDescriptiveNameAndIsAssessAction - a sh:NodeShape ; - sh:name "CheckValue" ; - sh:description "" ; - - sh:target [ - a sh:SPARQLTarget ; - sh:select """ - PREFIX schema: - PREFIX shp: - - SELECT ?this - WHERE { - ?this schema:additionalType shp:CheckValue . - } - """ ; - ] ; - - sh:property [ - sh:path rdf:type ; - sh:minCount 1 ; - sh:hasValue schema:AssessAction; - sh:severity sh:Violation ; - sh:message "CheckValue MUST be a `AssessAction`." ; - ] ; - - sh:property [ - sh:a sh:PropertyShape ; - sh:name "name" ; - sh:description "CheckValue MUST have a human readable name string." ; - sh:path schema:name ; - sh:datatype xsd:string ; - sh:severity sh:Violation ; - sh:message "CheckValue MUST have a human readable name string." ; - ] . - -five-safes-crate:CheckValueActionStatusMustHaveAllowedValues - a sh:NodeShape ; - sh:name "CheckValue" ; - sh:description "" ; - - sh:target [ - a sh:SPARQLTarget ; - sh:select """ - PREFIX schema: - PREFIX shp: - - SELECT ?this - WHERE { - ?this schema:additionalType shp:CheckValue ; - schema:actionStatus ?status . - } - """ ; - ] ; - - sh:property [ - a sh:PropertyShape ; - sh:name "ActionStatus" ; - sh:path schema:actionStatus ; - sh:in ( - "http://schema.org/PotentialActionStatus" - "http://schema.org/ActiveActionStatus" - "http://schema.org/CompletedActionStatus" - "http://schema.org/FailedActionStatus" - ) ; - sh:severity sh:Violation ; - sh:message "`CheckValue` --> `actionStatus` MUST have one of the allowed values." ; - ] . diff --git a/tests/shared.py b/tests/shared.py index c6d76af0..80756ea5 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -97,6 +97,16 @@ def replace_uri_in_graph(graph, old_uri_str, new_uri_str): return g +def _uses_https_schema(graph: rdflib.Graph) -> bool: + for s, p, o in graph.triples((None, None, None)): + for term in (s, p, o): + if isinstance(term, rdflib.URIRef) and str(term).startswith( + "https://schema.org/" + ): + return True + return False + + def do_entity_test( rocrate_path: Union[Path, str], requirement_severity: models.Severity, @@ -152,10 +162,17 @@ def do_entity_test( if rocrate_entity_mod_sparql is not None: rocrate_graph = load_graph_and_preserve_relative_ids(rocrate) + if _uses_https_schema(rocrate_graph): + rocrate_entity_mod_sparql = rocrate_entity_mod_sparql.replace( + "http://schema.org/", + "https://schema.org/", + ) + rocrate_graph.update(rocrate_entity_mod_sparql) # save the updated RO-Crate metadata - context = "https://w3id.org/ro/crate/1.1/context" + # preserve the original context to avoid forcing a downgrade + context = rocrate.get("@context", "https://w3id.org/ro/crate/1.2/context") rocrate_graph.serialize( Path(temp_rocrate_path, "ro-crate-metadata.json"), format="json-ld",