@larsgw/formica 0.8.5 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
4
  if (k2 === undefined) k2 = k;
16
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -53,55 +42,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
53
42
  step((generator = generator.apply(thisArg, _arguments || [])).next());
54
43
  });
55
44
  };
56
- var __generator = (this && this.__generator) || function (thisArg, body) {
57
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
- function verb(n) { return function (v) { return step([n, v]); }; }
60
- function step(op) {
61
- if (f) throw new TypeError("Generator is already executing.");
62
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
- if (y = 0, t) op = [op[0] & 2, t.value];
65
- switch (op[0]) {
66
- case 0: case 1: t = op; break;
67
- case 4: _.label++; return { value: op[1], done: false };
68
- case 5: _.label++; y = op[1]; op = [0]; continue;
69
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
- default:
71
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
- if (t[2]) _.ops.pop();
76
- _.trys.pop(); continue;
77
- }
78
- op = body.call(thisArg, _);
79
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
- }
82
- };
83
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
84
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
85
- if (ar || !(i in from)) {
86
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
87
- ar[i] = from[i];
88
- }
89
- }
90
- return to.concat(ar || Array.prototype.slice.call(from));
91
- };
92
45
  Object.defineProperty(exports, "__esModule", { value: true });
93
- var fs_1 = require("fs");
94
- var path = __importStar(require("path"));
95
- var util = __importStar(require("util"));
96
- var jsonld = __importStar(require("jsonld"));
97
- var N3 = __importStar(require("n3"));
98
- var index_1 = require("../index");
99
- var resource_1 = require("../resources/resource");
100
- var csv_1 = require("../csv");
101
- var SHEETS = ['catalog', 'authors', 'places', 'publishers', 'taxa'];
102
- var PREFIX = 'https://purl.org/identification-resources/';
103
- var HANDLE_PREFIX = 'https://hdl.handle.net/';
104
- var SCOPES = {
46
+ const fs_1 = require("fs");
47
+ const path = __importStar(require("path"));
48
+ const util = __importStar(require("util"));
49
+ const jsonld = __importStar(require("jsonld"));
50
+ const N3 = __importStar(require("n3"));
51
+ const index_1 = require("../index");
52
+ const resource_1 = require("../resources/resource");
53
+ const csv_1 = require("../csv");
54
+ const SHEETS = ['catalog', 'authors', 'places', 'publishers', 'taxa'];
55
+ const PREFIX = 'https://purl.org/identification-resources/';
56
+ const HANDLE_PREFIX = 'https://hdl.handle.net/';
57
+ const SCOPES = {
105
58
  // animal life stage
106
59
  'adults': ['dwciri:lifeStage', 'http://rs.gbif.org/vocabulary/gbif/life_stage/adult'],
107
60
  'pupae': ['dwciri:lifeStage', 'http://rs.gbif.org/vocabulary/gbif/life_stage/pupa'],
@@ -144,7 +97,7 @@ var SCOPES = {
144
97
  'bones (upper jaws)': ['ac:subjectPart', 'http://rs.tdwg.org/acpart/values/p0028'],
145
98
  'bones (lower jaws)': ['ac:subjectPart', 'http://rs.tdwg.org/acpart/values/p0029'],
146
99
  };
147
- var PREFIXES = {
100
+ const PREFIXES = {
148
101
  'ac': 'http://rs.tdwg.org/ac/terms/',
149
102
  'bibo': 'http://purl.org/ontology/bibo/',
150
103
  'dcterms': 'http://purl.org/dc/terms/',
@@ -156,7 +109,7 @@ var PREFIXES = {
156
109
  'schema': 'https://schema.org/',
157
110
  'xsd': 'http://www.w3.org/2001/XMLSchema#',
158
111
  };
159
- var DWC_FIELDS = {
112
+ const DWC_FIELDS = {
160
113
  scientificName: 'dwc:scientificName',
161
114
  scientificNameAuthorship: 'dwc:scientificNameAuthorship',
162
115
  genericName: 'dwc:genericName',
@@ -168,30 +121,29 @@ var DWC_FIELDS = {
168
121
  taxonomicStatus: 'dwc:taxonomicStatus',
169
122
  verbatimIdentification: 'dwc:verbatimIdentification',
170
123
  };
171
- var GBIF_RANKS = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species', 'subspecies'];
172
- var GBIF_VOCAB_RANKS = ['domain', 'kingdom', 'subkingdom', 'superphylum', 'phylum', 'subphylum', 'superclass', 'class', 'subclass', 'supercohort', 'cohort', 'subcohort', 'superorder', 'order', 'suborder', 'infraorder', 'superfamily', 'family', 'subfamily', 'tribe', 'subtribe', 'genus', 'subgenus', 'section', 'subsection', 'series', 'subseries', 'speciesAggregate', 'species', 'subspecificAggregate', 'subspecies', 'variety', 'subvariety', 'form', 'subform', 'cultivarGroup', 'cultivar', 'strain'];
173
- var STATUSES = {
124
+ const GBIF_RANKS = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species', 'subspecies'];
125
+ const GBIF_VOCAB_RANKS = ['domain', 'kingdom', 'subkingdom', 'superphylum', 'phylum', 'subphylum', 'superclass', 'class', 'subclass', 'supercohort', 'cohort', 'subcohort', 'superorder', 'order', 'suborder', 'infraorder', 'superfamily', 'family', 'subfamily', 'tribe', 'subtribe', 'genus', 'subgenus', 'section', 'subsection', 'series', 'subseries', 'speciesAggregate', 'species', 'subspecificAggregate', 'subspecies', 'variety', 'subvariety', 'form', 'subform', 'cultivarGroup', 'cultivar', 'strain'];
126
+ const STATUSES = {
174
127
  'accepted': 'http://rs.gbif.org/vocabulary/gbif/taxonomicStatus/accepted',
175
128
  'heterotypic synonym': 'http://rs.gbif.org/vocabulary/gbif/taxonomicStatus/heterotypicSynonym',
176
129
  'synonym': 'http://rs.gbif.org/vocabulary/gbif/taxonomicStatus/synonym',
177
130
  };
178
131
  function getCoveringTaxon(taxa) {
179
132
  if (taxa.length === 1 && !taxa[0].has('gbif')) {
180
- return "".concat(PREFIX, "taxon/").concat(taxa[0].get('id'));
133
+ return `${PREFIX}taxon/${taxa[0].get('id')}`;
181
134
  }
182
135
  function getAncestors(taxon) {
183
136
  var _a;
184
- var parents = ((_a = taxon.get('parent_taxa')) !== null && _a !== void 0 ? _a : []).slice(0);
137
+ const [...parents] = ((_a = taxon.get('parent_taxa')) !== null && _a !== void 0 ? _a : []);
185
138
  if (taxon.has('gbif')) {
186
139
  parents.push(taxon.get('gbif'));
187
140
  }
188
141
  return parents;
189
142
  }
190
- var ancestors = getAncestors(taxa[0]);
191
- for (var _i = 0, _a = taxa.slice(1); _i < _a.length; _i++) {
192
- var taxon = _a[_i];
193
- var otherAncestors = getAncestors(taxon);
194
- for (var i = 0; i < ancestors.length; i++) {
143
+ const ancestors = getAncestors(taxa[0]);
144
+ for (const taxon of taxa.slice(1)) {
145
+ const otherAncestors = getAncestors(taxon);
146
+ for (let i = 0; i < ancestors.length; i++) {
195
147
  if (ancestors[i] !== otherAncestors[i]) {
196
148
  ancestors.splice(i);
197
149
  }
@@ -200,40 +152,36 @@ function getCoveringTaxon(taxa) {
200
152
  return ancestors.length ? makeGbifUri(ancestors[ancestors.length - 1])['@id'] : null;
201
153
  }
202
154
  function mapEntities(names, entities) {
203
- var result = [];
204
- var _loop_1 = function (name_1) {
205
- var entity = entities.find(function (entity) {
206
- var values = entity.get('name');
207
- return Array.isArray(values) ? values.includes(name_1) : values === name_1;
155
+ const result = [];
156
+ for (const name of names) {
157
+ const entity = entities.find(entity => {
158
+ const values = entity.get('name');
159
+ return Array.isArray(values) ? values.includes(name) : values === name;
208
160
  });
209
161
  if (!entity) {
210
- console.error('Unmapped entity:', name_1);
211
- return "continue";
162
+ console.error('Unmapped entity:', name);
163
+ continue;
212
164
  }
213
165
  result.push(entity);
214
- };
215
- for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
216
- var name_1 = names_1[_i];
217
- _loop_1(name_1);
218
166
  }
219
167
  return result;
220
168
  }
221
169
  function makeWikidataUri(qid) {
222
- return { '@id': "http://www.wikidata.org/entity/".concat(qid) };
170
+ return { '@id': `http://www.wikidata.org/entity/${qid}` };
223
171
  }
224
172
  function makeGbifUri(id) {
225
- return { '@id': "https://gbif.org/species/".concat(id) };
173
+ return { '@id': `https://gbif.org/species/${id}` };
226
174
  }
227
175
  function makeWorkUri(id) {
228
- return { '@id': "".concat(PREFIX, "catalog/").concat(id) };
176
+ return { '@id': `${PREFIX}catalog/${id}` };
229
177
  }
230
178
  function makeScientificNameUri(id) {
231
- var resource = id.split(':').slice(0, -1).join(':');
232
- return { '@id': "".concat(PREFIX, "resource/").concat(resource, "#").concat(id) };
179
+ const resource = id.split(':').slice(0, -1).join(':');
180
+ return { '@id': `${PREFIX}resource/${resource}#${id}` };
233
181
  }
234
182
  function makeTaxonRankUri(rank) {
235
183
  if (GBIF_VOCAB_RANKS.includes(rank)) {
236
- return { '@id': "http://rs.gbif.org/vocabulary/gbif/rank/".concat(rank) };
184
+ return { '@id': `http://rs.gbif.org/vocabulary/gbif/rank/${rank}` };
237
185
  }
238
186
  else {
239
187
  return rank;
@@ -243,8 +191,8 @@ function makeTaxonomicStatusUri(status) {
243
191
  return { '@id': STATUSES[status] };
244
192
  }
245
193
  function makeLinkedDataForAuthor(author) {
246
- var node = {
247
- '@id': "".concat(PREFIX, "author/").concat(author.get('id')),
194
+ const node = {
195
+ '@id': `${PREFIX}author/${author.get('id')}`,
248
196
  '@type': 'foaf:Person',
249
197
  'foaf:name': author.get('display_name')
250
198
  };
@@ -254,8 +202,8 @@ function makeLinkedDataForAuthor(author) {
254
202
  return node;
255
203
  }
256
204
  function makeLinkedDataForPlace(place) {
257
- var node = {
258
- '@id': "".concat(PREFIX, "place/").concat(place.get('id')),
205
+ const node = {
206
+ '@id': `${PREFIX}place/${place.get('id')}`,
259
207
  '@type': 'dcterms:Location',
260
208
  'dcterms:title': place.get('display_name'),
261
209
  };
@@ -265,8 +213,8 @@ function makeLinkedDataForPlace(place) {
265
213
  return node;
266
214
  }
267
215
  function makeLinkedDataForPublisher(publisher) {
268
- var node = {
269
- '@id': "".concat(PREFIX, "publisher/").concat(publisher.get('id')),
216
+ const node = {
217
+ '@id': `${PREFIX}publisher/${publisher.get('id')}`,
270
218
  '@type': 'foaf:Organization',
271
219
  'foaf:name': publisher.get('display_name')
272
220
  };
@@ -276,15 +224,15 @@ function makeLinkedDataForPublisher(publisher) {
276
224
  return node;
277
225
  }
278
226
  function makeLinkedDataForTaxon(taxon) {
279
- var node = {
280
- '@id': "".concat(PREFIX, "taxon/").concat(taxon.get('id')),
227
+ const node = {
228
+ '@id': `${PREFIX}taxon/${taxon.get('id')}`,
281
229
  '@type': 'dwc:Taxon',
282
230
  'dwc:scientificName': taxon.get('name'),
283
231
  };
284
232
  if (taxon.has('rank')) {
285
233
  node['dwc:taxonRank'] = makeTaxonRankUri(taxon.get('rank'));
286
234
  }
287
- var ids = [];
235
+ const ids = [];
288
236
  if (taxon.has('qid')) {
289
237
  ids.push(makeWikidataUri(taxon.get('qid')));
290
238
  }
@@ -298,39 +246,37 @@ function makeLinkedDataForTaxon(taxon) {
298
246
  }
299
247
  function makeLinkedDataForTaxa(files) {
300
248
  var _a;
301
- var nodes = [];
302
- var gbifTaxa = {};
303
- for (var _i = 0, _b = files.taxa.entities; _i < _b.length; _i++) {
304
- var taxon = _b[_i];
305
- var node = makeLinkedDataForTaxon(taxon);
306
- var ancestors = (_a = taxon.get('ancestors_gbif')) !== null && _a !== void 0 ? _a : [];
249
+ const nodes = [];
250
+ const gbifTaxa = {};
251
+ for (const taxon of files.taxa.entities) {
252
+ const node = makeLinkedDataForTaxon(taxon);
253
+ const ancestors = (_a = taxon.get('ancestors_gbif')) !== null && _a !== void 0 ? _a : [];
307
254
  if (ancestors.length) {
308
255
  node['dwc:parentNameUsageID'] = makeGbifUri(ancestors[ancestors.length - 1]);
309
256
  }
310
257
  else if (taxon.get('id') !== 'T141') {
311
- node['dwc:parentNameUsageID'] = { '@id': "".concat(PREFIX, "taxon/T141") };
258
+ node['dwc:parentNameUsageID'] = { '@id': `${PREFIX}taxon/T141` };
312
259
  }
313
- for (var i = 0; i < ancestors.length; i++) {
314
- gbifTaxa[ancestors[i]] = __assign(__assign({}, makeGbifUri(ancestors[i])), { 'dwc:taxonRank': makeTaxonRankUri(GBIF_RANKS[i]), 'dwc:parentNameUsageID': i ? makeGbifUri(ancestors[i - 1]) : { '@id': "".concat(PREFIX, "taxon/T141") } });
260
+ for (let i = 0; i < ancestors.length; i++) {
261
+ gbifTaxa[ancestors[i]] = Object.assign(Object.assign({}, makeGbifUri(ancestors[i])), { 'dwc:taxonRank': makeTaxonRankUri(GBIF_RANKS[i]), 'dwc:parentNameUsageID': i ? makeGbifUri(ancestors[i - 1]) : { '@id': `${PREFIX}taxon/T141` } });
315
262
  }
316
263
  if (taxon.has('children_gbif')) {
317
- var children = taxon.get('children_gbif');
264
+ const children = taxon.get('children_gbif');
318
265
  node['@reverse'] = { 'dwc:parentNameUsageID': children.map(makeGbifUri) };
319
- var childRank = GBIF_RANKS[ancestors.length];
320
- for (var _c = 0, children_1 = children; _c < children_1.length; _c++) {
321
- var child = children_1[_c];
322
- gbifTaxa[child] = __assign(__assign({}, makeGbifUri(child)), { 'dwc:taxonRank': makeTaxonRankUri(childRank) });
266
+ const childRank = GBIF_RANKS[ancestors.length];
267
+ for (const child of children) {
268
+ gbifTaxa[child] = Object.assign(Object.assign({}, makeGbifUri(child)), { 'dwc:taxonRank': makeTaxonRankUri(childRank) });
323
269
  }
324
270
  }
325
271
  nodes.push(node);
326
272
  }
327
- nodes.push.apply(nodes, Object.values(gbifTaxa));
273
+ nodes.push(...Object.values(gbifTaxa));
328
274
  return nodes;
329
275
  }
330
276
  function makeLinkedDataForScientificName(name) {
331
- var node = __assign(__assign({}, makeScientificNameUri(name.scientificNameID)), { '@type': 'dwc:Taxon' });
332
- for (var field in DWC_FIELDS) {
333
- var value = name[field];
277
+ const node = Object.assign(Object.assign({}, makeScientificNameUri(name.scientificNameID)), { '@type': 'dwc:Taxon' });
278
+ for (const field in DWC_FIELDS) {
279
+ const value = name[field];
334
280
  if (value) {
335
281
  node[DWC_FIELDS[field]] = value;
336
282
  }
@@ -347,12 +293,12 @@ function makeLinkedDataForScientificName(name) {
347
293
  if (name.parentNameUsageID) {
348
294
  node['dwc:parentNameUsageID'] = makeScientificNameUri(name.parentNameUsageID);
349
295
  }
350
- var identifiers = [];
296
+ const identifiers = [];
351
297
  if (name.gbifTaxonID) {
352
298
  identifiers.push(makeGbifUri(name.gbifTaxonID));
353
299
  }
354
300
  if (name.colTaxonID) {
355
- identifiers.push({ '@id': "https://www.checklistbank.org/dataset/309120/taxon/".concat(name.colTaxonID) });
301
+ identifiers.push({ '@id': `https://www.checklistbank.org/dataset/309120/taxon/${name.colTaxonID}` });
356
302
  }
357
303
  if (identifiers.length) {
358
304
  node['dwc:taxonID'] = identifiers;
@@ -361,9 +307,9 @@ function makeLinkedDataForScientificName(name) {
361
307
  }
362
308
  function makeLinkedDataForResource(work, files, resourceId) {
363
309
  var _a, _b, _c, _d, _e, _f, _g, _h;
364
- var resource = new resource_1.WorkResource({});
310
+ const resource = new resource_1.WorkResource({});
365
311
  if (!resourceId) {
366
- resourceId = "".concat(work.get('id'), ":0");
312
+ resourceId = `${work.get('id')}:0`;
367
313
  }
368
314
  if (files.resources[resourceId] && files.resources[resourceId].metadata.catalog) {
369
315
  resource.fields = files.resources[resourceId].metadata.catalog;
@@ -371,8 +317,8 @@ function makeLinkedDataForResource(work, files, resourceId) {
371
317
  if (!resource.has('language')) {
372
318
  resource.fields.language = work.get('language');
373
319
  }
374
- var node = __assign(__assign({}, makeLinkedDataForWork(resource, files)), { '@id': "".concat(PREFIX, "resource/").concat(resourceId), '@type': 'bibo:DocumentPart' });
375
- var types = (_b = (_a = resource.get('key_type')) !== null && _a !== void 0 ? _a : work.get('key_type')) !== null && _b !== void 0 ? _b : [];
320
+ const node = Object.assign(Object.assign({}, makeLinkedDataForWork(resource, files)), { '@id': `${PREFIX}resource/${resourceId}`, '@type': 'bibo:DocumentPart' });
321
+ const types = (_b = (_a = resource.get('key_type')) !== null && _a !== void 0 ? _a : work.get('key_type')) !== null && _b !== void 0 ? _b : [];
376
322
  if (types.includes('matrix') || types.includes('algorithm')) {
377
323
  node['dcterms:type'] = { '@id': 'http://purl.org/dc/dcmitype/Software' };
378
324
  }
@@ -388,29 +334,27 @@ function makeLinkedDataForResource(work, files, resourceId) {
388
334
  if (types.includes('key') || types.includes('matrix')) {
389
335
  node['ac:subtype'] = { '@id': 'http://rs.tdwg.org/acsubtype/values/IdentificationKey' };
390
336
  }
391
- var taxonNames = (_c = resource.get('taxon')) !== null && _c !== void 0 ? _c : work.get('taxon');
337
+ const taxonNames = (_c = resource.get('taxon')) !== null && _c !== void 0 ? _c : work.get('taxon');
392
338
  if (taxonNames) {
393
- var taxa = mapEntities(taxonNames, files.taxa.entities);
394
- var coveringTaxon = taxa.length ? getCoveringTaxon(taxa) : null;
339
+ const taxa = mapEntities(taxonNames, files.taxa.entities);
340
+ const coveringTaxon = taxa.length ? getCoveringTaxon(taxa) : null;
395
341
  if (coveringTaxon !== null) {
396
342
  node['ac:taxonCoverage'] = { '@id': coveringTaxon };
397
343
  }
398
- node['dwc:taxonID'] = taxa.map(function (taxon) { return ({ '@id': "".concat(PREFIX, "taxon/").concat(taxon.get('id')) }); });
344
+ node['dwc:taxonID'] = taxa.map(taxon => ({ '@id': `${PREFIX}taxon/${taxon.get('id')}` }));
399
345
  }
400
- var scopes = (_d = resource.get('scope')) !== null && _d !== void 0 ? _d : work.get('scope');
346
+ const scopes = (_d = resource.get('scope')) !== null && _d !== void 0 ? _d : work.get('scope');
401
347
  if (scopes) {
402
- for (var _i = 0, _j = scopes; _i < _j.length; _i++) {
403
- var scope = _j[_i];
348
+ for (const scope of scopes) {
404
349
  if (!SCOPES[scope]) {
405
350
  console.error('Unmapped scope:', scope);
406
351
  continue;
407
352
  }
408
- var _k = SCOPES[scope], property = _k[0], values = _k.slice(1);
353
+ const [property, ...values] = SCOPES[scope];
409
354
  if (!Array.isArray(node[property])) {
410
355
  node[property] = [];
411
356
  }
412
- for (var _l = 0, values_1 = values; _l < values_1.length; _l++) {
413
- var value = values_1[_l];
357
+ for (const value of values) {
414
358
  if (value.startsWith('http')) {
415
359
  node[property].push({ '@id': value });
416
360
  }
@@ -420,34 +364,33 @@ function makeLinkedDataForResource(work, files, resourceId) {
420
364
  }
421
365
  }
422
366
  }
423
- var region = (_e = resource.get('region')) !== null && _e !== void 0 ? _e : work.get('region');
367
+ const region = (_e = resource.get('region')) !== null && _e !== void 0 ? _e : work.get('region');
424
368
  if (region) {
425
- var places = mapEntities(region, files.places.entities).map(function (place) { return ({ '@id': "".concat(PREFIX, "place/").concat(place.get('id')) }); });
369
+ const places = mapEntities(region, files.places.entities).map(place => ({ '@id': `${PREFIX}place/${place.get('id')}` }));
426
370
  node['dcterms:spatial'] = places;
427
371
  }
428
- var tags = [];
429
- var taxonScopes = (_f = resource.get('taxon_scope')) !== null && _f !== void 0 ? _f : work.get('taxon_scope');
372
+ const tags = [];
373
+ const taxonScopes = (_f = resource.get('taxon_scope')) !== null && _f !== void 0 ? _f : work.get('taxon_scope');
430
374
  if (taxonScopes) {
431
- tags.push.apply(tags, taxonScopes);
375
+ tags.push(...taxonScopes);
432
376
  }
433
377
  else if (((_g = resource.get('complete')) !== null && _g !== void 0 ? _g : work.get('complete')) === 'FALSE') {
434
378
  tags.push('not intended to be complete');
435
379
  }
436
- var targetTaxa = (_h = resource.get('target_taxa')) !== null && _h !== void 0 ? _h : work.get('target_taxa');
380
+ const targetTaxa = (_h = resource.get('target_taxa')) !== null && _h !== void 0 ? _h : work.get('target_taxa');
437
381
  if (targetTaxa) {
438
- var first = targetTaxa.slice(0, -1).map(function (rank) { return rank + ','; });
439
- var last = targetTaxa[targetTaxa.length - 1];
440
- var list = first.length ? first.join('') + ' or ' + last : last;
441
- tags.push("for identification to ".concat(list));
382
+ const first = targetTaxa.slice(0, -1).map(rank => rank + ',');
383
+ const last = targetTaxa[targetTaxa.length - 1];
384
+ const list = first.length ? first.join('') + ' or ' + last : last;
385
+ tags.push(`for identification to ${list}`);
442
386
  }
443
387
  if (tags.length) {
444
388
  node['ac:tag'] = tags;
445
389
  }
446
390
  if (files.resources[resourceId].taxa) {
447
- var leafs = new Set(files.resources[resourceId].taxa.map(function (taxon) { return taxon.scientificNameID; }));
448
- var taxa = [];
449
- for (var _m = 0, _o = files.resources[resourceId].taxa; _m < _o.length; _m++) {
450
- var taxon = _o[_m];
391
+ const leafs = new Set(files.resources[resourceId].taxa.map(taxon => taxon.scientificNameID));
392
+ const taxa = [];
393
+ for (const taxon of files.resources[resourceId].taxa) {
451
394
  taxa.push(makeLinkedDataForScientificName(taxon));
452
395
  if (taxon.parentNameUsageID) {
453
396
  leafs.delete(taxon.parentNameUsageID);
@@ -459,20 +402,20 @@ function makeLinkedDataForResource(work, files, resourceId) {
459
402
  return node;
460
403
  }
461
404
  function makeLinkedDataForWork(work, files) {
462
- var id = work.get('id');
463
- var node = makeWorkUri(id);
464
- var languages = work.get('language');
465
- node['dcterms:language'] = languages.map(function (language) { return ({ '@id': "http://id.loc.gov/vocabulary/iso639-1/".concat(language) }); });
405
+ const id = work.get('id');
406
+ const node = makeWorkUri(id);
407
+ const languages = work.get('language');
408
+ node['dcterms:language'] = languages.map(language => ({ '@id': `http://id.loc.gov/vocabulary/iso639-1/${language}` }));
466
409
  if (work.has('title')) {
467
- var title = work.get('title');
410
+ const title = work.get('title');
468
411
  if (title.length > languages.length) {
469
412
  title.splice(0, title.length, title.join('; '));
470
413
  }
471
- node['dcterms:title'] = title.map(function (value, i) { return ({ '@value': value, '@language': languages[i] }); });
414
+ node['dcterms:title'] = title.map((value, i) => ({ '@value': value, '@language': languages[i] }));
472
415
  }
473
416
  if (work.has('pages') && work.get('pages').includes('-')) {
474
- var containers = work.has('part_of') ? work.get('part_of').map(function (id) { return files.catalog.get(id); }) : [];
475
- if (containers.find(function (container) { return container.get('entry_type') === 'online'; })) {
417
+ const containers = work.has('part_of') ? work.get('part_of').map(id => files.catalog.get(id)) : [];
418
+ if (containers.find(container => container.get('entry_type') === 'online')) {
476
419
  node['@type'] = 'bibo:BookSection';
477
420
  }
478
421
  else {
@@ -486,28 +429,28 @@ function makeLinkedDataForWork(work, files) {
486
429
  node['@type'] = 'bibo:Book';
487
430
  }
488
431
  if (work.has('author')) {
489
- var authors = mapEntities(work.get('author'), files.authors.entities).map(function (author) { return ({ '@id': "".concat(PREFIX, "author/").concat(author.get('id')) }); });
432
+ const authors = mapEntities(work.get('author'), files.authors.entities).map(author => ({ '@id': `${PREFIX}author/${author.get('id')}` }));
490
433
  node['bibo:authorList'] = { '@list': authors };
491
434
  node['dcterms:creator'] = authors;
492
435
  }
493
436
  if (work.has('url')) {
494
- var urls = work.get('url');
495
- var handle = urls.find(function (url) { return url.startsWith(HANDLE_PREFIX); });
437
+ const urls = work.get('url');
438
+ const handle = urls.find(url => url.startsWith(HANDLE_PREFIX));
496
439
  if (handle) {
497
440
  node['bibo:handle'] = { '@id': handle.slice(HANDLE_PREFIX.length) };
498
441
  }
499
- node['schema:url'] = urls.map(function (url) { return ({ '@id': url }); });
442
+ node['schema:url'] = urls.map(url => ({ '@id': url }));
500
443
  }
501
444
  if (work.has('fulltext_url')) {
502
- var urls = work.get('fulltext_url');
503
- node['schema:encoding'] = urls.map(function (url) { return ({ '@type': 'schema:MediaObject', 'schema:contentUrl': { '@id': url } }); });
445
+ const urls = work.get('fulltext_url');
446
+ node['schema:encoding'] = urls.map(url => ({ '@type': 'schema:MediaObject', 'schema:contentUrl': { '@id': url } }));
504
447
  }
505
448
  if (work.has('archive_url')) {
506
- node['schema:archivedAt'] = work.get('archive_url').map(function (url) { return ({ '@id': url }); });
449
+ node['schema:archivedAt'] = work.get('archive_url').map(url => ({ '@id': url }));
507
450
  }
508
451
  if (work.has('date')) {
509
- var date = work.get('date');
510
- var dateType = 'rdfs:Literal';
452
+ const date = work.get('date');
453
+ let dateType = 'rdfs:Literal';
511
454
  if (date.match(/^\d{4}-\d{2}-\d{2}$/)) {
512
455
  dateType = 'xsd:date';
513
456
  }
@@ -520,16 +463,15 @@ function makeLinkedDataForWork(work, files) {
520
463
  node['dcterms:issued'] = { '@value': work.get('date'), '@type': dateType };
521
464
  }
522
465
  if (work.has('publisher')) {
523
- var publishers = mapEntities(work.get('publisher'), files.publishers.entities).map(function (publisher) { return ({ '@id': "".concat(PREFIX, "publisher/").concat(publisher.get('id')) }); });
466
+ const publishers = mapEntities(work.get('publisher'), files.publishers.entities).map(publisher => ({ '@id': `${PREFIX}publisher/${publisher.get('id')}` }));
524
467
  node['dcterms:publisher'] = publishers;
525
468
  }
526
469
  if (work.has('ISSN')) {
527
470
  node['bibo:issn'] = work.get('ISSN');
528
471
  }
529
472
  if (work.has('ISBN')) {
530
- var isbns = work.get('ISBN');
531
- for (var _i = 0, isbns_1 = isbns; _i < isbns_1.length; _i++) {
532
- var isbn = isbns_1[_i];
473
+ const isbns = work.get('ISBN');
474
+ for (const isbn of isbns) {
533
475
  if (isbn.length === 13) {
534
476
  node['bibo:isbn13'] = isbn;
535
477
  }
@@ -554,14 +496,14 @@ function makeLinkedDataForWork(work, files) {
554
496
  node['bibo:issue'] = work.get('issue');
555
497
  }
556
498
  if (work.has('pages')) {
557
- var pages = work.get('pages');
558
- var range = pages.split('-');
499
+ const pages = work.get('pages');
500
+ const range = pages.split('-');
559
501
  if (pages.match(/^\d+$/)) {
560
502
  node['bibo:numPages'] = parseInt(pages);
561
503
  }
562
504
  else if (range.length === 2) {
563
505
  node['bibo:pages'] = pages;
564
- var _a = range.map(function (part) { return parseInt(part); }), start = _a[0], end = _a[1];
506
+ const [start, end] = range.map(part => parseInt(part));
565
507
  if (!isNaN(start)) {
566
508
  node['bibo:pageStart'] = start;
567
509
  }
@@ -580,38 +522,36 @@ function makeLinkedDataForWork(work, files) {
580
522
  node['bibo:edition'] = work.get('edition');
581
523
  }
582
524
  if (work.has('license')) {
583
- var licenses = work.get('license');
584
- node['dcterms:rights'] = licenses.map(function (license) {
525
+ const licenses = work.get('license');
526
+ node['dcterms:rights'] = licenses.map(license => {
585
527
  if (license === '<public domain>' || license.match(/^<.+\?>$/)) {
586
528
  return license.slice(1, -1);
587
529
  }
588
530
  else {
589
- return { '@id': "https://spdx.org/licenses/".concat(license, ".html") };
531
+ return { '@id': `https://spdx.org/licenses/${license}.html` };
590
532
  }
591
533
  });
592
534
  }
593
535
  return node;
594
536
  }
595
537
  function makeLinkedDataForWorks(files) {
596
- var nodes = {};
597
- var works = files.catalog;
598
- for (var _i = 0, _a = works.entities; _i < _a.length; _i++) {
599
- var work = _a[_i];
538
+ const nodes = {};
539
+ const works = files.catalog;
540
+ for (const work of works.entities) {
600
541
  nodes[work.get('id')] = makeLinkedDataForWork(work, files);
601
542
  }
602
- var _loop_2 = function (work) {
603
- var id = work.get('id');
604
- var node = nodes[id];
605
- var language = work.get('language');
543
+ for (const work of works.entities) {
544
+ const id = work.get('id');
545
+ const node = nodes[id];
546
+ const language = work.get('language');
606
547
  if (work.has('part_of')) {
607
- var containers = work.get('part_of');
548
+ const containers = work.get('part_of');
608
549
  if (work.get('key_type').includes('supplement')) {
609
550
  node['bibo:annotates'] = containers.map(makeWorkUri);
610
551
  }
611
552
  else {
612
553
  node['dcterms:isPartOf'] = containers.map(makeWorkUri);
613
- for (var _d = 0, containers_1 = containers; _d < containers_1.length; _d++) {
614
- var container = containers_1[_d];
554
+ for (const container of containers) {
615
555
  if (!Array.isArray(nodes[container]['dcterms:hasPart'])) {
616
556
  nodes[container]['dcterms:hasPart'] = [];
617
557
  }
@@ -620,23 +560,22 @@ function makeLinkedDataForWorks(files) {
620
560
  }
621
561
  }
622
562
  if (work.has('listed_in')) {
623
- var referers = work.get('listed_in');
563
+ const referers = work.get('listed_in');
624
564
  node['bibo:citedBy'] = node['dcterms:isReferencedBy'] = referers.map(makeWorkUri);
625
- for (var _e = 0, referers_1 = referers; _e < referers_1.length; _e++) {
626
- var referer = referers_1[_e];
565
+ for (const referer of referers) {
627
566
  nodes[referer]['bibo:cites'] = nodes[referer]['dcterms:references'] = makeWorkUri(id);
628
567
  }
629
568
  }
630
569
  if (work.has('version_of')) {
631
- var originals = work.get('version_of');
632
- var originalLanguages_1 = originals.map(function (id) { return works.get(id).get('language').join(); });
633
- node['bibo:translationOf'] = originals.filter(function (_, i) { return originalLanguages_1[i] !== language.join(); }).map(makeWorkUri);
634
- node['dcterms:isVersionOf'] = originals.filter(function (id) { return work.get('id') !== id; }).map(makeWorkUri);
635
- }
636
- var resourceIndex = 1;
637
- var resourceId = void 0;
638
- while ((resourceId = "".concat(id, ":").concat(resourceIndex++)) in files.resources) {
639
- var resource = makeLinkedDataForResource(work, files, resourceId);
570
+ const originals = work.get('version_of');
571
+ const originalLanguages = originals.map(id => works.get(id).get('language').join());
572
+ node['bibo:translationOf'] = originals.filter((_, i) => originalLanguages[i] !== language.join()).map(makeWorkUri);
573
+ node['dcterms:isVersionOf'] = originals.filter(id => work.get('id') !== id).map(makeWorkUri);
574
+ }
575
+ let resourceIndex = 1;
576
+ let resourceId;
577
+ while ((resourceId = `${id}:${resourceIndex++}`) in files.resources) {
578
+ const resource = makeLinkedDataForResource(work, files, resourceId);
640
579
  if (!Array.isArray(node['dcterms:hasPart'])) {
641
580
  node['dcterms:hasPart'] = [];
642
581
  }
@@ -646,144 +585,82 @@ function makeLinkedDataForWorks(files) {
646
585
  }
647
586
  resource['dcterms:isPartOf'].push({ '@id': node['@id'] });
648
587
  }
649
- };
650
- for (var _b = 0, _c = works.entities; _b < _c.length; _b++) {
651
- var work = _c[_b];
652
- _loop_2(work);
653
588
  }
654
589
  return Object.values(nodes);
655
590
  }
656
591
  function writeOutput(document_1) {
657
- return __awaiter(this, arguments, void 0, function (document, format) {
658
- var nquads, parser, writer;
659
- if (format === void 0) { format = 'jsonld'; }
660
- return __generator(this, function (_a) {
661
- switch (_a.label) {
662
- case 0:
663
- if (format === 'jsonld') {
664
- process.stdout.write(JSON.stringify(document, null, 2));
665
- return [2 /*return*/];
666
- }
667
- return [4 /*yield*/, jsonld.toRDF(document, { format: 'application/n-quads' })];
668
- case 1:
669
- nquads = _a.sent();
670
- if (format === 'nquads') {
671
- process.stdout.write(nquads);
672
- return [2 /*return*/];
673
- }
674
- parser = new N3.StreamParser();
675
- writer = new N3.StreamWriter({ prefixes: PREFIXES });
676
- parser.write(nquads);
677
- parser.pipe(writer);
678
- writer.pipe(process.stdout);
679
- return [2 /*return*/];
680
- }
681
- });
592
+ return __awaiter(this, arguments, void 0, function* (document, format = 'jsonld') {
593
+ if (format === 'jsonld') {
594
+ process.stdout.write(JSON.stringify(document, null, 2));
595
+ return;
596
+ }
597
+ const nquads = yield jsonld.toRDF(document, { format: 'application/n-quads' });
598
+ if (format === 'nquads') {
599
+ process.stdout.write(nquads);
600
+ return;
601
+ }
602
+ const parser = new N3.StreamParser();
603
+ const writer = new N3.StreamWriter({ prefixes: PREFIXES });
604
+ parser.write(nquads);
605
+ parser.pipe(writer);
606
+ writer.pipe(process.stdout);
682
607
  });
683
608
  }
684
609
  function main() {
685
- return __awaiter(this, void 0, void 0, function () {
686
- var args, directory, files, _i, SHEETS_1, sheet, filePath, file, resources, _a, _b, _loop_3, _c, _d, _e, _f, id, graph, _g, _h, entity, _j, _k, entity, _l, _m, entity, document;
687
- return __generator(this, function (_o) {
688
- switch (_o.label) {
689
- case 0:
690
- args = util.parseArgs({
691
- allowPositionals: true,
692
- options: {
693
- format: {
694
- type: 'string',
695
- short: 'f',
696
- default: 'jsonld',
697
- }
698
- },
699
- });
700
- directory = path.resolve(args.positionals[0]);
701
- files = {};
702
- _i = 0, SHEETS_1 = SHEETS;
703
- _o.label = 1;
704
- case 1:
705
- if (!(_i < SHEETS_1.length)) return [3 /*break*/, 4];
706
- sheet = SHEETS_1[_i];
707
- filePath = path.join(directory, "".concat(sheet, ".csv"));
708
- if (!(0, fs_1.existsSync)(filePath)) {
709
- throw new Error("File \"".concat(sheet, ".csv\" must be provided"));
710
- }
711
- return [4 /*yield*/, fs_1.promises.readFile(filePath, 'utf8')];
712
- case 2:
713
- file = _o.sent();
714
- files[sheet] = index_1.catalog.loadData(file, sheet);
715
- _o.label = 3;
716
- case 3:
717
- _i++;
718
- return [3 /*break*/, 1];
719
- case 4:
720
- files.resources = {};
721
- _b = (_a = JSON).parse;
722
- return [4 /*yield*/, fs_1.promises.readFile(path.join(directory, 'resources', 'index.json'), 'utf8')];
723
- case 5:
724
- resources = _b.apply(_a, [_o.sent()]);
725
- _loop_3 = function (id) {
726
- var filePath, file, _p, header, rows, taxa;
727
- return __generator(this, function (_q) {
728
- switch (_q.label) {
729
- case 0:
730
- filePath = path.join(directory, 'resources', 'dwc', id.split(':').join('-') + '.csv');
731
- return [4 /*yield*/, fs_1.promises.readFile(filePath, 'utf8')];
732
- case 1:
733
- file = _q.sent();
734
- _p = (0, csv_1.parseCsv)(file), header = _p[0], rows = _p.slice(1);
735
- taxa = rows.map(function (row) { return row.reduce(function (object, value, index) {
736
- object[header[index]] = value;
737
- return object;
738
- }, {}); });
739
- files.resources[id] = { metadata: resources[id], taxa: taxa };
740
- return [2 /*return*/];
741
- }
742
- });
743
- };
744
- _c = resources;
745
- _d = [];
746
- for (_e in _c)
747
- _d.push(_e);
748
- _f = 0;
749
- _o.label = 6;
750
- case 6:
751
- if (!(_f < _d.length)) return [3 /*break*/, 9];
752
- _e = _d[_f];
753
- if (!(_e in _c)) return [3 /*break*/, 8];
754
- id = _e;
755
- return [5 /*yield**/, _loop_3(id)];
756
- case 7:
757
- _o.sent();
758
- _o.label = 8;
759
- case 8:
760
- _f++;
761
- return [3 /*break*/, 6];
762
- case 9:
763
- graph = __spreadArray(__spreadArray([], makeLinkedDataForWorks(files), true), makeLinkedDataForTaxa(files), true);
764
- for (_g = 0, _h = files.authors.entities; _g < _h.length; _g++) {
765
- entity = _h[_g];
766
- graph.push(makeLinkedDataForAuthor(entity));
767
- }
768
- for (_j = 0, _k = files.places.entities; _j < _k.length; _j++) {
769
- entity = _k[_j];
770
- graph.push(makeLinkedDataForPlace(entity));
771
- }
772
- for (_l = 0, _m = files.publishers.entities; _l < _m.length; _l++) {
773
- entity = _m[_l];
774
- graph.push(makeLinkedDataForPublisher(entity));
775
- }
776
- document = {
777
- '@context': PREFIXES,
778
- '@graph': graph
779
- };
780
- writeOutput(document, args.values.format);
781
- return [2 /*return*/];
782
- }
610
+ return __awaiter(this, void 0, void 0, function* () {
611
+ const args = util.parseArgs({
612
+ allowPositionals: true,
613
+ options: {
614
+ format: {
615
+ type: 'string',
616
+ short: 'f',
617
+ default: 'jsonld',
618
+ }
619
+ },
783
620
  });
621
+ const directory = path.resolve(args.positionals[0]);
622
+ const files = {};
623
+ for (const sheet of SHEETS) {
624
+ const filePath = path.join(directory, `${sheet}.csv`);
625
+ if (!(0, fs_1.existsSync)(filePath)) {
626
+ throw new Error(`File "${sheet}.csv" must be provided`);
627
+ }
628
+ const file = yield fs_1.promises.readFile(filePath, 'utf8');
629
+ files[sheet] = index_1.catalog.loadData(file, sheet);
630
+ }
631
+ files.resources = {};
632
+ const resources = JSON.parse(yield fs_1.promises.readFile(path.join(directory, 'resources', 'index.json'), 'utf8'));
633
+ for (const id in resources) {
634
+ const filePath = path.join(directory, 'resources', 'dwc', id.split(':').join('-') + '.csv');
635
+ const file = yield fs_1.promises.readFile(filePath, 'utf8');
636
+ const [header, ...rows] = (0, csv_1.parseCsv)(file);
637
+ const taxa = rows.map(row => row.reduce((object, value, index) => {
638
+ object[header[index]] = value;
639
+ return object;
640
+ }, {}));
641
+ files.resources[id] = { metadata: resources[id], taxa };
642
+ }
643
+ const graph = [
644
+ ...makeLinkedDataForWorks(files),
645
+ ...makeLinkedDataForTaxa(files),
646
+ ];
647
+ for (const entity of files.authors.entities) {
648
+ graph.push(makeLinkedDataForAuthor(entity));
649
+ }
650
+ for (const entity of files.places.entities) {
651
+ graph.push(makeLinkedDataForPlace(entity));
652
+ }
653
+ for (const entity of files.publishers.entities) {
654
+ graph.push(makeLinkedDataForPublisher(entity));
655
+ }
656
+ const document = {
657
+ '@context': PREFIXES,
658
+ '@graph': graph
659
+ };
660
+ writeOutput(document, args.values.format);
784
661
  });
785
662
  }
786
- main().catch(function (error) {
663
+ main().catch((error) => {
787
664
  console.error(error);
788
665
  process.exit(1);
789
666
  });