cocoda-sdk 3.3.3 → 3.3.4
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.
- package/dist/cjs/index.cjs +809 -0
- package/dist/cocoda-sdk.js +16 -11
- package/dist/cocoda-sdk.js.LICENSES.txt +177 -3
- package/dist/cocoda-sdk.js.map +4 -4
- package/dist/esm/errors/index.js +22 -0
- package/dist/esm/lib/CocodaSDK.js +99 -0
- package/dist/esm/providers/base-provider.js +88 -0
- package/dist/esm/providers/concept-api-provider.js +108 -0
- package/dist/esm/providers/label-search-suggestion-provider.js +39 -0
- package/dist/esm/providers/loc-api-provider.js +58 -0
- package/dist/esm/providers/local-mappings-provider.js +57 -0
- package/dist/esm/providers/mappings-api-provider.js +116 -0
- package/dist/esm/providers/mycore-provider.js +42 -0
- package/dist/esm/providers/occurrences-api-provider.js +32 -0
- package/dist/esm/providers/reconciliation-api-provider.js +21 -0
- package/dist/esm/providers/skohub-provider.js +26 -0
- package/dist/esm/providers/skosmos-api-provider.js +89 -0
- package/dist/esm/utils/index.js +8 -0
- package/package.json +5 -5
|
@@ -71,6 +71,9 @@ function madsToJskosConcept(data, { scheme }) {
|
|
|
71
71
|
return concept;
|
|
72
72
|
}
|
|
73
73
|
class LocApiProvider extends BaseProvider {
|
|
74
|
+
/**
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
74
77
|
_prepare() {
|
|
75
78
|
this.has.schemes = true;
|
|
76
79
|
this.has.top = false;
|
|
@@ -84,6 +87,13 @@ class LocApiProvider extends BaseProvider {
|
|
|
84
87
|
this.has[c] = false;
|
|
85
88
|
});
|
|
86
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
|
|
92
|
+
*
|
|
93
|
+
* @param {Object} options
|
|
94
|
+
* @param {Object} options.scheme scheme for which the config is requested
|
|
95
|
+
* @returns {Object} provider configuration
|
|
96
|
+
*/
|
|
87
97
|
static _registryConfigForBartocApiConfig({ scheme } = {}) {
|
|
88
98
|
if (!scheme || !supportedSchemes.find((s) => jskos.compare(s, scheme))) {
|
|
89
99
|
return null;
|
|
@@ -92,6 +102,11 @@ class LocApiProvider extends BaseProvider {
|
|
|
92
102
|
schemes: [scheme]
|
|
93
103
|
};
|
|
94
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns all concept schemes.
|
|
107
|
+
*
|
|
108
|
+
* @returns {Object[]} array of JSKOS concept scheme objects
|
|
109
|
+
*/
|
|
95
110
|
async getSchemes() {
|
|
96
111
|
const schemes = [];
|
|
97
112
|
for (let scheme of await Promise.all(
|
|
@@ -116,6 +131,29 @@ class LocApiProvider extends BaseProvider {
|
|
|
116
131
|
}
|
|
117
132
|
return schemes;
|
|
118
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* TODO: Possibly reenable for LCC
|
|
136
|
+
* Returns top concepts for a concept scheme.
|
|
137
|
+
*
|
|
138
|
+
* @param {Object} config
|
|
139
|
+
* @param {Object} config.scheme concept scheme object
|
|
140
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
141
|
+
*/
|
|
142
|
+
// async getTop({ scheme }) {
|
|
143
|
+
// if (scheme.topConcepts && !scheme.topConcepts.includes(null)) {
|
|
144
|
+
// return scheme.topConcepts
|
|
145
|
+
// }
|
|
146
|
+
// const schemes = await this.getSchemes()
|
|
147
|
+
// scheme = schemes.find(s => jskos.compare(s, scheme))
|
|
148
|
+
// return scheme && scheme.topConcepts || []
|
|
149
|
+
// }
|
|
150
|
+
/**
|
|
151
|
+
* Returns details for a list of concepts.
|
|
152
|
+
*
|
|
153
|
+
* @param {Object} config
|
|
154
|
+
* @param {Object[]} config.concepts list of concept objects to load
|
|
155
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
156
|
+
*/
|
|
119
157
|
async getConcepts({ concepts }) {
|
|
120
158
|
if (!Array.isArray(concepts)) {
|
|
121
159
|
concepts = [concepts];
|
|
@@ -139,6 +177,16 @@ class LocApiProvider extends BaseProvider {
|
|
|
139
177
|
}
|
|
140
178
|
return resultConcepts;
|
|
141
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns suggestion result in OpenSearch Suggest Format.
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} config
|
|
184
|
+
* @param {string} config.search search string
|
|
185
|
+
* @param {Object} config.scheme concept scheme to search in
|
|
186
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
187
|
+
* @param {number} [config.offset=0] offset
|
|
188
|
+
* @returns {Array} result in OpenSearch Suggest Format
|
|
189
|
+
*/
|
|
142
190
|
async suggest(config) {
|
|
143
191
|
const results = await this.search(config);
|
|
144
192
|
return [
|
|
@@ -150,6 +198,16 @@ class LocApiProvider extends BaseProvider {
|
|
|
150
198
|
results.map((c) => c.uri)
|
|
151
199
|
];
|
|
152
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns search results in JSKOS Format.
|
|
203
|
+
*
|
|
204
|
+
* @param {Object} config
|
|
205
|
+
* @param {string} config.search search string
|
|
206
|
+
* @param {Object} config.scheme concept scheme to search in
|
|
207
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
208
|
+
* @param {number} [config.offset=0] offset
|
|
209
|
+
* @returns {Array} result in JSKOS Format
|
|
210
|
+
*/
|
|
153
211
|
async search({ search, scheme, limit, offset }) {
|
|
154
212
|
const schemeUri = jskos.getAllUris(scheme).find((uri) => uri.startsWith(locUriPrefix));
|
|
155
213
|
if (!schemeUri || !supportedSchemes.find((s) => jskos.compare(s, { uri: schemeUri }))) {
|
|
@@ -7,6 +7,9 @@ import * as errors from "../errors/index.js";
|
|
|
7
7
|
import { listOfCapabilities } from "../utils/index.js";
|
|
8
8
|
const uriPrefix = "urn:uuid:";
|
|
9
9
|
class LocalMappingsProvider extends BaseProvider {
|
|
10
|
+
/**
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
10
13
|
_prepare() {
|
|
11
14
|
this.has.mappings = {
|
|
12
15
|
read: true,
|
|
@@ -18,6 +21,9 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
18
21
|
this.has[c] = false;
|
|
19
22
|
});
|
|
20
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
21
27
|
_setup() {
|
|
22
28
|
this.queue = [];
|
|
23
29
|
this.localStorageKey = "cocoda-mappings--" + this._path;
|
|
@@ -59,6 +65,14 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
59
65
|
}
|
|
60
66
|
return false;
|
|
61
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns a Promise that returns an object { mappings, done } with the local mappings and a done function that is supposed to be called when the transaction is finished.
|
|
70
|
+
* This prevents conflicts when saveMapping is called multiple times simultaneously.
|
|
71
|
+
*
|
|
72
|
+
* TODO: There might be a better solution for this...
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
62
76
|
_getMappingsQueue() {
|
|
63
77
|
let last = _.last(this.queue) || Promise.resolve();
|
|
64
78
|
return new Promise((resolve) => {
|
|
@@ -84,6 +98,13 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
84
98
|
});
|
|
85
99
|
});
|
|
86
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns a single mapping.
|
|
103
|
+
*
|
|
104
|
+
* @param {Object} config
|
|
105
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
106
|
+
* @returns {Object} JSKOS mapping object
|
|
107
|
+
*/
|
|
87
108
|
async getMapping({ mapping, ...config }) {
|
|
88
109
|
config._raw = true;
|
|
89
110
|
if (!mapping || !mapping.uri) {
|
|
@@ -91,6 +112,14 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
91
112
|
}
|
|
92
113
|
return (await this.getMappings({ ...config, uri: mapping.uri }))[0];
|
|
93
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns a list of local mappings.
|
|
117
|
+
*
|
|
118
|
+
* TODO: Add support for sort (`created` or `modified`) and order (`asc` or `desc`).
|
|
119
|
+
* TODO: Clean up and use async/await
|
|
120
|
+
*
|
|
121
|
+
* @returns {Object[]} array of JSKOS mapping objects
|
|
122
|
+
*/
|
|
94
123
|
async getMappings({ from, fromScheme, to, toScheme, creator, type, partOf, offset, limit, direction, mode, identifier, uri } = {}) {
|
|
95
124
|
let params = {};
|
|
96
125
|
if (from) {
|
|
@@ -236,6 +265,13 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
236
265
|
return mappings;
|
|
237
266
|
});
|
|
238
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Creates a mapping.
|
|
270
|
+
*
|
|
271
|
+
* @param {Object} config
|
|
272
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
273
|
+
* @returns {Object} JSKOS mapping object
|
|
274
|
+
*/
|
|
239
275
|
async postMapping({ mapping }) {
|
|
240
276
|
if (!mapping) {
|
|
241
277
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -271,6 +307,13 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
271
307
|
throw error;
|
|
272
308
|
}
|
|
273
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Overwrites a mapping.
|
|
312
|
+
*
|
|
313
|
+
* @param {Object} config
|
|
314
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
315
|
+
* @returns {Object} JSKOS mapping object
|
|
316
|
+
*/
|
|
274
317
|
async putMapping({ mapping }) {
|
|
275
318
|
if (!mapping) {
|
|
276
319
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -296,6 +339,13 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
296
339
|
throw error;
|
|
297
340
|
}
|
|
298
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Patches a mapping.
|
|
344
|
+
*
|
|
345
|
+
* @param {Object} config
|
|
346
|
+
* @param {Object} mapping JSKOS mapping (or part of mapping)
|
|
347
|
+
* @returns {Object} JSKOS mapping object
|
|
348
|
+
*/
|
|
299
349
|
async patchMapping({ mapping }) {
|
|
300
350
|
if (!mapping) {
|
|
301
351
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -321,6 +371,13 @@ class LocalMappingsProvider extends BaseProvider {
|
|
|
321
371
|
throw error;
|
|
322
372
|
}
|
|
323
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Removes a mapping from local storage.
|
|
376
|
+
*
|
|
377
|
+
* @param {Object} config
|
|
378
|
+
* @param {Object} mapping JSKOS mapping
|
|
379
|
+
* @returns {boolean} boolean whether deleting the mapping was successful
|
|
380
|
+
*/
|
|
324
381
|
async deleteMapping({ mapping }) {
|
|
325
382
|
if (!mapping) {
|
|
326
383
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -4,6 +4,9 @@ import * as _ from "../utils/lodash.js";
|
|
|
4
4
|
import * as errors from "../errors/index.js";
|
|
5
5
|
import * as utils from "../utils/index.js";
|
|
6
6
|
class MappingsApiProvider extends BaseProvider {
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
7
10
|
_prepare() {
|
|
8
11
|
if (this._api.api && this._api.status === void 0) {
|
|
9
12
|
this._api.status = utils.concatUrl(this._api.api, "/status");
|
|
@@ -15,6 +18,9 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
15
18
|
this.has[c] = false;
|
|
16
19
|
});
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
18
24
|
_setup() {
|
|
19
25
|
if (this._api.api) {
|
|
20
26
|
const endpoints = {
|
|
@@ -55,6 +61,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
55
61
|
properties: "annotations"
|
|
56
62
|
};
|
|
57
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns a single mapping.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} config
|
|
68
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
69
|
+
* @returns {Object} JSKOS mapping object
|
|
70
|
+
*/
|
|
58
71
|
async getMapping({ mapping, ...config }) {
|
|
59
72
|
if (!mapping) {
|
|
60
73
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -78,6 +91,12 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
78
91
|
throw error;
|
|
79
92
|
}
|
|
80
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns a list of mappings.
|
|
96
|
+
*
|
|
97
|
+
* @param {Object} config request config with parameters
|
|
98
|
+
* @returns {Object[]} array of JSKOS mapping objects
|
|
99
|
+
*/
|
|
81
100
|
async getMappings({ from, fromScheme, to, toScheme, creator, type, partOf, offset, limit, direction, mode, identifier, cardinality, annotatedBy, annotatedFor, annotatedWith, sort, order, ...config }) {
|
|
82
101
|
let params = {}, url = this._api.mappings;
|
|
83
102
|
if (from) {
|
|
@@ -145,6 +164,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
145
164
|
}
|
|
146
165
|
});
|
|
147
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a mapping.
|
|
169
|
+
*
|
|
170
|
+
* @param {Object} config
|
|
171
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
172
|
+
* @returns {Object} JSKOS mapping object
|
|
173
|
+
*/
|
|
148
174
|
async postMapping({ mapping, ...config }) {
|
|
149
175
|
if (!mapping) {
|
|
150
176
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -162,6 +188,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
162
188
|
}
|
|
163
189
|
});
|
|
164
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Overwrites a mapping.
|
|
193
|
+
*
|
|
194
|
+
* @param {Object} config
|
|
195
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
196
|
+
* @returns {Object} JSKOS mapping object
|
|
197
|
+
*/
|
|
165
198
|
async putMapping({ mapping, ...config }) {
|
|
166
199
|
if (!mapping) {
|
|
167
200
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -183,6 +216,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
183
216
|
}
|
|
184
217
|
});
|
|
185
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Patches a mapping.
|
|
221
|
+
*
|
|
222
|
+
* @param {Object} config
|
|
223
|
+
* @param {Object} config.mapping JSKOS mapping (or part of mapping)
|
|
224
|
+
* @returns {Object} JSKOS mapping object
|
|
225
|
+
*/
|
|
186
226
|
async patchMapping({ mapping, ...config }) {
|
|
187
227
|
if (!mapping) {
|
|
188
228
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -202,6 +242,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
202
242
|
}
|
|
203
243
|
});
|
|
204
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Deletes a mapping.
|
|
247
|
+
*
|
|
248
|
+
* @param {Object} config
|
|
249
|
+
* @param {Object} config.mapping JSKOS mapping
|
|
250
|
+
* @returns {boolean} `true` if deletion was successful
|
|
251
|
+
*/
|
|
205
252
|
async deleteMapping({ mapping, ...config }) {
|
|
206
253
|
if (!mapping) {
|
|
207
254
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
|
|
@@ -217,6 +264,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
217
264
|
});
|
|
218
265
|
return true;
|
|
219
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Returns a list of annotations.
|
|
269
|
+
*
|
|
270
|
+
* @param {Object} config
|
|
271
|
+
* @param {string} [config.target] target URI
|
|
272
|
+
* @returns {Object[]} array of JSKOS annotation objects
|
|
273
|
+
*/
|
|
220
274
|
async getAnnotations({ target, ...config }) {
|
|
221
275
|
if (target) {
|
|
222
276
|
_.set(config, "params.target", target);
|
|
@@ -227,6 +281,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
227
281
|
url: this._api.annotations
|
|
228
282
|
});
|
|
229
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Creates an annotation.
|
|
286
|
+
*
|
|
287
|
+
* @param {Object} config
|
|
288
|
+
* @param {Object} config.annotation JSKOS annotation
|
|
289
|
+
* @returns {Object} JSKOS annotation object
|
|
290
|
+
*/
|
|
230
291
|
async postAnnotation({ annotation, ...config }) {
|
|
231
292
|
return this.axios({
|
|
232
293
|
...config,
|
|
@@ -235,6 +296,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
235
296
|
data: annotation
|
|
236
297
|
});
|
|
237
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Overwrites an annotation.
|
|
301
|
+
*
|
|
302
|
+
* @param {Object} config
|
|
303
|
+
* @param {Object} config.annotation JSKOS annotation
|
|
304
|
+
* @returns {Object} JSKOS annotation object
|
|
305
|
+
*/
|
|
238
306
|
async putAnnotation({ annotation, ...config }) {
|
|
239
307
|
const uri = annotation.id;
|
|
240
308
|
if (!uri || !uri.startsWith(this._api.annotations)) {
|
|
@@ -247,6 +315,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
247
315
|
data: annotation
|
|
248
316
|
});
|
|
249
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Patches an annotation.
|
|
320
|
+
*
|
|
321
|
+
* @param {Object} config
|
|
322
|
+
* @param {Object} config.annotation JSKOS annotation
|
|
323
|
+
* @returns {Object} JSKOS annotation object
|
|
324
|
+
*/
|
|
250
325
|
async patchAnnotation({ annotation, ...config }) {
|
|
251
326
|
const uri = annotation.id;
|
|
252
327
|
if (!uri || !uri.startsWith(this._api.annotations)) {
|
|
@@ -259,6 +334,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
259
334
|
data: annotation
|
|
260
335
|
});
|
|
261
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Deletes an annotation.
|
|
339
|
+
*
|
|
340
|
+
* @param {Object} config
|
|
341
|
+
* @param {Object} config.annotation JSKOS annotation
|
|
342
|
+
* @returns {boolean} `true` if deletion was successful
|
|
343
|
+
*/
|
|
262
344
|
async deleteAnnotation({ annotation, ...config }) {
|
|
263
345
|
const uri = annotation.id;
|
|
264
346
|
if (!uri || !uri.startsWith(this._api.annotations)) {
|
|
@@ -271,6 +353,12 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
271
353
|
});
|
|
272
354
|
return true;
|
|
273
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Returns a list of concordances.
|
|
358
|
+
*
|
|
359
|
+
* @param {Object} config
|
|
360
|
+
* @returns {Object[]} array of JSKOS concordance objects
|
|
361
|
+
*/
|
|
274
362
|
async getConcordances(config) {
|
|
275
363
|
return this.axios({
|
|
276
364
|
...config,
|
|
@@ -278,6 +366,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
278
366
|
url: this._api.concordances
|
|
279
367
|
});
|
|
280
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Creates a concordance.
|
|
371
|
+
*
|
|
372
|
+
* @param {Object} config
|
|
373
|
+
* @param {Object} config.concordance JSKOS concordance
|
|
374
|
+
* @returns {Object} JSKOS concordance object
|
|
375
|
+
*/
|
|
281
376
|
async postConcordance({ concordance, ...config }) {
|
|
282
377
|
if (!concordance) {
|
|
283
378
|
throw new errors.InvalidOrMissingParameterError({ parameter: "concordance" });
|
|
@@ -293,6 +388,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
293
388
|
}
|
|
294
389
|
});
|
|
295
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Overwrites a concordance.
|
|
393
|
+
*
|
|
394
|
+
* @param {Object} config
|
|
395
|
+
* @param {Object} config.concordance JSKOS concordance
|
|
396
|
+
* @returns {Object} JSKOS concordance object
|
|
397
|
+
*/
|
|
296
398
|
async putConcordance({ concordance, ...config }) {
|
|
297
399
|
if (!concordance) {
|
|
298
400
|
throw new errors.InvalidOrMissingParameterError({ parameter: "concordance" });
|
|
@@ -312,6 +414,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
312
414
|
}
|
|
313
415
|
});
|
|
314
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Patches a concordance.
|
|
419
|
+
*
|
|
420
|
+
* @param {Object} config
|
|
421
|
+
* @param {Object} config.concordance JSKOS concordance (or part of concordance)
|
|
422
|
+
* @returns {Object} JSKOS concordance object
|
|
423
|
+
*/
|
|
315
424
|
async patchConcordance({ concordance, ...config }) {
|
|
316
425
|
if (!concordance) {
|
|
317
426
|
throw new errors.InvalidOrMissingParameterError({ parameter: "concordance" });
|
|
@@ -331,6 +440,13 @@ class MappingsApiProvider extends BaseProvider {
|
|
|
331
440
|
}
|
|
332
441
|
});
|
|
333
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Deletes a concordance.
|
|
445
|
+
*
|
|
446
|
+
* @param {Object} config
|
|
447
|
+
* @param {Object} config.concordance JSKOS concordance
|
|
448
|
+
* @returns {boolean} `true` if deletion was successful
|
|
449
|
+
*/
|
|
334
450
|
async deleteConcordance({ concordance, ...config }) {
|
|
335
451
|
if (!concordance) {
|
|
336
452
|
throw new errors.InvalidOrMissingParameterError({ parameter: "concordance" });
|
|
@@ -22,6 +22,14 @@ class MyCoReProvider extends BaseProvider {
|
|
|
22
22
|
_setup() {
|
|
23
23
|
this._scheme = null;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} options
|
|
29
|
+
* @param {Object} options.url API URL for BARTOC instance
|
|
30
|
+
* @param {Object} options.scheme scheme for which the config is requested
|
|
31
|
+
* @returns {Object} provider configuration
|
|
32
|
+
*/
|
|
25
33
|
static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
|
|
26
34
|
if (!url || !scheme) {
|
|
27
35
|
return null;
|
|
@@ -30,6 +38,9 @@ class MyCoReProvider extends BaseProvider {
|
|
|
30
38
|
api: url
|
|
31
39
|
};
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts scheme info (full scheme data that comes from the API) to a JSKOS scheme
|
|
43
|
+
*/
|
|
33
44
|
_schemeInfoToJSKOS(schemeInfo) {
|
|
34
45
|
const uri = schemeInfo.labels.find((l) => l.lang === "x-uri").text;
|
|
35
46
|
const prefLabel = {};
|
|
@@ -48,6 +59,13 @@ class MyCoReProvider extends BaseProvider {
|
|
|
48
59
|
}
|
|
49
60
|
return scheme;
|
|
50
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Converts a category to a JSKOS concept.
|
|
64
|
+
* - Also saves that concept in data
|
|
65
|
+
* - Also adds the concept's prefLabels to the search index
|
|
66
|
+
*
|
|
67
|
+
* ? Question: Should scopeNotes be part of the search index?
|
|
68
|
+
*/
|
|
51
69
|
_categoryToJSKOS(category, { scheme, broader = [] }) {
|
|
52
70
|
if (!category || !scheme) {
|
|
53
71
|
return null;
|
|
@@ -80,11 +98,17 @@ class MyCoReProvider extends BaseProvider {
|
|
|
80
98
|
};
|
|
81
99
|
return data[scheme.uri].concepts[uri];
|
|
82
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Helper function that replaces `narrower` key with [null] if it has values. Use this before returning concepts.
|
|
103
|
+
*/
|
|
83
104
|
_removeNarrower(concept) {
|
|
84
105
|
if (!concept)
|
|
85
106
|
return concept;
|
|
86
107
|
return Object.assign({}, concept, { narrower: concept.narrower && concept.narrower.length ? [null] : [] });
|
|
87
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Loads the data from the API. Only called from getSchemes and only called once.
|
|
111
|
+
*/
|
|
88
112
|
async _loadSchemeData(config) {
|
|
89
113
|
const schemeInfo = await this.axios({
|
|
90
114
|
...config,
|
|
@@ -171,6 +195,15 @@ class MyCoReProvider extends BaseProvider {
|
|
|
171
195
|
concept = data[this._scheme.uri].concepts[concept.uri];
|
|
172
196
|
return (concept && concept.narrower || []).map((c) => data[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
|
|
173
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Returns concept search results.
|
|
200
|
+
*
|
|
201
|
+
* @param {Object} config
|
|
202
|
+
* @param {string} config.search search string
|
|
203
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
204
|
+
* @param {number} [config.limit=100] maximum number of search results
|
|
205
|
+
* @returns {Array} array of JSKOS concept objects
|
|
206
|
+
*/
|
|
174
207
|
async search({ search, scheme, limit = 100 }) {
|
|
175
208
|
if (!scheme || !scheme.uri) {
|
|
176
209
|
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme" });
|
|
@@ -190,6 +223,15 @@ class MyCoReProvider extends BaseProvider {
|
|
|
190
223
|
const result = await data[this._scheme.uri].searchIndex.search(search);
|
|
191
224
|
return result.map((uri) => data[this._scheme.uri].concepts[uri]).map(this._removeNarrower).slice(0, limit);
|
|
192
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Returns suggestion result in OpenSearch Suggest Format.
|
|
228
|
+
*
|
|
229
|
+
* @param {Object} config
|
|
230
|
+
* @param {string} config.search search string
|
|
231
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
232
|
+
* @param {number} [config.limit=100] maximum number of search results
|
|
233
|
+
* @returns {Array} result in OpenSearch Suggest Format
|
|
234
|
+
*/
|
|
193
235
|
async suggest(config) {
|
|
194
236
|
config._raw = true;
|
|
195
237
|
const concepts = await this.search(config);
|
|
@@ -8,6 +8,9 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
8
8
|
get _cache() {
|
|
9
9
|
return cache[this.uri];
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
11
14
|
_prepare() {
|
|
12
15
|
cache[this.uri] = [];
|
|
13
16
|
this._occurrencesSupportedSchemes = [];
|
|
@@ -17,6 +20,13 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
17
20
|
this.has[c] = false;
|
|
18
21
|
});
|
|
19
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether a concept scheme is supported for occurrences.
|
|
25
|
+
*
|
|
26
|
+
* @private
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} scheme JSKOS scheme to query
|
|
29
|
+
*/
|
|
20
30
|
async _occurrencesIsSupported(scheme) {
|
|
21
31
|
if (this._occurrencesSupportedSchemes && this._occurrencesSupportedSchemes.length) {
|
|
22
32
|
} else {
|
|
@@ -38,6 +48,12 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
38
48
|
}
|
|
39
49
|
return supported;
|
|
40
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Wrapper around getOccurrences that converts occurrences into mappings.
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} config config object for getOccurrences request
|
|
55
|
+
* @returns {Object[]} array of JSKOS mapping objects
|
|
56
|
+
*/
|
|
41
57
|
async getMappings(config) {
|
|
42
58
|
const occurrences = await this.getOccurrences(config);
|
|
43
59
|
const from = config.from;
|
|
@@ -81,6 +97,15 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
81
97
|
mappings._url = occurrences._url;
|
|
82
98
|
return mappings;
|
|
83
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns a list of occurrences.
|
|
102
|
+
*
|
|
103
|
+
* @param {Object} config
|
|
104
|
+
* @param {Object} [config.from] JSKOS concept to load occurrences for (from side)
|
|
105
|
+
* @param {Object} [config.to] JSKOS concept to load occurrences for (to side)
|
|
106
|
+
* @param {Object[]} [config.concepts] list of JSKOS concepts to load occurrences for
|
|
107
|
+
* @returns {Object[]} array of JSKOS occurrence objects
|
|
108
|
+
*/
|
|
84
109
|
async getOccurrences({ from, to, concepts, threshold = 0, ...config }) {
|
|
85
110
|
let promises = [];
|
|
86
111
|
concepts = (concepts || []).concat([from, to]).filter((c) => !!c);
|
|
@@ -133,6 +158,13 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
133
158
|
occurrences._url = results.map((result) => result._url);
|
|
134
159
|
return occurrences;
|
|
135
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Internal function for getOccurrences that either makes an API request or uses a local cache.
|
|
163
|
+
*
|
|
164
|
+
* @private
|
|
165
|
+
*
|
|
166
|
+
* @param {Object} config passthrough of config parameter for axios request
|
|
167
|
+
*/
|
|
136
168
|
async _getOccurrences(config) {
|
|
137
169
|
let resultsFromCache = this._cache.find((item) => {
|
|
138
170
|
return _.isEqual(item.config.params, config.params);
|
|
@@ -8,6 +8,9 @@ class ReconciliationApiProvider extends BaseProvider {
|
|
|
8
8
|
get _cache() {
|
|
9
9
|
return cache[this.uri];
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
11
14
|
_prepare() {
|
|
12
15
|
cache[this.uri] = [];
|
|
13
16
|
this.has.mappings = true;
|
|
@@ -15,6 +18,15 @@ class ReconciliationApiProvider extends BaseProvider {
|
|
|
15
18
|
this.has[c] = false;
|
|
16
19
|
});
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns a list of mappings suggestions.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} config
|
|
25
|
+
* @param {Object} config.from JSKOS concept on from side
|
|
26
|
+
* @param {Object} config.to JSKOS concept on to side
|
|
27
|
+
* @param {Object} config.mode mappings mode
|
|
28
|
+
* @returns {Object[]} array of JSKOS mapping objects
|
|
29
|
+
*/
|
|
18
30
|
async getMappings({ from, to, mode, ...config }) {
|
|
19
31
|
let schemes = [];
|
|
20
32
|
if (_.isArray(this.schemes)) {
|
|
@@ -99,6 +111,15 @@ class ReconciliationApiProvider extends BaseProvider {
|
|
|
99
111
|
mappings._url = url;
|
|
100
112
|
return mappings;
|
|
101
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Internal function that either makes an API request or uses a local cache.
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
118
|
+
*
|
|
119
|
+
* @param {Object} config passthrough of config object for axios request
|
|
120
|
+
* @param {string[]} labels list of labels to get results for
|
|
121
|
+
* @param {string} language language of labels
|
|
122
|
+
*/
|
|
102
123
|
async _getReconciliationResults({ labels, language, ...config }) {
|
|
103
124
|
labels = labels.sort();
|
|
104
125
|
let resultsFromCache = this._cache.find((item) => {
|
|
@@ -41,6 +41,14 @@ class SkohubProvider extends BaseProvider {
|
|
|
41
41
|
get _schemeCache() {
|
|
42
42
|
return data[this.uri] && data[this.uri].schemeCache;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} options
|
|
48
|
+
* @param {Object} options.url API URL for BARTOC instance
|
|
49
|
+
* @param {Object} options.scheme scheme for which the config is requested
|
|
50
|
+
* @returns {Object} provider configuration
|
|
51
|
+
*/
|
|
44
52
|
static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
|
|
45
53
|
if (!url || !scheme) {
|
|
46
54
|
return null;
|
|
@@ -170,6 +178,15 @@ class SkohubProvider extends BaseProvider {
|
|
|
170
178
|
concept = await this._loadConcept({ ...config, uri: concept.uri });
|
|
171
179
|
return concept.narrower;
|
|
172
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns concept search results.
|
|
183
|
+
*
|
|
184
|
+
* @param {Object} config
|
|
185
|
+
* @param {string} config.search search string
|
|
186
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
187
|
+
* @param {number} [config.limit=100] maximum number of search results
|
|
188
|
+
* @returns {Array} array of JSKOS concept objects
|
|
189
|
+
*/
|
|
173
190
|
async search({ search, scheme, limit = 100 }) {
|
|
174
191
|
scheme = await this._loadScheme({ scheme });
|
|
175
192
|
if (!scheme || !scheme.uri) {
|
|
@@ -215,6 +232,15 @@ class SkohubProvider extends BaseProvider {
|
|
|
215
232
|
const concepts = await this.getConcepts({ concepts: result.map((uri) => ({ uri })) });
|
|
216
233
|
return concepts.slice(0, limit);
|
|
217
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Returns suggestion result in OpenSearch Suggest Format.
|
|
237
|
+
*
|
|
238
|
+
* @param {Object} config
|
|
239
|
+
* @param {string} config.search search string
|
|
240
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
241
|
+
* @param {number} [config.limit=100] maximum number of search results
|
|
242
|
+
* @returns {Array} result in OpenSearch Suggest Format
|
|
243
|
+
*/
|
|
218
244
|
async suggest(config) {
|
|
219
245
|
config._raw = true;
|
|
220
246
|
const concepts = await this.search(config);
|