Skip to content

Commit 0665cb6

Browse files
Merge pull request #10 from eScienceLab/ro-crate-1.3
RO Crate 1.3
2 parents 5cc0ebf + 87f16cc commit 0665cb6

9 files changed

Lines changed: 316 additions & 123 deletions

‎README.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ ROCrate crate;
9696

9797
### Create an Entity
9898

99-
To create an entity, instantiate the `Entity` class. You can must provide a type,
100-
or list of types.
99+
To create an entity, instantiate the `Entity` class. You must provide a type,
100+
or can provide a list of types.
101101

102102
```cpp
103103
// Single type
@@ -139,16 +139,28 @@ Entity alice({"Person"});
139139
crate.addEntity("#alice", alice);
140140
```
141141
142+
### Add additional context to an RO-Crate
143+
144+
To add additional context to an RO-Crate, use the `addContext` method. The first
145+
argument is the id of the context to add. The second is the context link itself
146+
which must be non-empty.
147+
148+
```cpp
149+
ROCrate crate;
150+
151+
crate.addContext("txc", "https://purl.archive.org/language-data-commons/terms#");
152+
```
153+
142154
### Write out an RO-Crate
143155

144156
To write out an RO-Crate, use the `writeOut` method. The argument is the path to
145157
write the RO-Crate to. This will write out the `ro-crate-metadata.json` file.
146158

147159
```cpp
148-
crate.writeOut("./routput/");o
160+
crate.writeOut("./routput/ro-crate-metadata.json");
149161
```
150162

151-
## Explaination
163+
## Explanation
152164

153165
These notes are mostly aimed at developers who want to understand the design of
154166
this library, but may be of interest to users as well.

‎include/ro-crate.hpp‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ namespace rocrate {
177177
*/
178178
Entity& getEntity(const std::string& id);
179179

180+
/**
181+
* Adds a context entry to the RO-Crate's root metadata entity.
182+
*
183+
* @param key The context key to add.
184+
* @param value The context value associated with the key.
185+
* @throw std::invalid_argument if the key or value is empty.
186+
*/
187+
void addContext(const std::string& key, const std::string& value);
188+
180189
/**
181190
* Serializes the RO-Crate to a JSON file at the specified path.
182191
*
@@ -200,6 +209,7 @@ namespace rocrate {
200209
) const;
201210

202211
EntityRegister entities_;
212+
std::map<std::string, std::string> context_;
203213
};
204214

205215
inline ROCrate::ROCrate() {
@@ -210,7 +220,7 @@ namespace rocrate {
210220
Entity rootEntity({"CreativeWork"});
211221
rootEntity.set(
212222
"conformsTo",
213-
"https://w3id.org/ro/crate/1.1",
223+
"https://w3id.org/ro/crate/1.3",
214224
ValueType::Reference
215225
);
216226
addEntity("ro-crate-metadata.json", rootEntity);
@@ -249,12 +259,35 @@ namespace rocrate {
249259
return it->second;
250260
}
251261

252-
inline void ROCrate::writeOut(const std::string& path) {
262+
inline void ROCrate::addContext(const std::string& key, const std::string& value) {
263+
// Validate the context
264+
if (key.empty()) {
265+
throw std::invalid_argument("Context key cannot be empty.");
266+
}
267+
if (value.empty()) {
268+
throw std::invalid_argument("Context value cannot be empty.");
269+
}
270+
271+
// Add the context entry to the RO-Crate's root metadata entity
272+
context_[key] = value;
273+
}
274+
275+
inline void ROCrate::writeOut(const std::string& path) {
276+
// Create the JSON representation of the RO-Crate
253277
nlohmann::json outCrate = {
254-
{"@context", "https://w3id.org/ro/crate/1.1/context"},
278+
{"@context", "https://w3id.org/ro/crate/1.3/context"},
255279
{"@graph", nlohmann::json::array()}
256280
};
257281

282+
// Add the context entries to the JSON representation
283+
if (!context_.empty()) {
284+
outCrate["@context"] = nlohmann::json::array();
285+
outCrate["@context"].push_back("https://w3id.org/ro/crate/1.3/context");
286+
for (const auto& [key, value] : context_) {
287+
outCrate["@context"].push_back({{key, value}});
288+
}
289+
}
290+
258291
// Iterate over the entities, conver to json and append to the graph
259292
for (const auto& [id, entity] : entities_) {
260293
outCrate["@graph"].push_back(serializeEntity(id, entity));

‎tests/fixtures/example-with-file-author-location.json‎

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{ "@context": "https://w3id.org/ro/crate/1.3/context",
2+
"@graph": [
3+
{
4+
"@type": "CreativeWork",
5+
"@id": "ro-crate-metadata.json",
6+
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.3"},
7+
"about": {"@id": "./"}
8+
},
9+
{
10+
"@id": "./",
11+
"@type": "Dataset",
12+
"name": "Example Dataset",
13+
"datePublished": "2016-02-01",
14+
"author": {"@id": "https://orcid.org/0000-0003-4953-0830"},
15+
"license": "CC-BY",
16+
"hasPart": [
17+
{
18+
"@id": "cp7glop.ai"
19+
},
20+
{
21+
"@id": "lots_of_little_files/"
22+
}
23+
]
24+
},
25+
{
26+
"@id": "cp7glop.ai",
27+
"@type": "File",
28+
"name": "Diagram showing trend to increase",
29+
"contentSize": "383766",
30+
"description": "Illustrator file for Glop Pot",
31+
"encodingFormat": "application/pdf"
32+
},
33+
{
34+
"@id": "lots_of_little_files/",
35+
"@type": "Dataset",
36+
"name": "Too many files",
37+
"description": "This directory contains many small files -- the name of the file is a date in YYYY-MM-DD.csv, each file contains daily temperature readings, sampled hourly for the Glop Pot cave."
38+
},
39+
{
40+
"@id": "https://orcid.org/0000-0003-4953-0830",
41+
"@type": "Person",
42+
"name": "Michael Lake"
43+
}
44+
]
45+
}

‎tests/fixtures/example-with-web-resources.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{ "@context": "https://w3id.org/ro/crate/1.1/context",
1+
{ "@context": "https://w3id.org/ro/crate/1.3/context",
22
"@graph": [
33
{
44
"@type": "CreativeWork",
55
"@id": "ro-crate-metadata.json",
6-
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
6+
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.3"},
77
"about": {"@id": "./"}
88
},
99
{
@@ -16,7 +16,7 @@
1616
{
1717
"@id": "https://zenodo.org/record/3541888/files/ro-crate-1.0.0.pdf"
1818
}
19-
]
19+
]
2020
},
2121
{
2222
"@id": "survey-responses-2019.csv",
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
{ "@context": "https://w3id.org/ro/crate/1.1/context",
1+
{ "@context": "https://w3id.org/ro/crate/1.3/context",
22
"@graph": [
33

44
{
5-
"@type": "CreativeWork",
65
"@id": "ro-crate-metadata.json",
7-
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
8-
"about": {"@id": "./"}
6+
"@type": "CreativeWork",
7+
"about": {"@id": "./"},
8+
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.3"}
99
},
1010
{
1111
"@id": "./",
12-
"identifier": "https://doi.org/10.4225/59/59672c09f4a4b",
1312
"@type": "Dataset",
13+
"identifier": {"@id": "https://doi.org/10.4225/59/59672c09f4a4b"},
14+
"cite-as": "https://doi.org/10.4225/59/59672c09f4a4b",
1415
"datePublished": "2017",
1516
"name": "Data files associated with the manuscript:Effects of facilitated family case conferencing for ...",
1617
"description": "Palliative care planning for nursing home residents with advanced dementia ...",
17-
"license": {"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/"}
18+
"license": {"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/"},
19+
"creditText": "Agar, M. et al., 2017. Data supporting \"Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial\". https://doi.org/10.4225/59/59672c09f4a4b"
20+
},
21+
{
22+
"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/",
23+
"@type": "CreativeWork",
24+
"description": "This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Australia License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/au/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.",
25+
"identifier": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/",
26+
"name": "Attribution-NonCommercial-ShareAlike 3.0 Australia (CC BY-NC-SA 3.0 AU)"
1827
},
1928
{
20-
"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/",
21-
"@type": "CreativeWork",
22-
"description": "This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Australia License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/au/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.",
23-
"identifier": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/",
24-
"name": "Attribution-NonCommercial-ShareAlike 3.0 Australia (CC BY-NC-SA 3.0 AU)"
25-
}
29+
"@id": "https://doi.org/10.4225/59/59672c09f4a4b",
30+
"@type": "PropertyValue",
31+
"propertyID": "https://registry.identifiers.org/registry/doi",
32+
"value": "doi:10.4225/59/59672c09f4a4b",
33+
"url": "https://doi.org/10.4225/59/59672c09f4a4b"
34+
}
2635
]
2736
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{ "@context": [
2+
"https://w3id.org/ro/crate/1.3/context",
3+
{"txc": "https://purl.archive.org/language-data-commons/terms#"}
4+
],
5+
"@graph": [
6+
{
7+
"@id": "ro-crate-metadata.json",
8+
"@type": "CreativeWork",
9+
"description": "RO-Crate Metadata File Descriptor (this file)",
10+
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.3"},
11+
"about": {"@id": "./"}
12+
},
13+
{
14+
"@id": "./",
15+
"@type": "Dataset",
16+
"description": "This is an experimental language data ontology based on OLAC terms for use in the ATAP and LDaCA projects",
17+
"name": "Language Data Ontology",
18+
"mentions": [
19+
{"@id": "txc:Annotation"},
20+
{"@id": "txc:CollectionEvent"}
21+
]
22+
},
23+
{
24+
"@id": "txc:Annotation",
25+
"@type": "rdfs:Class",
26+
"name": "Annotation",
27+
"sameAs": "http://www.language-archives.org/REC/type-20020628.html#annotation",
28+
"rdfs:comment": "The resource includes information which annotates some other linguistic record.",
29+
"rdfs:label": "Annotation",
30+
"rdfs:subClassOf": {
31+
"@id": "schema:CreativeWork"
32+
}
33+
},
34+
{
35+
"@id": "txc:CollectionEvent",
36+
"@type": "rdfs:Class",
37+
"name": "CollectionEvent",
38+
"rdfs:comment": "A description of an event at which one or more PrimaryTexts were captured, e.g. as video or audio",
39+
"rdfs:label": "CollectionEvent",
40+
"rdfs:subClassOf": [
41+
{
42+
"@id": "schema:Event"
43+
},
44+
{
45+
"@id": "schema:CreateAction"
46+
}
47+
]
48+
}
49+
]
50+
}

0 commit comments

Comments
 (0)