forked from crs4/rocrate-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Outputs Rulset #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6ccabb
First commit containing only some rules coded in SHACL
EttoreM 9574808
Added pytests for rules implemented so far.
EttoreM 1cc26d4
Addressed Eli's comments on PR.
EttoreM 613c925
Removed unnecessary SHACL constraint ( --> must reference fully def…
EttoreM 57dba21
Addressed Eli's comments.
EttoreM 606f9cb
Merge branch 'develop' into 35-implement-outputs-rulset
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
89 changes: 89 additions & 0 deletions
89
rocrate_validator/profiles/five-safes-crate/should/10_outputs.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,89 @@ | ||
| # 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 sh: <http://www.w3.org/ns/shacl#> . | ||
| @prefix validator: <https://github.com/crs4/rocrate-validator/> . | ||
| @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
|
||
|
|
||
|
|
||
| five-safes-crate:CreateActionHasResultIfActionCompleted | ||
| a sh:NodeShape ; | ||
| sh:name "CreateAction" ; | ||
| sh:description "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ; | ||
|
|
||
| sh:target [ | ||
| a sh:SPARQLTarget ; | ||
| sh:name "Result" ; | ||
| sh:description "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ; | ||
| sh:prefixes ro-crate:sparqlPrefixes ; | ||
| sh:select """ | ||
| SELECT ?this WHERE { | ||
| ?this a schema:CreateAction ; | ||
| schema:actionStatus "http://schema.org/CompletedActionStatus" . | ||
| } | ||
| """ | ||
| ] ; | ||
|
|
||
|
|
||
| sh:property [ | ||
| a sh:PropertyShape ; | ||
| sh:name "Result" ; | ||
| sh:path schema:result ; | ||
| sh:minCount 1 ; | ||
| sh:severity sh:Warning ; | ||
| sh:message "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ; | ||
| ] . | ||
|
|
||
|
|
||
| five-safes-crate:CreateActionResultOutputsHaveAllowedTypes | ||
| a sh:NodeShape ; | ||
| sh:name "Output" ; | ||
| sh:description "Result SHOULD have a `@type` among an allowed set of values." ; | ||
| sh:target [ | ||
| a sh:SPARQLTarget ; | ||
| sh:select """ | ||
| PREFIX schema: <http://schema.org/> | ||
| SELECT ?this | ||
| WHERE { | ||
| ?createAction a schema:CreateAction . | ||
| ?createAction schema:result ?this . | ||
| } | ||
| """ ; | ||
| ] ; | ||
| sh:message "Result SHOULD have a `@type` among an allowed set of values." ; | ||
| sh:severity sh:Warning ; | ||
| sh:or ( | ||
| [ | ||
| sh:class schema:MediaObject; | ||
| ] | ||
| [ | ||
| sh:class schema:Dataset; | ||
| ] | ||
| [ | ||
| sh:class schema:Collection; | ||
| ] | ||
| [ | ||
| sh:class schema:DigitalDocument; | ||
| ] | ||
| [ | ||
| sh:class schema:PropertyValue; | ||
| ] | ||
| ) . | ||
|
|
93 changes: 93 additions & 0 deletions
93
tests/integration/profiles/five-safes-crate/test_5src_10_outputs.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,93 @@ | ||
| # Copyright (c) 2024-2025 CRS4 | ||
| # | ||
| # 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__) | ||
|
|
||
|
|
||
| # ----- SHOULD fails tests | ||
|
|
||
|
|
||
| def test_completed_createaction_does_not_have_result(): | ||
| """ | ||
| Test a Five Safes Crate where `CreateAction` has `CompletedActionStatus` but | ||
| does not have the property `result`. | ||
| (We remove `result` from `CreateAction` if this has `CompletedActionStatus`) | ||
| """ | ||
| sparql = ( | ||
| SPARQL_PREFIXES | ||
| + """ | ||
| DELETE { | ||
| ?action schema:result ?o . | ||
| } | ||
| WHERE { | ||
| ?action a schema:CreateAction ; | ||
| schema:actionStatus "http://schema.org/CompletedActionStatus" ; | ||
| schema:result ?o | ||
| } | ||
| """ | ||
| ) | ||
|
|
||
| do_entity_test( | ||
| rocrate_path=ValidROC().five_safes_crate_result, | ||
| requirement_severity=Severity.RECOMMENDED, | ||
| expected_validation_result=False, | ||
| expected_triggered_requirements=["CreateAction"], | ||
| expected_triggered_issues=[ | ||
| "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." | ||
| ], | ||
| profile_identifier="five-safes-crate", | ||
| rocrate_entity_mod_sparql=sparql, | ||
| ) | ||
|
|
||
|
|
||
| def test_result_output_does_not_have_allowed_type(): | ||
| """ | ||
| Test a Five Safes Crate where the result output does not have a type that | ||
| is among those allowed. | ||
| (We remove the output entity and replace it with one that is of a wrong type)""" | ||
| sparql = ( | ||
| SPARQL_PREFIXES | ||
| + """ | ||
| DELETE { | ||
| ?result a ?oldType . | ||
| } | ||
| INSERT { | ||
| ?result a schema:Person . | ||
| } | ||
| WHERE { | ||
| ?action a schema:CreateAction ; | ||
| schema:result ?result . | ||
| ?result a ?oldType . | ||
| } | ||
| """ | ||
| ) | ||
|
|
||
| do_entity_test( | ||
| rocrate_path=ValidROC().five_safes_crate_result, | ||
| requirement_severity=Severity.RECOMMENDED, | ||
| expected_validation_result=False, | ||
| expected_triggered_requirements=["Output"], | ||
| expected_triggered_issues=[ | ||
| "Result SHOULD have a `@type` among an allowed set of values." | ||
| ], | ||
| profile_identifier="five-safes-crate", | ||
| rocrate_entity_mod_sparql=sparql, | ||
| ) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.