cocoda-sdk 3.4.13 → 3.6.0

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.
@@ -13,7 +13,7 @@ class BaseProvider {
13
13
  this._jskos = registry;
14
14
  this.axios = axios.create({
15
15
  // TODO: Decide on timeout value
16
- timeout: 2e4
16
+ timeout: 2e5
17
17
  });
18
18
  this._path = typeof window !== "undefined" && window.location.pathname;
19
19
  this.has = {};
@@ -158,6 +158,7 @@ class BaseProvider {
158
158
  }
159
159
  throw new errors.NetworkError({ relatedError: error });
160
160
  } else {
161
+ console.error(error);
161
162
  throw new errors.CDKError({ relatedError: error });
162
163
  }
163
164
  }
@@ -291,6 +292,34 @@ class BaseProvider {
291
292
  }
292
293
  }, config);
293
294
  }
295
+ /**
296
+ * Returns suggestion result in OpenSearch Suggest Format.
297
+ *
298
+ * @param {Object} config
299
+ * @param {string} config.search search string
300
+ * @param {Object} [config.scheme] concept scheme to search in
301
+ * @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
302
+ * @param {string[]} [config.types=[]] list of type URIs
303
+ * @returns {Array} result in OpenSearch Suggest Format
304
+ */
305
+ async suggest(config) {
306
+ config._raw = true;
307
+ const concepts = await this.search(config);
308
+ const result = [config.search, [], [], []];
309
+ for (let concept of concepts) {
310
+ const notation = jskos.notation(concept);
311
+ const label = jskos.prefLabel(concept);
312
+ result[1].push((notation ? notation + " " : "") + label);
313
+ result[2].push("");
314
+ result[3].push(concept.uri);
315
+ }
316
+ if (concepts._totalCount != void 0) {
317
+ result._totalCount = concepts._totalCount;
318
+ } else {
319
+ result._totalCount = concepts.length;
320
+ }
321
+ return result;
322
+ }
294
323
  /**
295
324
  * Returns whether a user is authorized for a certain request.
296
325
  *
@@ -4,6 +4,8 @@ import * as errors from "../errors/index.js";
4
4
  import * as utils from "../utils/index.js";
5
5
  import jskos from "jskos-tools";
6
6
  class ConceptApiProvider extends BaseProvider {
7
+ static providerName = "ConceptApi";
8
+ static providerType = "http://bartoc.org/api-type/jskos";
7
9
  static supports = {
8
10
  schemes: true,
9
11
  top: true,
@@ -185,7 +187,8 @@ class ConceptApiProvider extends BaseProvider {
185
187
  * @returns {Object[]} array of JSKOS concept objects
186
188
  */
187
189
  async getConcepts({ concepts, ...config }) {
188
- if (this.has.data === false) {
190
+ const url = this._api.concepts || this._api.data;
191
+ if (!url) {
189
192
  throw new errors.MissingApiUrlError();
190
193
  }
191
194
  if (!concepts) {
@@ -198,7 +201,7 @@ class ConceptApiProvider extends BaseProvider {
198
201
  return this.axios({
199
202
  ...config,
200
203
  method: "get",
201
- url: this._api.data,
204
+ url,
202
205
  params: {
203
206
  ...this._defaultParams,
204
207
  // ? What should the default limit be?
@@ -216,24 +219,29 @@ class ConceptApiProvider extends BaseProvider {
216
219
  * @returns {Object[]} array of JSKOS concept objects
217
220
  */
218
221
  async getNarrower({ concept, ...config }) {
219
- if (!this._api.narrower) {
220
- throw new errors.MissingApiUrlError();
221
- }
222
222
  if (!concept || !concept.uri) {
223
223
  throw new errors.InvalidOrMissingParameterError({ parameter: "concept" });
224
224
  }
225
- return this.axios({
226
- ...config,
227
- method: "get",
228
- url: this._api.narrower,
229
- params: {
230
- ...this._defaultParams,
231
- // ? What should the default limit be?
232
- limit: 1e4,
233
- ...config.params || {},
234
- uri: concept.uri
235
- }
236
- });
225
+ if (this._api.narrower) {
226
+ return this.axios({
227
+ ...config,
228
+ method: "get",
229
+ url: this._api.narrower,
230
+ params: {
231
+ ...this._defaultParams,
232
+ // ? What should the default limit be?
233
+ limit: 1e4,
234
+ ...config.params || {},
235
+ uri: concept.uri
236
+ }
237
+ });
238
+ } else {
239
+ const conf2 = { params: {}, ...config };
240
+ conf2.params.properties = "narrower";
241
+ const response = await this.getConcepts({ concepts: [concept], ...conf2 });
242
+ const narrower = response[0]?.narrower || [];
243
+ return narrower.length ? this.getConcepts({ concepts: narrower, ...config }) : [];
244
+ }
237
245
  }
238
246
  /**
239
247
  * Returns ancestor concepts for a concept.
@@ -243,24 +251,29 @@ class ConceptApiProvider extends BaseProvider {
243
251
  * @returns {Object[]} array of JSKOS concept objects
244
252
  */
245
253
  async getAncestors({ concept, ...config }) {
246
- if (!this._api.ancestors) {
247
- throw new errors.MissingApiUrlError();
248
- }
249
254
  if (!concept || !concept.uri) {
250
255
  throw new errors.InvalidOrMissingParameterError({ parameter: "concept" });
251
256
  }
252
- return this.axios({
253
- ...config,
254
- method: "get",
255
- url: this._api.ancestors,
256
- params: {
257
- ...this._defaultParams,
258
- // ? What should the default limit be?
259
- limit: 1e4,
260
- ...config.params || {},
261
- uri: concept.uri
262
- }
263
- });
257
+ if (this._api.ancestors) {
258
+ return this.axios({
259
+ ...config,
260
+ method: "get",
261
+ url: this._api.ancestors,
262
+ params: {
263
+ ...this._defaultParams,
264
+ // ? What should the default limit be?
265
+ limit: 1e4,
266
+ ...config.params || {},
267
+ uri: concept.uri
268
+ }
269
+ });
270
+ } else {
271
+ const conf2 = { params: {}, ...config };
272
+ conf2.params.properties = "ancestors";
273
+ const response = await this.getConcepts({ concepts: [concept], ...conf2 });
274
+ const ancestors = response[0]?.ancestors || [];
275
+ return ancestors.length ? this.getConcepts({ concepts: ancestors, ...config }) : [];
276
+ }
264
277
  }
265
278
  /**
266
279
  * Returns suggestion result in OpenSearch Suggest Format.
@@ -401,8 +414,6 @@ class ConceptApiProvider extends BaseProvider {
401
414
  return types;
402
415
  }
403
416
  }
404
- ConceptApiProvider.providerName = "ConceptApi";
405
- ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
406
417
  export {
407
418
  ConceptApiProvider as default
408
419
  };
@@ -0,0 +1,240 @@
1
+ const context_jskos = {
2
+ "@context": {
3
+ uri: "@id",
4
+ type: {
5
+ "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
6
+ "@type": "@id",
7
+ "@container": "@set"
8
+ },
9
+ created: {
10
+ "@id": "http://purl.org/dc/terms/created",
11
+ "@type": "xsd:date"
12
+ },
13
+ issued: {
14
+ "@id": "http://purl.org/dc/terms/issued",
15
+ "@type": "xsd:date"
16
+ },
17
+ modified: {
18
+ "@id": "http://purl.org/dc/terms/modified",
19
+ "@type": "xsd:date"
20
+ },
21
+ creator: {
22
+ "@id": "http://purl.org/dc/terms/creator",
23
+ "@container": "@set"
24
+ },
25
+ contributor: {
26
+ "@id": "http://purl.org/dc/terms/contributor",
27
+ "@container": "@set"
28
+ },
29
+ publisher: {
30
+ "@id": "http://purl.org/dc/terms/publisher",
31
+ "@container": "@set"
32
+ },
33
+ partOf: {
34
+ "@id": "http://purl.org/dc/terms/isPartOf",
35
+ "@container": "@set"
36
+ },
37
+ url: {
38
+ "@id": "http://xmlns.com/foaf/0.1/page",
39
+ "@type": "@id"
40
+ },
41
+ identifier: {
42
+ "@id": "http://purl.org/dc/terms/identifier",
43
+ "@container": "@set"
44
+ },
45
+ notation: {
46
+ "@id": "http://www.w3.org/2004/02/skos/core#notation",
47
+ "@container": "@set"
48
+ },
49
+ prefLabel: {
50
+ "@id": "http://www.w3.org/2004/02/skos/core#prefLabel",
51
+ "@container": "@language"
52
+ },
53
+ altLabel: {
54
+ "@id": "http://www.w3.org/2004/02/skos/core#altLabel",
55
+ "@container": "@language"
56
+ },
57
+ hiddenLabel: {
58
+ "@id": "http://www.w3.org/2004/02/skos/core#hiddenLabel",
59
+ "@container": "@language"
60
+ },
61
+ note: {
62
+ "@id": "http://www.w3.org/2004/02/skos/core#note",
63
+ "@container": "@language"
64
+ },
65
+ scopeNote: {
66
+ "@id": "http://www.w3.org/2004/02/skos/core#scopeNote",
67
+ "@container": "@language"
68
+ },
69
+ definition: {
70
+ "@id": "http://www.w3.org/2004/02/skos/core#definition",
71
+ "@container": "@language"
72
+ },
73
+ example: {
74
+ "@id": "http://www.w3.org/2004/02/skos/core#example",
75
+ "@container": "@language"
76
+ },
77
+ historyNote: {
78
+ "@id": "http://www.w3.org/2004/02/skos/core#historyNote",
79
+ "@container": "@language"
80
+ },
81
+ editorialNote: {
82
+ "@id": "http://www.w3.org/2004/02/skos/core#editorialNote",
83
+ "@container": "@language"
84
+ },
85
+ changeNote: {
86
+ "@id": "http://www.w3.org/2004/02/skos/core#changeNote",
87
+ "@container": "@language"
88
+ },
89
+ subject: {
90
+ "@id": "http://purl.org/dc/terms/subject",
91
+ "@container": "@set"
92
+ },
93
+ subjectOf: {
94
+ "@reverse": "http://purl.org/dc/terms/subject",
95
+ "@container": "@set"
96
+ },
97
+ source: {
98
+ "@id": "http://purl.org/dc/terms/source",
99
+ "@container": "@set"
100
+ },
101
+ depiction: {
102
+ "@id": "http://xmlns.com/foaf/0.1/depiction",
103
+ "@type": "@id",
104
+ "@container": "@set"
105
+ },
106
+ media: {
107
+ "@id": "http://xmlns.com/foaf/0.1/depiction",
108
+ "@context": "http://iiif.io/api/presentation/3/context.json"
109
+ },
110
+ place: {
111
+ "@id": "http://schema.org/location",
112
+ "@container": "@set"
113
+ },
114
+ startPlace: {
115
+ "@id": "http://schema.org/fromLocation",
116
+ "@container": "@set"
117
+ },
118
+ endPlace: {
119
+ "@id": "http://schema.org/toLocation",
120
+ "@container": "@set"
121
+ },
122
+ narrower: {
123
+ "@id": "http://www.w3.org/2004/02/skos/core#narrower",
124
+ "@container": "@set"
125
+ },
126
+ broader: {
127
+ "@id": "http://www.w3.org/2004/02/skos/core#broader",
128
+ "@container": "@set"
129
+ },
130
+ related: {
131
+ "@id": "http://www.w3.org/2004/02/skos/core#related",
132
+ "@container": "@set"
133
+ },
134
+ previous: {
135
+ "@id": "http://rdf-vocabulary.ddialliance.org/xkos#previous",
136
+ "@container": "@set"
137
+ },
138
+ next: {
139
+ "@id": "http://rdf-vocabulary.ddialliance.org/xkos#next",
140
+ "@container": "@set"
141
+ },
142
+ startDate: "http://schema.org/startDate",
143
+ endDate: "http://schema.org/endDate",
144
+ relatedDate: "http://www.w3.org/2000/01/rdf-schema#seeAlso",
145
+ relatedDates: "http://www.w3.org/2000/01/rdf-schema#seeAlso",
146
+ location: {
147
+ "@id": "http://www.opengis.net/ont/geosparql#asGeoJSON",
148
+ "@type": "@json"
149
+ },
150
+ address: "http://schema.org/address",
151
+ street: "http://schema.org/streetAddress",
152
+ ext: "http://schema.org/streetAddress",
153
+ pobox: "http://schema.org/postOfficeBoxNumber",
154
+ locality: "http://schema.org/addressLocality",
155
+ region: "http://schema.org/addressRegion",
156
+ code: "http://schema.org/postalCode",
157
+ country: "http://schema.org/addressCountry",
158
+ ancestors: {
159
+ "@id": "http://www.w3.org/2004/02/skos/core#broaderTransitive",
160
+ "@container": "@set"
161
+ },
162
+ inScheme: {
163
+ "@id": "http://www.w3.org/2004/02/skos/core#inScheme",
164
+ "@container": "@set"
165
+ },
166
+ topConceptOf: {
167
+ "@id": "http://www.w3.org/2004/02/skos/core#topConceptOf",
168
+ "@container": "@set"
169
+ },
170
+ topConcepts: {
171
+ "@id": "http://www.w3.org/2004/02/skos/core#hasTopConcept",
172
+ "@container": "@set"
173
+ },
174
+ versionOf: {
175
+ "@id": "http://purl.org/dc/terms/isVersionOf",
176
+ "@container": "@set"
177
+ },
178
+ extent: "http://purl.org/dc/terms/extent",
179
+ languages: {
180
+ "@id": "http://purl.org/dc/terms/language",
181
+ "@container": "@set"
182
+ },
183
+ license: {
184
+ "@id": "http://purl.org/dc/terms/license",
185
+ "@container": "@set"
186
+ },
187
+ deprecated: "http://www.w3.org/2002/07/owl#deprecated",
188
+ replacedBy: "http://purl.org/dc/terms/isReplacedBy",
189
+ namespace: "http://rdfs.org/ns/void#uriSpace",
190
+ uriPattern: "http://rdfs.org/ns/void#voidRegexPattern",
191
+ fromScheme: "http://rdfs.org/ns/void#subjectsTarget",
192
+ toScheme: "http://rdfs.org/ns/void#objectsTarget",
193
+ memberList: {
194
+ "@id": "http://www.loc.gov/mads/rdf/v1#componentList",
195
+ "@container": "@list"
196
+ },
197
+ memberSet: {
198
+ "@id": "http://www.w3.org/2004/02/skos/core#member",
199
+ "@container": "@set"
200
+ },
201
+ memberChoice: {
202
+ "@id": "http://www.w3.org/2004/02/skos/core#member",
203
+ "@container": "@set"
204
+ },
205
+ count: "http://rdfs.org/ns/void#entities",
206
+ distributions: {
207
+ "@id": "http://www.w3.org/ns/dcat#distribution",
208
+ "@container": "@set"
209
+ },
210
+ download: "http://www.w3.org/ns/dcat#downloadURL",
211
+ accessURL: "http://www.w3.org/ns/dcat#accessURL",
212
+ checksum: "http://spdx.org/rdf/terms#checksum",
213
+ mimetype: "http://www.w3.org/ns/dcat#mediaType",
214
+ packageFormat: "http://www.w3.org/ns/dcat#packageFormat",
215
+ compressFormat: "http://www.w3.org/ns/dcat#compressFormat",
216
+ format: "http://purl.org/dc/terms/format",
217
+ size: "http://www.w3.org/ns/dcat#byteSize",
218
+ value: "http://spdx.org/rdf/terms#checksumValue",
219
+ qualifiedRelations: "@nest",
220
+ qualifiedLiterals: "@nest",
221
+ qualifiedDates: "@nest",
222
+ resource: "http://www.w3.org/1999/02/22-rdf-syntax-ns#object",
223
+ date: "http://www.w3.org/1999/02/22-rdf-syntax-ns#object",
224
+ literal: {
225
+ "@id": "http://www.w3.org/2008/05/skos-xl#literalForm",
226
+ "@context": {
227
+ string: "@value",
228
+ language: "@language"
229
+ }
230
+ },
231
+ rank: "http://wikiba.se/ontology#rank",
232
+ version: "http://www.w3.org/2002/07/owl#versionInfo",
233
+ justification: "https://w3id.org/sssom/mapping_justification"
234
+ }
235
+ };
236
+ var context_jskos_default = context_jskos;
237
+ export {
238
+ context_jskos,
239
+ context_jskos_default as default
240
+ };
@@ -0,0 +1,59 @@
1
+ const context_mod = {
2
+ "@context": {
3
+ subject: "http://purl.org/dc/terms/subject",
4
+ type: {
5
+ "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
6
+ "@type": "@id"
7
+ },
8
+ source_name: "http://www.w3.org/2004/02/skos/core#notation",
9
+ label: "http://www.w3.org/2004/02/skos/core#prefLabel",
10
+ synonyms: {
11
+ "@id": "http://www.w3.org/2004/02/skos/core#altLabel",
12
+ "@container": "@set"
13
+ },
14
+ descriptions: {
15
+ "@id": "http://www.w3.org/2004/02/skos/core#definition",
16
+ "@container": "@language"
17
+ },
18
+ language: {
19
+ "@id": "http://purl.org/dc/terms/language",
20
+ "@container": "@set"
21
+ },
22
+ iri: "@id",
23
+ identifier: "http://purl.org/dc/terms/identifier",
24
+ source: "http://purl.org/dc/terms/source",
25
+ source_url: "http://rdfs.org/ns/void#uriSpace",
26
+ landingPage: {
27
+ "@id": "http://xmlns.com/foaf/0.1/page",
28
+ "@type": "@id"
29
+ },
30
+ version: "http://www.w3.org/2002/07/owl#versionInfo",
31
+ modified: {
32
+ "@id": "http://purl.org/dc/terms/modified",
33
+ "@type": "xsd:date"
34
+ },
35
+ created: {
36
+ "@id": "http://purl.org/dc/terms/created",
37
+ "@type": "xsd:date"
38
+ },
39
+ hasFormat: "http://purl.org/dc/terms/format",
40
+ license: "http://purl.org/dc/terms/license",
41
+ creator: "http://purl.org/dc/terms/creator",
42
+ contributor: "http://purl.org/dc/terms/contributor",
43
+ publisher: "http://purl.org/dc/terms/publisher",
44
+ released: {
45
+ "@id": "http://purl.org/dc/terms/issued",
46
+ "@type": "xsd:date"
47
+ },
48
+ children: {
49
+ "@id": "http://www.w3.org/2004/02/skos/core#narrower",
50
+ "@container": "@set"
51
+ },
52
+ short_form: "http://www.w3.org/2004/02/skos/core#notation"
53
+ }
54
+ };
55
+ var context_mod_default = context_mod;
56
+ export {
57
+ context_mod,
58
+ context_mod_default as default
59
+ };
@@ -9,6 +9,8 @@ import SkosmosApiProvider from "./skosmos-api-provider.js";
9
9
  import LocApiProvider from "./loc-api-provider.js";
10
10
  import SkohubProvider from "./skohub-provider.js";
11
11
  import LobidApiProvider from "./lobid-api-provider.js";
12
+ import ModApiProvider from "./mod-api-provider.js";
13
+ import OlsApiProvider from "./ols-api-provider.js";
12
14
  import MyCoReProvider from "./mycore-provider.js";
13
15
  import NoTApiProvider from "./not-api-provider.js";
14
16
  export {
@@ -19,9 +21,11 @@ export {
19
21
  LocApiProvider,
20
22
  LocalMappingsProvider,
21
23
  MappingsApiProvider,
24
+ ModApiProvider,
22
25
  MyCoReProvider,
23
26
  NoTApiProvider,
24
27
  OccurrencesApiProvider,
28
+ OlsApiProvider,
25
29
  ReconciliationApiProvider,
26
30
  SkohubProvider,
27
31
  SkosmosApiProvider