|
| 1 | +# Copyright (c) 2024-2025 CRS4 |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +@prefix ro: <./> . |
| 16 | +@prefix ro-crate: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> . |
| 17 | +@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> . |
| 18 | +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
| 19 | +@prefix schema: <http://schema.org/> . |
| 20 | +@prefix sh: <http://www.w3.org/ns/shacl#> . |
| 21 | +@prefix validator: <https://github.com/crs4/rocrate-validator/> . |
| 22 | +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . |
| 23 | + |
| 24 | + |
| 25 | +# Any CreateAction entity must have one (and only one) agent |
| 26 | +five-safes-crate:CreateActionHasAgent |
| 27 | + a sh:NodeShape ; |
| 28 | + sh:description "CreateAction MUST have an agent property." ; |
| 29 | + sh:targetClass schema:CreateAction ; |
| 30 | + sh:property [ |
| 31 | + sh:path schema:agent ; |
| 32 | + sh:minCount 1 ; |
| 33 | + sh:maxCount 1 ; |
| 34 | + sh:nodeKind sh:IRI ; |
| 35 | + sh:message "CreateAction MUST have an agent property." ; |
| 36 | + ] . |
| 37 | + |
| 38 | + |
| 39 | +# The agent of a CreateAction must be a Person |
| 40 | +five-safes-crate:CreateActionAgentIsPerson |
| 41 | + a sh:NodeShape ; |
| 42 | + sh:description "The agent of a CreateAction entity MUST be a Person." ; |
| 43 | + sh:target [ |
| 44 | + a sh:SPARQLTarget ; |
| 45 | + sh:prefixes ro-crate:sparqlPrefixes ; |
| 46 | + sh:select """ |
| 47 | + SELECT DISTINCT ?this WHERE { |
| 48 | + ?action a schema:CreateAction ; |
| 49 | + schema:agent ?this . |
| 50 | + } |
| 51 | + """ |
| 52 | + ] ; |
| 53 | + sh:class schema:Person ; |
| 54 | + sh:severity sh:Violation ; |
| 55 | + sh:message "The agent of a CreateAction entity MUST be a Person." . |
| 56 | + |
| 57 | + |
| 58 | +# The affiliation (if any) of a CreateAction's agent MUST be an Organization |
| 59 | +five-safes-crate:AgentAffiliationIsOrganization |
| 60 | + a sh:NodeShape ; |
| 61 | + sh:description "The affiliation (if any) of a CreateAction's agent MUST be an Organization" ; |
| 62 | + sh:severity sh:Violation ; |
| 63 | + sh:target [ |
| 64 | + a sh:SPARQLTarget ; |
| 65 | + sh:prefixes ro-crate:sparqlPrefixes ; |
| 66 | + sh:select """ |
| 67 | + SELECT DISTINCT ?this WHERE { |
| 68 | + ?action a schema:CreateAction ; |
| 69 | + schema:agent ?this . |
| 70 | + ?this a schema:Person . |
| 71 | + ?this schema:affiliation ?aff . |
| 72 | + } |
| 73 | + """ |
| 74 | + ] ; |
| 75 | + sh:property [ |
| 76 | + sh:path schema:affiliation ; |
| 77 | + sh:class schema:Organization ; |
| 78 | + sh:message "The affiliation (if any) of a CreateAction's agent MUST be an Organization" ; |
| 79 | + ] . |
| 80 | + |
| 81 | + |
| 82 | +# All schema:Organization instances: @id MUST be a PID permalink (ROR / ISNI / Wikidata) |
| 83 | +five-safes-crate:OrganizationIdIsPIDPermalink |
| 84 | + a sh:NodeShape ; |
| 85 | + sh:name "Organizations value restriction" ; |
| 86 | + sh:description "An Organization `@id` must be a PID permalink (ROR, ISNI, or Wikidata)." ; |
| 87 | + |
| 88 | + # Target the CLASS node; values are all subjects with rdf:type schema:Organization |
| 89 | + sh:targetNode schema:Organization ; |
| 90 | + |
| 91 | + sh:property [ |
| 92 | + a sh:PropertyShape ; |
| 93 | + sh:name "Organization URI value" ; |
| 94 | + sh:description "Check that the Organization entity URI (@id) is a PID permalink." ; |
| 95 | + |
| 96 | + # From the class node, walk inverse rdf:type to all instances |
| 97 | + sh:path [ sh:inversePath rdf:type ] ; |
| 98 | + |
| 99 | + # Require at least one instance (prevents empty graphs from 'passing') |
| 100 | + sh:minCount 1 ; |
| 101 | + |
| 102 | + # Regex over the string form of the instance IRI |
| 103 | + sh:pattern "^(?:https://(?:ror\\.org/0[0-9a-hjkmnp-tv-z]{6}[0-9]{2}|isni\\.org/isni/\\d{15}[\\dX]|(?:www\\.)?wikidata\\.org/entity/Q\\d+))$" ; |
| 104 | + sh:flags "i" ; |
| 105 | + |
| 106 | + sh:message "Organization @id MUST be a PID permalink (ROR/ISNI/Wikidata)." ; |
| 107 | + ] . |
0 commit comments