Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> .
@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix shp: <https://w3id.org/shp#> .


# Root Dataset SHOULD declare conformsTo Five Safes profile
five-safes-crate:RootDatasetConformsToFiveSafes
a sh:NodeShape ;
sh:name "RootDataEntity" ;
sh:targetClass ro-crate:RootDataEntity ;

sh:property [
a sh:PropertyShape ;
sh:name "conformsTo Five Safes profile" ;
sh:path dct:conformsTo ;
sh:hasValue <https://w3id.org/5s-crate/0.4> ;
sh:severity sh:Warning ;
sh:message "Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4" ;
] .

five-safes-crate:RootDatasetDatePublishedWhenPublished
a sh:NodeShape ;
sh:name "datePublished present on published crates" ;
sh:description "If the root dataset is published (has schema:publisher), it SHOULD have schema:datePublished." ;
sh:targetClass ro-crate:RootDataEntity ;
sh:severity sh:Warning ;
sh:message "A crate SHOULD have a publishedDate if and only if it has a publisher." ;
sh:xone (
# datePublished SHOULD be present if and only if the publisher is specified:
[ sh:not [ sh:property [
sh:path schema:publisher ;
sh:minCount 1 ;
]]]
[ sh:property [
sh:path schema:datePublished ;
sh:minCount 1 ;
]]
) .
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more appropriate to use the sh:xone constraint here? If there should only be a publication date if there's a publisher then I think we don't ever want to have both of these checks to be true.
See https://www.w3.org/TR/shacl/#XoneConstraintComponent

This would then require an extra test, in which we add a schema:datePublished object without any schema:publisher object.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the new commit


five-safes-crate:RootDatasetLicenseWhenPublished
a sh:NodeShape ;
sh:name "License present on published crates" ;
sh:description "If the root dataset is published (has schema:publisher), it SHOULD declare a license." ;
sh:targetClass ro-crate:RootDataEntity ;
sh:severity sh:Warning ;
sh:message "Profile Conformance: Published crates SHOULD include a license." ;
sh:or (
# license not required if no publisher:
[ sh:not [ sh:property [
sh:path schema:publisher ;
sh:minCount 1 ;
]]]
# license required if publisher present:
[ sh:property [
sh:path schema:license ;
sh:minCount 1 ;
]]
) .
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Copyright (c) 2024-2025 CRS4
# Copyright (c) 2025-2026 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.

import logging

from rocrate_validator.models import Severity
from tests.ro_crates import ValidROC
from tests.shared import do_entity_test, SPARQL_PREFIXES

# set up logging
logger = logging.getLogger(__name__)


# ----- MUST fails tests


# ----- SHOULD fails tests


def test_5src_root_data_entity_missing_conformsto_property():
"""
Test a Five Safes Crate where the RootDataEntity does not have the conformsTo property.
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?rootdataentity dct:conformsTo ?profile .
}
WHERE {
?metadatafile a schema:CreativeWork ;
schema:about ?rootdataentity .
?rootdataentity dct:conformsTo ?profile .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_request,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["RootDataEntity"],
expected_triggered_issues=[
"Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4"
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


def test_5src_root_data_entity_conforms_to_wrong_profile():
"""
Test a Five Safes Crate where the RootDataEntity does not conform to the expected profile.
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?rootdataentity dct:conformsTo ?profile .
}
INSERT {
?rootdataentity dct:conformsTo "This is not the IRI to the 5sc profile"
}
WHERE {
?metadatafile a schema:CreativeWork ;
schema:about ?rootdataentity .
?rootdataentity dct:conformsTo ?profile .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_request,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["RootDataEntity"],
expected_triggered_issues=[
"Root Dataset SHOULD include `conformsTo` https://w3id.org/5s-crate/0.4"
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


def test_5src_root_data_entity_has_publisher_but_not_date_published():
"""
Test a Five Safes Crate where the RootDataEntity has published but not date published.
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?rootdataentity schema:datePublished ?datePublished .
}
WHERE {
?metadatafile a schema:CreativeWork ;
schema:about ?rootdataentity .
?rootdataentity schema:publisher ?publisher ;
schema:datePublished ?datePublished .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_result,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["datePublished present on published crates"],
expected_triggered_issues=[
"A crate SHOULD have a publishedDate if and only if it has a publisher."
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


def test_5src_root_data_entity_has_date_published_but_not_publisher():
"""
Test a Five Safes Crate where the RootDataEntity has published but not date published.
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?rootdataentity schema:publisher ?publisher .
}
WHERE {
?metadatafile a schema:CreativeWork ;
schema:about ?rootdataentity .
?rootdataentity schema:publisher ?publisher ;
schema:datePublished ?datePublished .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_result,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["datePublished present on published crates"],
expected_triggered_issues=[
"A crate SHOULD have a publishedDate if and only if it has a publisher."
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


def test_5src_root_data_entity_has_publisher_but_not_license():
"""
Test a Five Safes Crate where the RootDataEntity has publisher but not license.
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?rootdataentity schema:license ?license .
}
WHERE {
?metadatafile a schema:CreativeWork ;
schema:about ?rootdataentity .
?rootdataentity schema:publisher ?publisher ;
schema:license ?license .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_result,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["License present on published crates"],
expected_triggered_issues=[
"Profile Conformance: Published crates SHOULD include a license."
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


# ----- MAY fails tests
Loading