Skip to content

Commit b190409

Browse files
authored
Merge pull request #49 from eScienceLab/15-metadata-file
Implement Metadata File expectations
2 parents b10983f + 8c61b6a commit b190409

File tree

12 files changed

+742
-27
lines changed

12 files changed

+742
-27
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
import re
16+
17+
import rocrate_validator.log as logging
18+
from rocrate_validator.models import Severity, ValidationContext
19+
from rocrate_validator.requirements.python import PyFunctionCheck, check, requirement
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
@requirement(name="RO-Crate context version")
26+
class FileDescriptorContextVersion(PyFunctionCheck):
27+
"""The RO-Crate metadata file MUST include the RO-Crate context version 1.2
28+
(or later minor version) in `@context`"""
29+
30+
@check(name="RO-Crate context version", severity=Severity.REQUIRED)
31+
def test_existence(self, context: ValidationContext) -> bool:
32+
"""
33+
The RO-Crate metadata file MUST include the RO-Crate context version 1.2
34+
(or later minor version) in `@context`
35+
"""
36+
try:
37+
json_dict = context.ro_crate.metadata.as_dict()
38+
context_value = json_dict["@context"]
39+
pattern = re.compile(
40+
r"https://w3id\.org/ro/crate/1\.[2-9](-DRAFT)?/context"
41+
)
42+
passed = True
43+
if isinstance(context_value, list):
44+
if not any(
45+
pattern.match(item)
46+
for item in context_value
47+
if isinstance(item, str)
48+
):
49+
passed = False
50+
else:
51+
if not pattern.match(context_value):
52+
passed = False
53+
if not passed:
54+
context.result.add_issue(
55+
"The RO-Crate metadata file MUST include the RO-Crate context "
56+
"version 1.2 (or later minor version) in `@context`",
57+
self,
58+
)
59+
return passed
60+
61+
except Exception as e:
62+
if logger.isEnabledFor(logging.DEBUG):
63+
logger.exception(e)
64+
return True
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2025 eScience Lab, The University of Manchester
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-crate: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> .
16+
@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> .
17+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
18+
@prefix schema: <http://schema.org/> .
19+
@prefix purl: <http://purl.org/dc/terms/> .
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+
@prefix dct: <http://purl.org/dc/terms/> .
24+
25+
five-safes-crate:MetadataFileDescriptorProperties a sh:NodeShape ;
26+
sh:name "RO-Crate conforms to 1.2 or later minor version" ;
27+
sh:description """The RO-Crate metadata file descriptor MUST have a `conformsTo` property with RO-Crate specification version 1.2 or later minor version""";
28+
sh:targetClass ro-crate:ROCrateMetadataFileDescriptor ;
29+
sh:property [
30+
a sh:PropertyShape ;
31+
sh:name "RO-Crate conforms to 1.2 or later minor version" ;
32+
sh:description "The RO-Crate metadata file descriptor MUST have a `conformsTo` property with RO-Crate specification version 1.2 or later minor version" ;
33+
sh:minCount 1 ;
34+
sh:nodeKind sh:IRI ;
35+
sh:path dct:conformsTo ;
36+
sh:pattern "https://w3id\\.org/ro/crate/(1\\.[2-9](-DRAFT)?)" ;
37+
sh:severity sh:Violation;
38+
sh:message "The RO-Crate metadata file descriptor MUST have a `conformsTo` property with RO-Crate specification version 1.2 or later minor version" ;
39+
] .
40+
41+
ro-crate:conformsToROCrateSpec sh:deactivated true .

rocrate_validator/profiles/ro-crate/must/1_file-descriptor_metadata.ttl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ ro-crate:ROCrateMetadataFileDescriptorRecommendedProperties a sh:NodeShape ;
8989
sh:class schema_org:Dataset ;
9090
sh:message "The RO-Crate metadata file descriptor MUST have an `about` property referencing the Root Data Entity" ;
9191
] ;
92-
sh:property [
93-
a sh:PropertyShape ;
94-
sh:name "Metadata File Descriptor entity: `conformsTo` property" ;
95-
sh:description """Check if the RO-Crate Metadata File Descriptor has a `conformsTo` property which points to the RO-Crate specification version""" ;
96-
sh:minCount 1 ;
97-
sh:nodeKind sh:IRI ;
98-
sh:path dct:conformsTo ;
99-
sh:hasValue <https://w3id.org/ro/crate/1.1> ;
100-
sh:message "The RO-Crate metadata file descriptor MUST have a `conformsTo` property with the RO-Crate specification version" ;
101-
] .
92+
sh:property ro-crate:conformsToROCrateSpec .
93+
94+
ro-crate:conformsToROCrateSpec sh:name "Metadata File Descriptor entity: `conformsTo` property" ;
95+
sh:description """Check if the RO-Crate Metadata File Descriptor has a `conformsTo` property which points to the RO-Crate specification version""" ;
96+
sh:minCount 1 ;
97+
sh:nodeKind sh:IRI ;
98+
sh:path dct:conformsTo ;
99+
sh:hasValue <https://w3id.org/ro/crate/1.1> ;
100+
sh:message "The RO-Crate metadata file descriptor MUST have a `conformsTo` property with the RO-Crate specification version" .
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
{
2+
"@context": ["https://w3id.org/ro/crate/1.1/context", "http://schema.org", {"test": "http://schema.org/test"}],
3+
"@graph": [
4+
{
5+
"@type": "CreativeWork",
6+
"@id": "ro-crate-metadata.json",
7+
"about": {
8+
"@id": "./"
9+
},
10+
"conformsTo": {
11+
"@id": "https://w3id.org/ro/crate/1.2"
12+
}
13+
},
14+
{
15+
"@id": "./",
16+
"@type": "Dataset",
17+
"name": "5-Safe RO-Crate Request",
18+
"description": "example 5-Safe RO-Crate request metadata for testing",
19+
"license": "Apache-2.0",
20+
"datePublished": "2025-09-20T14:38:00+00:00",
21+
"conformsTo": {
22+
"@id": "https://w3id.org/5s-crate/0.4"
23+
},
24+
"hasPart": [
25+
{
26+
"@id": "https://workflowhub.eu/workflows/289?version=1"
27+
},
28+
{
29+
"@id": "input1.txt"
30+
}
31+
],
32+
"mainEntity": {
33+
"@id": "https://workflowhub.eu/workflows/289?version=1"
34+
},
35+
"mentions": {
36+
"@id": "#query-37252371-c937-43bd-a0a7-3680b48c0538"
37+
},
38+
"sourceOrganization": {
39+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70"
40+
}
41+
},
42+
{
43+
"@id": "https://w3id.org/5s-crate/0.4",
44+
"@type": "Profile",
45+
"name": "Five Safes RO-Crate profile"
46+
},
47+
{
48+
"@id": "https://workflowhub.eu/workflows/289?version=1",
49+
"@type": "Dataset",
50+
"name": "CWL Protein MD Setup tutorial with mutations",
51+
"conformsTo": {
52+
"@id": "https://w3id.org/workflowhub/workflow-ro-crate/1.0"
53+
},
54+
"distribution": {
55+
"@id": "https://workflowhub.eu/workflows/289/ro_crate?version=1"
56+
}
57+
},
58+
{
59+
"@id": "https://workflowhub.eu/workflows/289/ro_crate?version=1",
60+
"@type": "DataDownload",
61+
"conformsTo": {
62+
"@id": "https://w3id.org/ro/crate"
63+
},
64+
"encodingFormat": "application/zip"
65+
},
66+
{
67+
"@id": "#query-37252371-c937-43bd-a0a7-3680b48c0538",
68+
"@type": "CreateAction",
69+
"actionStatus": "http://schema.org/PotentialActionStatus",
70+
"agent": {
71+
"@id": "https://orcid.org/0000-0001-9842-9718"
72+
},
73+
"instrument": {
74+
"@id": "https://workflowhub.eu/workflows/289?version=1"
75+
},
76+
"name": "Execute query 12389 on workflow ",
77+
"object": [
78+
{
79+
"@id": "input1.txt"
80+
},
81+
{
82+
"@id": "#enableFastMode"
83+
}
84+
]
85+
},
86+
{
87+
"@id": "https://orcid.org/0000-0001-9842-9718",
88+
"@type": "Person",
89+
"name": "Stian Soiland-Reyes",
90+
"affiliation": {
91+
"@id": "https://ror.org/027m9bs27"
92+
},
93+
"memberOf": [
94+
{
95+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70"
96+
}
97+
]
98+
},
99+
{
100+
"@id": "https://ror.org/027m9bs27",
101+
"@type": "Organization",
102+
"name": "The University of Manchester"
103+
},
104+
{
105+
"@id": "https://ror.org/01ee9ar58",
106+
"@type": "Organization",
107+
"name": "University of Nottingham"
108+
},
109+
{
110+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70",
111+
"@type": "Project",
112+
"name": "Investigation of cancer (TRE72 project 81)",
113+
"identifier": [
114+
{
115+
"@id": "_:localid:tre72:project81"
116+
}
117+
],
118+
"funding": {
119+
"@id": "https://gtr.ukri.org/projects?ref=10038961"
120+
},
121+
"member": [
122+
{
123+
"@id": "https://ror.org/027m9bs27"
124+
},
125+
{
126+
"@id": "https://ror.org/01ee9ar58"
127+
}
128+
]
129+
},
130+
{
131+
"@id": "_:localid:tre72:project81",
132+
"@type": "PropertyValue",
133+
"name": "tre72",
134+
"value": "project81"
135+
},
136+
{
137+
"@id": "https://gtr.ukri.org/projects?ref=10038961",
138+
"@type": "Grant",
139+
"name": "EOSC4Cancer"
140+
},
141+
{
142+
"@id": "input1.txt",
143+
"@type": "File",
144+
"name": "input1",
145+
"exampleOfWork": {
146+
"@id": "#sequence"
147+
}
148+
},
149+
{
150+
"@id": "#enableFastMode",
151+
"@type": "PropertyValue",
152+
"name": "--fast-mode",
153+
"value": "True",
154+
"exampleOfWork": {
155+
"@id": "#fast"
156+
}
157+
},
158+
{
159+
"@id": "#sequence",
160+
"@type": "FormalParameter",
161+
"name": "input-sequence"
162+
},
163+
{
164+
"@id": "#fast",
165+
"@type": "FormalParameter",
166+
"name": "fast-mode"
167+
}
168+
]
169+
}

0 commit comments

Comments
 (0)