Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
This is part of datacrate, a node.js library for working with
DataCrates. Copyright (C) 2018 University of Technology Sydney
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const CONTEXT = { };
/* Convert metadata from a redbox data publication and
its data record to a JSON-LD datacrate catalogue */
// TODO; add contentSize, encodingFormat and fileFormat
// from siegfried to the dataLocations array
// org is the organisation as an array with keys @id
// and name:
// {
// "@id": "https://www.uts.edu.au/"
// "name": "University of Technology Sydney",
// }
function datapub2catalog(datapub, org) {
const catalog = {
'@context': CONTEXT,
'@graph': []
};
const organisation = {
'@id': org['@id'],
'@type': 'Organization',
'identifier': org['@id'],
'name': org['name']
};
// assuming that all creators are affiliated to this one organisation
const people = creators(datapub, organisation);
const files = attachments(datapub);
const graph = [
dataset(datapub, files, organisation),
organisation,
about(datapub),
spatial(datapub),
temporal(datapub),
creators,
licence(datapub),
citation(datapub),
files,
related(datapub)
];
catalog['@graph'] = graph.filter((e) => e);
return catalog;
}
function dataset(datapub, files) {
}
// files(datapub)
// crosswalk dataLocations to an array of File items.
// The dataLocations are expected to have contentSize,
// encodingFormat and fileFormat already set
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
if( !datapub['dataLocations'] ) {
return [];
}
const files = datapub['dataLocations'].map((dl) => {
if( dl['type'] == 'attachment' ) {
return {
'@id': dl['name'],
'name': dl['name'],
'@type': 'File',
'contentSize': dl['contentSize'],
'encodingFormat': dl['encodingFormat'],
'fileFormat': dl['fileFormat']
}
} else {
// todo: URLs and physical locations
return undefined;
}
});
return files.filter((x) => x);
}
// creators(datapub)
//
// returns the array of Person items from the creators
// field of the data publication
// TODO: affiliations
function creators(datapub, organisation) {
if( !datapub['creators'] ) {
throw Error("A DataCrate has to have at least one creator");
}
const creators = datapub['creators'].map((p) => {
const id = p['orcid'] || p['email'] || p['text_full_name'];
return {
'@id': id,
'identifier': id,
'name': p['text_full_name'],
'familyName': p['family_name'],
'givenName': p['given_name'],
'email': p['email'],
'affiliation': { '@id': organisation['@id'] }
}
})
return creators.filter((x) => x)
}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
return undefined;
}
function about(datapub) {
return undefined;
}
function spatial(datapub) {
return undefined;
}
function temporal(datapub) {
return undefined;
}
function licence(datapub) {
return undefined;
}
function citation(datapub) {
return undefined;
}
function related(datapub) {
return undefined;
}
module.exports = {
'datapub2catalog': datapub2catalog
};