forked from crs4/rocrate-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Add SHACL warnings for five-safes-profile conformance, datePublished, and licence #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EttoreM
wants to merge
5
commits into
develop
Choose a base branch
from
106-add-shacl-warnings-for-five-safes-profile-conformance-conformsto-datepublished-licence
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+272
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43289a5
Added CHACL code and corresponding tests about RootDataEntity conform…
EttoreM 36f495a
Added SHACL code and corresponding tests about RootDataEntity having …
EttoreM 95ecd30
Added SHACL code and corresponding tests for licencing information in…
EttoreM 6399536
(1) Changed to , (2) Replaced with , and (3) added a test to accoun…
EttoreM 38243b3
(1) Changed 'sh:targetNode: ro' to 'sh:targetClass: ro-crate:RootData…
EttoreM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
rocrate_validator/profiles/five-safes-crate/should/5_profile_conformance.ttl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ; | ||
| ]] | ||
| ) . | ||
|
|
||
| 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 ; | ||
| ]] | ||
| ) . | ||
193 changes: 193 additions & 0 deletions
193
tests/integration/profiles/five-safes-crate/test_5src_5_profile_conformance.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:xoneconstraint 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:datePublishedobject without anyschema:publisherobject.There was a problem hiding this comment.
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