@shaclmate/shacl-ast 2.0.23 → 3.0.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.
package/dist/generated.js CHANGED
@@ -1,4 +1,5 @@
1
- import { DataFactory as dataFactory } from "n3";
1
+ import { StoreFactory as _DatasetFactory, DataFactory as dataFactory, } from "n3";
2
+ const datasetFactory = new _DatasetFactory();
2
3
  import * as purify from "purify-ts";
3
4
  import * as rdfjsResource from "rdfjs-resource";
4
5
  import { PropertyPath } from "./PropertyPath.js";
@@ -37,95 +38,150 @@ export var BaseShaclCoreShapeStatic;
37
38
  $Identifier.fromString = fromString;
38
39
  $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
39
40
  })($Identifier = BaseShaclCoreShapeStatic.$Identifier || (BaseShaclCoreShapeStatic.$Identifier = {}));
40
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSetParameter, resource: $resource,
41
+ function $fromRdf(resource, options) {
42
+ let { ignoreRdfType = false, languageIn, objectSet, ...context } = options ?? {};
43
+ if (!objectSet) {
44
+ objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
45
+ }
46
+ return ShaclCoreNodeShape.$fromRdf(resource, {
47
+ ...context,
48
+ ignoreRdfType: false,
49
+ objectSet,
50
+ }).altLazy(() => ShaclCorePropertyShape.$fromRdf(resource, {
51
+ ...context,
52
+ ignoreRdfType: false,
53
+ objectSet,
54
+ }));
55
+ }
56
+ BaseShaclCoreShapeStatic.$fromRdf = $fromRdf;
57
+ function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSet, resource: $resource,
41
58
  // @ts-ignore
42
59
  ...$context }) {
43
60
  const $identifier = $resource.identifier;
44
- const _andEither = purify.Either.sequence($resource
45
- .values(BaseShaclCoreShapeStatic.$properties.and["identifier"], { unique: true })
46
- .map((item) => item
47
- .toValues()
48
- .head()
49
- .chain((value) => value.toList())
50
- .chain((values) => purify.Either.sequence(values.map((value) => value
51
- .toValues()
52
- .head()
53
- .chain((value) => value.toIdentifier()))))));
61
+ const _andEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.and["identifier"], { unique: true }))
62
+ .chain((values) => values.chainMap((value) => value.toList()))
63
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
64
+ objects: valueList,
65
+ predicate: BaseShaclCoreShapeStatic.$properties.and["identifier"],
66
+ subject: $resource,
67
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
68
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
69
+ .map((values) => values.toArray())
70
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
71
+ object: valuesArray,
72
+ predicate: BaseShaclCoreShapeStatic.$properties.and["identifier"],
73
+ subject: $resource,
74
+ }))
75
+ .chain((values) => values.head());
54
76
  if (_andEither.isLeft()) {
55
77
  return _andEither;
56
78
  }
57
79
  const and = _andEither.unsafeCoerce();
58
- const _classesEither = purify.Either.sequence($resource
59
- .values(BaseShaclCoreShapeStatic.$properties.classes["identifier"], { unique: true })
60
- .map((item) => item
61
- .toValues()
62
- .head()
63
- .chain((value) => value.toIri())));
80
+ const _classesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.classes["identifier"], { unique: true }))
81
+ .chain((values) => values.chainMap((value) => value.toIri()))
82
+ .map((values) => values.toArray())
83
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
84
+ object: valuesArray,
85
+ predicate: BaseShaclCoreShapeStatic.$properties.classes["identifier"],
86
+ subject: $resource,
87
+ }))
88
+ .chain((values) => values.head());
64
89
  if (_classesEither.isLeft()) {
65
90
  return _classesEither;
66
91
  }
67
92
  const classes = _classesEither.unsafeCoerce();
68
- const _commentsEither = purify.Either.sequence($resource
69
- .values(BaseShaclCoreShapeStatic.$properties.comments["identifier"], { unique: true })
70
- .map((item) => item
71
- .toValues()
72
- .filter((_value) => {
73
- const _languageInOrDefault = $languageIn ?? [];
74
- if (_languageInOrDefault.length === 0) {
75
- return true;
76
- }
77
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
78
- if (typeof _valueLiteral === "undefined") {
79
- return false;
80
- }
81
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
93
+ const _commentsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.comments["identifier"], { unique: true }))
94
+ .chain((values) => {
95
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
96
+ if (literalValuesEither.isLeft()) {
97
+ return literalValuesEither;
98
+ }
99
+ const literalValues = literalValuesEither.unsafeCoerce();
100
+ const nonUniqueLanguageIn = $languageIn ?? [];
101
+ if (nonUniqueLanguageIn.length === 0) {
102
+ return purify.Either.of(literalValues);
103
+ }
104
+ let uniqueLanguageIn;
105
+ if (nonUniqueLanguageIn.length === 1) {
106
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
107
+ }
108
+ else {
109
+ uniqueLanguageIn = [];
110
+ for (const languageIn of nonUniqueLanguageIn) {
111
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
112
+ uniqueLanguageIn.push(languageIn);
113
+ }
114
+ }
115
+ }
116
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
117
+ // Within a languageIn the literals may be in any order.
118
+ let filteredLiteralValues;
119
+ for (const languageIn of uniqueLanguageIn) {
120
+ if (!filteredLiteralValues) {
121
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
122
+ }
123
+ else {
124
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
125
+ .filter((value) => value.language === languageIn)
126
+ .toArray());
127
+ }
128
+ }
129
+ return purify.Either.of(filteredLiteralValues);
82
130
  })
83
- .head()
84
- .chain((value) => value.toLiteral())));
131
+ .map((values) => values.toArray())
132
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
133
+ object: valuesArray,
134
+ predicate: BaseShaclCoreShapeStatic.$properties.comments["identifier"],
135
+ subject: $resource,
136
+ }))
137
+ .chain((values) => values.head());
85
138
  if (_commentsEither.isLeft()) {
86
139
  return _commentsEither;
87
140
  }
88
141
  const comments = _commentsEither.unsafeCoerce();
89
- const _datatypeEither = $resource
90
- .values(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], { unique: true })
91
- .head()
92
- .chain((value) => value.toIri())
93
- .map((value) => purify.Maybe.of(value))
94
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
95
- ? purify.Right(purify.Maybe.empty())
96
- : purify.Left(error));
142
+ const _datatypeEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], { unique: true }))
143
+ .chain((values) => values.chainMap((value) => value.toIri()))
144
+ .map((values) => values.length > 0
145
+ ? values.map((value) => purify.Maybe.of(value))
146
+ : rdfjsResource.Resource.Values.fromValue({
147
+ object: purify.Maybe.empty(),
148
+ predicate: BaseShaclCoreShapeStatic.$properties.datatype["identifier"],
149
+ subject: $resource,
150
+ }))
151
+ .chain((values) => values.head());
97
152
  if (_datatypeEither.isLeft()) {
98
153
  return _datatypeEither;
99
154
  }
100
155
  const datatype = _datatypeEither.unsafeCoerce();
101
- const _deactivatedEither = $resource
102
- .values(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], { unique: true })
103
- .head()
104
- .chain((value) => value.toBoolean())
105
- .map((value) => purify.Maybe.of(value))
106
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
107
- ? purify.Right(purify.Maybe.empty())
108
- : purify.Left(error));
156
+ const _deactivatedEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], { unique: true }))
157
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
158
+ .map((values) => values.length > 0
159
+ ? values.map((value) => purify.Maybe.of(value))
160
+ : rdfjsResource.Resource.Values.fromValue({
161
+ object: purify.Maybe.empty(),
162
+ predicate: BaseShaclCoreShapeStatic.$properties.deactivated["identifier"],
163
+ subject: $resource,
164
+ }))
165
+ .chain((values) => values.head());
109
166
  if (_deactivatedEither.isLeft()) {
110
167
  return _deactivatedEither;
111
168
  }
112
169
  const deactivated = _deactivatedEither.unsafeCoerce();
113
- const _flagsEither = purify.Either.sequence($resource
114
- .values(BaseShaclCoreShapeStatic.$properties.flags["identifier"], { unique: true })
115
- .map((item) => item
116
- .toValues()
117
- .head()
118
- .chain((value) => value.toString())));
170
+ const _flagsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.flags["identifier"], { unique: true }))
171
+ .chain((values) => values.chainMap((value) => value.toString()))
172
+ .map((values) => values.toArray())
173
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
174
+ object: valuesArray,
175
+ predicate: BaseShaclCoreShapeStatic.$properties.flags["identifier"],
176
+ subject: $resource,
177
+ }))
178
+ .chain((values) => values.head());
119
179
  if (_flagsEither.isLeft()) {
120
180
  return _flagsEither;
121
181
  }
122
182
  const flags = _flagsEither.unsafeCoerce();
123
- const _hasValuesEither = purify.Either.sequence($resource
124
- .values(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], { unique: true })
125
- .map((item) => item
126
- .toValues()
127
- .head()
128
- .chain((value) => purify.Either.of(value.toTerm()).chain((term) => {
183
+ const _hasValuesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], { unique: true }))
184
+ .chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
129
185
  switch (term.termType) {
130
186
  case "Literal":
131
187
  case "NamedNode":
@@ -138,19 +194,25 @@ export var BaseShaclCoreShapeStatic;
138
194
  predicate: BaseShaclCoreShapeStatic.$properties.hasValues["identifier"],
139
195
  }));
140
196
  }
141
- }))));
197
+ })))
198
+ .map((values) => values.toArray())
199
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
200
+ object: valuesArray,
201
+ predicate: BaseShaclCoreShapeStatic.$properties.hasValues["identifier"],
202
+ subject: $resource,
203
+ }))
204
+ .chain((values) => values.head());
142
205
  if (_hasValuesEither.isLeft()) {
143
206
  return _hasValuesEither;
144
207
  }
145
208
  const hasValues = _hasValuesEither.unsafeCoerce();
146
- const _in_Either = $resource
147
- .values(BaseShaclCoreShapeStatic.$properties.in_["identifier"], { unique: true })
148
- .head()
149
- .chain((value) => value.toList())
150
- .chain((values) => purify.Either.sequence(values.map((value) => value
151
- .toValues()
152
- .head()
153
- .chain((value) => purify.Either.of(value.toTerm()).chain((term) => {
209
+ const _in_Either = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.in_["identifier"], { unique: true }))
210
+ .chain((values) => values.chainMap((value) => value.toList()))
211
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
212
+ objects: valueList,
213
+ predicate: BaseShaclCoreShapeStatic.$properties.in_["identifier"],
214
+ subject: $resource,
215
+ })).chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
154
216
  switch (term.termType) {
155
217
  case "Literal":
156
218
  case "NamedNode":
@@ -164,207 +226,368 @@ export var BaseShaclCoreShapeStatic;
164
226
  }));
165
227
  }
166
228
  })))))
167
- .map((value) => purify.Maybe.of(value))
168
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
169
- ? purify.Right(purify.Maybe.empty())
170
- : purify.Left(error));
229
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
230
+ .map((values) => values.length > 0
231
+ ? values.map((value) => purify.Maybe.of(value))
232
+ : rdfjsResource.Resource.Values.fromValue({
233
+ object: purify.Maybe.empty(),
234
+ predicate: BaseShaclCoreShapeStatic.$properties.in_["identifier"],
235
+ subject: $resource,
236
+ }))
237
+ .chain((values) => values.head());
171
238
  if (_in_Either.isLeft()) {
172
239
  return _in_Either;
173
240
  }
174
241
  const in_ = _in_Either.unsafeCoerce();
175
- const _isDefinedByEither = $resource
176
- .values(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], { unique: true })
177
- .head()
178
- .chain((value) => value.toIdentifier())
179
- .map((value) => purify.Maybe.of(value))
180
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
181
- ? purify.Right(purify.Maybe.empty())
182
- : purify.Left(error));
242
+ const _isDefinedByEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], { unique: true }))
243
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
244
+ .map((values) => values.length > 0
245
+ ? values.map((value) => purify.Maybe.of(value))
246
+ : rdfjsResource.Resource.Values.fromValue({
247
+ object: purify.Maybe.empty(),
248
+ predicate: BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"],
249
+ subject: $resource,
250
+ }))
251
+ .chain((values) => values.head());
183
252
  if (_isDefinedByEither.isLeft()) {
184
253
  return _isDefinedByEither;
185
254
  }
186
255
  const isDefinedBy = _isDefinedByEither.unsafeCoerce();
187
- const _labelsEither = purify.Either.sequence($resource
188
- .values(BaseShaclCoreShapeStatic.$properties.labels["identifier"], { unique: true })
189
- .map((item) => item
190
- .toValues()
191
- .filter((_value) => {
192
- const _languageInOrDefault = $languageIn ?? [];
193
- if (_languageInOrDefault.length === 0) {
194
- return true;
195
- }
196
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
197
- if (typeof _valueLiteral === "undefined") {
198
- return false;
199
- }
200
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
256
+ const _labelsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.labels["identifier"], { unique: true }))
257
+ .chain((values) => {
258
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
259
+ if (literalValuesEither.isLeft()) {
260
+ return literalValuesEither;
261
+ }
262
+ const literalValues = literalValuesEither.unsafeCoerce();
263
+ const nonUniqueLanguageIn = $languageIn ?? [];
264
+ if (nonUniqueLanguageIn.length === 0) {
265
+ return purify.Either.of(literalValues);
266
+ }
267
+ let uniqueLanguageIn;
268
+ if (nonUniqueLanguageIn.length === 1) {
269
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
270
+ }
271
+ else {
272
+ uniqueLanguageIn = [];
273
+ for (const languageIn of nonUniqueLanguageIn) {
274
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
275
+ uniqueLanguageIn.push(languageIn);
276
+ }
277
+ }
278
+ }
279
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
280
+ // Within a languageIn the literals may be in any order.
281
+ let filteredLiteralValues;
282
+ for (const languageIn of uniqueLanguageIn) {
283
+ if (!filteredLiteralValues) {
284
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
285
+ }
286
+ else {
287
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
288
+ .filter((value) => value.language === languageIn)
289
+ .toArray());
290
+ }
291
+ }
292
+ return purify.Either.of(filteredLiteralValues);
201
293
  })
202
- .head()
203
- .chain((value) => value.toLiteral())));
294
+ .map((values) => values.toArray())
295
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
296
+ object: valuesArray,
297
+ predicate: BaseShaclCoreShapeStatic.$properties.labels["identifier"],
298
+ subject: $resource,
299
+ }))
300
+ .chain((values) => values.head());
204
301
  if (_labelsEither.isLeft()) {
205
302
  return _labelsEither;
206
303
  }
207
304
  const labels = _labelsEither.unsafeCoerce();
208
- const _languageInEither = $resource
209
- .values(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], { unique: true })
210
- .head()
211
- .chain((value) => value.toList())
212
- .chain((values) => purify.Either.sequence(values.map((value) => value
213
- .toValues()
214
- .head()
215
- .chain((value) => value.toString()))))
216
- .map((value) => purify.Maybe.of(value))
217
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
218
- ? purify.Right(purify.Maybe.empty())
219
- : purify.Left(error));
305
+ const _languageInEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], { unique: true }))
306
+ .chain((values) => values.chainMap((value) => value.toList()))
307
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
308
+ objects: valueList,
309
+ predicate: BaseShaclCoreShapeStatic.$properties.languageIn["identifier"],
310
+ subject: $resource,
311
+ })).chain((values) => values.chainMap((value) => value.toString()))))
312
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
313
+ .map((values) => values.length > 0
314
+ ? values.map((value) => purify.Maybe.of(value))
315
+ : rdfjsResource.Resource.Values.fromValue({
316
+ object: purify.Maybe.empty(),
317
+ predicate: BaseShaclCoreShapeStatic.$properties.languageIn["identifier"],
318
+ subject: $resource,
319
+ }))
320
+ .chain((values) => values.head());
220
321
  if (_languageInEither.isLeft()) {
221
322
  return _languageInEither;
222
323
  }
223
324
  const languageIn = _languageInEither.unsafeCoerce();
224
- const _maxCountEither = $resource
225
- .values(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], { unique: true })
226
- .head()
227
- .chain((value) => value.toNumber())
228
- .map((value) => purify.Maybe.of(value))
229
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
230
- ? purify.Right(purify.Maybe.empty())
231
- : purify.Left(error));
325
+ const _maxCountEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], { unique: true }))
326
+ .chain((values) => values.chainMap((value) => value.toNumber()))
327
+ .map((values) => values.length > 0
328
+ ? values.map((value) => purify.Maybe.of(value))
329
+ : rdfjsResource.Resource.Values.fromValue({
330
+ object: purify.Maybe.empty(),
331
+ predicate: BaseShaclCoreShapeStatic.$properties.maxCount["identifier"],
332
+ subject: $resource,
333
+ }))
334
+ .chain((values) => values.head());
232
335
  if (_maxCountEither.isLeft()) {
233
336
  return _maxCountEither;
234
337
  }
235
338
  const maxCount = _maxCountEither.unsafeCoerce();
236
- const _maxExclusiveEither = $resource
237
- .values(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], { unique: true })
238
- .filter((_value) => {
239
- const _languageInOrDefault = $languageIn ?? [];
240
- if (_languageInOrDefault.length === 0) {
241
- return true;
242
- }
243
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
244
- if (typeof _valueLiteral === "undefined") {
245
- return false;
246
- }
247
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
339
+ const _maxExclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], {
340
+ unique: true,
341
+ }))
342
+ .chain((values) => {
343
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
344
+ if (literalValuesEither.isLeft()) {
345
+ return literalValuesEither;
346
+ }
347
+ const literalValues = literalValuesEither.unsafeCoerce();
348
+ const nonUniqueLanguageIn = $languageIn ?? [];
349
+ if (nonUniqueLanguageIn.length === 0) {
350
+ return purify.Either.of(literalValues);
351
+ }
352
+ let uniqueLanguageIn;
353
+ if (nonUniqueLanguageIn.length === 1) {
354
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
355
+ }
356
+ else {
357
+ uniqueLanguageIn = [];
358
+ for (const languageIn of nonUniqueLanguageIn) {
359
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
360
+ uniqueLanguageIn.push(languageIn);
361
+ }
362
+ }
363
+ }
364
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
365
+ // Within a languageIn the literals may be in any order.
366
+ let filteredLiteralValues;
367
+ for (const languageIn of uniqueLanguageIn) {
368
+ if (!filteredLiteralValues) {
369
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
370
+ }
371
+ else {
372
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
373
+ .filter((value) => value.language === languageIn)
374
+ .toArray());
375
+ }
376
+ }
377
+ return purify.Either.of(filteredLiteralValues);
248
378
  })
249
- .head()
250
- .chain((value) => value.toLiteral())
251
- .map((value) => purify.Maybe.of(value))
252
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
253
- ? purify.Right(purify.Maybe.empty())
254
- : purify.Left(error));
379
+ .map((values) => values.length > 0
380
+ ? values.map((value) => purify.Maybe.of(value))
381
+ : rdfjsResource.Resource.Values.fromValue({
382
+ object: purify.Maybe.empty(),
383
+ predicate: BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"],
384
+ subject: $resource,
385
+ }))
386
+ .chain((values) => values.head());
255
387
  if (_maxExclusiveEither.isLeft()) {
256
388
  return _maxExclusiveEither;
257
389
  }
258
390
  const maxExclusive = _maxExclusiveEither.unsafeCoerce();
259
- const _maxInclusiveEither = $resource
260
- .values(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], { unique: true })
261
- .filter((_value) => {
262
- const _languageInOrDefault = $languageIn ?? [];
263
- if (_languageInOrDefault.length === 0) {
264
- return true;
265
- }
266
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
267
- if (typeof _valueLiteral === "undefined") {
268
- return false;
269
- }
270
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
391
+ const _maxInclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], {
392
+ unique: true,
393
+ }))
394
+ .chain((values) => {
395
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
396
+ if (literalValuesEither.isLeft()) {
397
+ return literalValuesEither;
398
+ }
399
+ const literalValues = literalValuesEither.unsafeCoerce();
400
+ const nonUniqueLanguageIn = $languageIn ?? [];
401
+ if (nonUniqueLanguageIn.length === 0) {
402
+ return purify.Either.of(literalValues);
403
+ }
404
+ let uniqueLanguageIn;
405
+ if (nonUniqueLanguageIn.length === 1) {
406
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
407
+ }
408
+ else {
409
+ uniqueLanguageIn = [];
410
+ for (const languageIn of nonUniqueLanguageIn) {
411
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
412
+ uniqueLanguageIn.push(languageIn);
413
+ }
414
+ }
415
+ }
416
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
417
+ // Within a languageIn the literals may be in any order.
418
+ let filteredLiteralValues;
419
+ for (const languageIn of uniqueLanguageIn) {
420
+ if (!filteredLiteralValues) {
421
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
422
+ }
423
+ else {
424
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
425
+ .filter((value) => value.language === languageIn)
426
+ .toArray());
427
+ }
428
+ }
429
+ return purify.Either.of(filteredLiteralValues);
271
430
  })
272
- .head()
273
- .chain((value) => value.toLiteral())
274
- .map((value) => purify.Maybe.of(value))
275
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
276
- ? purify.Right(purify.Maybe.empty())
277
- : purify.Left(error));
431
+ .map((values) => values.length > 0
432
+ ? values.map((value) => purify.Maybe.of(value))
433
+ : rdfjsResource.Resource.Values.fromValue({
434
+ object: purify.Maybe.empty(),
435
+ predicate: BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"],
436
+ subject: $resource,
437
+ }))
438
+ .chain((values) => values.head());
278
439
  if (_maxInclusiveEither.isLeft()) {
279
440
  return _maxInclusiveEither;
280
441
  }
281
442
  const maxInclusive = _maxInclusiveEither.unsafeCoerce();
282
- const _maxLengthEither = $resource
283
- .values(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], { unique: true })
284
- .head()
285
- .chain((value) => value.toNumber())
286
- .map((value) => purify.Maybe.of(value))
287
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
288
- ? purify.Right(purify.Maybe.empty())
289
- : purify.Left(error));
443
+ const _maxLengthEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], { unique: true }))
444
+ .chain((values) => values.chainMap((value) => value.toNumber()))
445
+ .map((values) => values.length > 0
446
+ ? values.map((value) => purify.Maybe.of(value))
447
+ : rdfjsResource.Resource.Values.fromValue({
448
+ object: purify.Maybe.empty(),
449
+ predicate: BaseShaclCoreShapeStatic.$properties.maxLength["identifier"],
450
+ subject: $resource,
451
+ }))
452
+ .chain((values) => values.head());
290
453
  if (_maxLengthEither.isLeft()) {
291
454
  return _maxLengthEither;
292
455
  }
293
456
  const maxLength = _maxLengthEither.unsafeCoerce();
294
- const _minCountEither = $resource
295
- .values(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], { unique: true })
296
- .head()
297
- .chain((value) => value.toNumber())
298
- .map((value) => purify.Maybe.of(value))
299
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
300
- ? purify.Right(purify.Maybe.empty())
301
- : purify.Left(error));
457
+ const _minCountEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], { unique: true }))
458
+ .chain((values) => values.chainMap((value) => value.toNumber()))
459
+ .map((values) => values.length > 0
460
+ ? values.map((value) => purify.Maybe.of(value))
461
+ : rdfjsResource.Resource.Values.fromValue({
462
+ object: purify.Maybe.empty(),
463
+ predicate: BaseShaclCoreShapeStatic.$properties.minCount["identifier"],
464
+ subject: $resource,
465
+ }))
466
+ .chain((values) => values.head());
302
467
  if (_minCountEither.isLeft()) {
303
468
  return _minCountEither;
304
469
  }
305
470
  const minCount = _minCountEither.unsafeCoerce();
306
- const _minExclusiveEither = $resource
307
- .values(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], { unique: true })
308
- .filter((_value) => {
309
- const _languageInOrDefault = $languageIn ?? [];
310
- if (_languageInOrDefault.length === 0) {
311
- return true;
312
- }
313
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
314
- if (typeof _valueLiteral === "undefined") {
315
- return false;
316
- }
317
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
471
+ const _minExclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], {
472
+ unique: true,
473
+ }))
474
+ .chain((values) => {
475
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
476
+ if (literalValuesEither.isLeft()) {
477
+ return literalValuesEither;
478
+ }
479
+ const literalValues = literalValuesEither.unsafeCoerce();
480
+ const nonUniqueLanguageIn = $languageIn ?? [];
481
+ if (nonUniqueLanguageIn.length === 0) {
482
+ return purify.Either.of(literalValues);
483
+ }
484
+ let uniqueLanguageIn;
485
+ if (nonUniqueLanguageIn.length === 1) {
486
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
487
+ }
488
+ else {
489
+ uniqueLanguageIn = [];
490
+ for (const languageIn of nonUniqueLanguageIn) {
491
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
492
+ uniqueLanguageIn.push(languageIn);
493
+ }
494
+ }
495
+ }
496
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
497
+ // Within a languageIn the literals may be in any order.
498
+ let filteredLiteralValues;
499
+ for (const languageIn of uniqueLanguageIn) {
500
+ if (!filteredLiteralValues) {
501
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
502
+ }
503
+ else {
504
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
505
+ .filter((value) => value.language === languageIn)
506
+ .toArray());
507
+ }
508
+ }
509
+ return purify.Either.of(filteredLiteralValues);
318
510
  })
319
- .head()
320
- .chain((value) => value.toLiteral())
321
- .map((value) => purify.Maybe.of(value))
322
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
323
- ? purify.Right(purify.Maybe.empty())
324
- : purify.Left(error));
511
+ .map((values) => values.length > 0
512
+ ? values.map((value) => purify.Maybe.of(value))
513
+ : rdfjsResource.Resource.Values.fromValue({
514
+ object: purify.Maybe.empty(),
515
+ predicate: BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"],
516
+ subject: $resource,
517
+ }))
518
+ .chain((values) => values.head());
325
519
  if (_minExclusiveEither.isLeft()) {
326
520
  return _minExclusiveEither;
327
521
  }
328
522
  const minExclusive = _minExclusiveEither.unsafeCoerce();
329
- const _minInclusiveEither = $resource
330
- .values(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], { unique: true })
331
- .filter((_value) => {
332
- const _languageInOrDefault = $languageIn ?? [];
333
- if (_languageInOrDefault.length === 0) {
334
- return true;
335
- }
336
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
337
- if (typeof _valueLiteral === "undefined") {
338
- return false;
339
- }
340
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
523
+ const _minInclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], {
524
+ unique: true,
525
+ }))
526
+ .chain((values) => {
527
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
528
+ if (literalValuesEither.isLeft()) {
529
+ return literalValuesEither;
530
+ }
531
+ const literalValues = literalValuesEither.unsafeCoerce();
532
+ const nonUniqueLanguageIn = $languageIn ?? [];
533
+ if (nonUniqueLanguageIn.length === 0) {
534
+ return purify.Either.of(literalValues);
535
+ }
536
+ let uniqueLanguageIn;
537
+ if (nonUniqueLanguageIn.length === 1) {
538
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
539
+ }
540
+ else {
541
+ uniqueLanguageIn = [];
542
+ for (const languageIn of nonUniqueLanguageIn) {
543
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
544
+ uniqueLanguageIn.push(languageIn);
545
+ }
546
+ }
547
+ }
548
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
549
+ // Within a languageIn the literals may be in any order.
550
+ let filteredLiteralValues;
551
+ for (const languageIn of uniqueLanguageIn) {
552
+ if (!filteredLiteralValues) {
553
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
554
+ }
555
+ else {
556
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
557
+ .filter((value) => value.language === languageIn)
558
+ .toArray());
559
+ }
560
+ }
561
+ return purify.Either.of(filteredLiteralValues);
341
562
  })
342
- .head()
343
- .chain((value) => value.toLiteral())
344
- .map((value) => purify.Maybe.of(value))
345
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
346
- ? purify.Right(purify.Maybe.empty())
347
- : purify.Left(error));
563
+ .map((values) => values.length > 0
564
+ ? values.map((value) => purify.Maybe.of(value))
565
+ : rdfjsResource.Resource.Values.fromValue({
566
+ object: purify.Maybe.empty(),
567
+ predicate: BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"],
568
+ subject: $resource,
569
+ }))
570
+ .chain((values) => values.head());
348
571
  if (_minInclusiveEither.isLeft()) {
349
572
  return _minInclusiveEither;
350
573
  }
351
574
  const minInclusive = _minInclusiveEither.unsafeCoerce();
352
- const _minLengthEither = $resource
353
- .values(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], { unique: true })
354
- .head()
355
- .chain((value) => value.toNumber())
356
- .map((value) => purify.Maybe.of(value))
357
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
358
- ? purify.Right(purify.Maybe.empty())
359
- : purify.Left(error));
575
+ const _minLengthEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], { unique: true }))
576
+ .chain((values) => values.chainMap((value) => value.toNumber()))
577
+ .map((values) => values.length > 0
578
+ ? values.map((value) => purify.Maybe.of(value))
579
+ : rdfjsResource.Resource.Values.fromValue({
580
+ object: purify.Maybe.empty(),
581
+ predicate: BaseShaclCoreShapeStatic.$properties.minLength["identifier"],
582
+ subject: $resource,
583
+ }))
584
+ .chain((values) => values.head());
360
585
  if (_minLengthEither.isLeft()) {
361
586
  return _minLengthEither;
362
587
  }
363
588
  const minLength = _minLengthEither.unsafeCoerce();
364
- const _nodeKindEither = $resource
365
- .values(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], { unique: true })
366
- .head()
367
- .chain((value) => value.toIri().chain((iri) => {
589
+ const _nodeKindEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], { unique: true }))
590
+ .chain((values) => values.chainMap((value) => value.toIri().chain((iri) => {
368
591
  switch (iri.value) {
369
592
  case "http://www.w3.org/ns/shacl#BlankNode":
370
593
  return purify.Either.of(iri);
@@ -386,69 +609,92 @@ export var BaseShaclCoreShapeStatic;
386
609
  predicate: BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"],
387
610
  }));
388
611
  }
389
- }))
390
- .map((value) => purify.Maybe.of(value))
391
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
392
- ? purify.Right(purify.Maybe.empty())
393
- : purify.Left(error));
612
+ })))
613
+ .map((values) => values.length > 0
614
+ ? values.map((value) => purify.Maybe.of(value))
615
+ : rdfjsResource.Resource.Values.fromValue({
616
+ object: purify.Maybe.empty(),
617
+ predicate: BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"],
618
+ subject: $resource,
619
+ }))
620
+ .chain((values) => values.head());
394
621
  if (_nodeKindEither.isLeft()) {
395
622
  return _nodeKindEither;
396
623
  }
397
624
  const nodeKind = _nodeKindEither.unsafeCoerce();
398
- const _nodesEither = purify.Either.sequence($resource
399
- .values(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], { unique: true })
400
- .map((item) => item
401
- .toValues()
402
- .head()
403
- .chain((value) => value.toIdentifier())));
625
+ const _nodesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], { unique: true }))
626
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
627
+ .map((values) => values.toArray())
628
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
629
+ object: valuesArray,
630
+ predicate: BaseShaclCoreShapeStatic.$properties.nodes["identifier"],
631
+ subject: $resource,
632
+ }))
633
+ .chain((values) => values.head());
404
634
  if (_nodesEither.isLeft()) {
405
635
  return _nodesEither;
406
636
  }
407
637
  const nodes = _nodesEither.unsafeCoerce();
408
- const _notEither = purify.Either.sequence($resource
409
- .values(BaseShaclCoreShapeStatic.$properties.not["identifier"], { unique: true })
410
- .map((item) => item
411
- .toValues()
412
- .head()
413
- .chain((value) => value.toIdentifier())));
638
+ const _notEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.not["identifier"], { unique: true }))
639
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
640
+ .map((values) => values.toArray())
641
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
642
+ object: valuesArray,
643
+ predicate: BaseShaclCoreShapeStatic.$properties.not["identifier"],
644
+ subject: $resource,
645
+ }))
646
+ .chain((values) => values.head());
414
647
  if (_notEither.isLeft()) {
415
648
  return _notEither;
416
649
  }
417
650
  const not = _notEither.unsafeCoerce();
418
- const _orEither = purify.Either.sequence($resource
419
- .values(BaseShaclCoreShapeStatic.$properties.or["identifier"], { unique: true })
420
- .map((item) => item
421
- .toValues()
422
- .head()
423
- .chain((value) => value.toList())
424
- .chain((values) => purify.Either.sequence(values.map((value) => value
425
- .toValues()
426
- .head()
427
- .chain((value) => value.toIdentifier()))))));
651
+ const _orEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.or["identifier"], { unique: true }))
652
+ .chain((values) => values.chainMap((value) => value.toList()))
653
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
654
+ objects: valueList,
655
+ predicate: BaseShaclCoreShapeStatic.$properties.or["identifier"],
656
+ subject: $resource,
657
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
658
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
659
+ .map((values) => values.toArray())
660
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
661
+ object: valuesArray,
662
+ predicate: BaseShaclCoreShapeStatic.$properties.or["identifier"],
663
+ subject: $resource,
664
+ }))
665
+ .chain((values) => values.head());
428
666
  if (_orEither.isLeft()) {
429
667
  return _orEither;
430
668
  }
431
669
  const or = _orEither.unsafeCoerce();
432
- const _patternsEither = purify.Either.sequence($resource
433
- .values(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], { unique: true })
434
- .map((item) => item
435
- .toValues()
436
- .head()
437
- .chain((value) => value.toString())));
670
+ const _patternsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], { unique: true }))
671
+ .chain((values) => values.chainMap((value) => value.toString()))
672
+ .map((values) => values.toArray())
673
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
674
+ object: valuesArray,
675
+ predicate: BaseShaclCoreShapeStatic.$properties.patterns["identifier"],
676
+ subject: $resource,
677
+ }))
678
+ .chain((values) => values.head());
438
679
  if (_patternsEither.isLeft()) {
439
680
  return _patternsEither;
440
681
  }
441
682
  const patterns = _patternsEither.unsafeCoerce();
442
- const _xoneEither = purify.Either.sequence($resource
443
- .values(BaseShaclCoreShapeStatic.$properties.xone["identifier"], { unique: true })
444
- .map((item) => item
445
- .toValues()
446
- .head()
447
- .chain((value) => value.toList())
448
- .chain((values) => purify.Either.sequence(values.map((value) => value
449
- .toValues()
450
- .head()
451
- .chain((value) => value.toIdentifier()))))));
683
+ const _xoneEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.xone["identifier"], { unique: true }))
684
+ .chain((values) => values.chainMap((value) => value.toList()))
685
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
686
+ objects: valueList,
687
+ predicate: BaseShaclCoreShapeStatic.$properties.xone["identifier"],
688
+ subject: $resource,
689
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
690
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
691
+ .map((values) => values.toArray())
692
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
693
+ object: valuesArray,
694
+ predicate: BaseShaclCoreShapeStatic.$properties.xone["identifier"],
695
+ subject: $resource,
696
+ }))
697
+ .chain((values) => values.head());
452
698
  if (_xoneEither.isLeft()) {
453
699
  return _xoneEither;
454
700
  }
@@ -483,14 +729,15 @@ export var BaseShaclCoreShapeStatic;
483
729
  });
484
730
  }
485
731
  BaseShaclCoreShapeStatic.$propertiesFromRdf = $propertiesFromRdf;
486
- function $fromRdf(parameters) {
487
- const { ignoreRdfType: _, ...otherParameters } = parameters;
488
- return ShaclCoreNodeShape.$fromRdf(otherParameters).altLazy(() => ShaclCorePropertyShape.$fromRdf(otherParameters));
489
- }
490
- BaseShaclCoreShapeStatic.$fromRdf = $fromRdf;
491
- function $toRdf(_baseShaclCoreShape, { mutateGraph, resourceSet, }) {
492
- const _resource = resourceSet.mutableResource(_baseShaclCoreShape.$identifier, { mutateGraph });
493
- _resource.add(BaseShaclCoreShapeStatic.$properties.and["identifier"], _baseShaclCoreShape.and.map((item) => item.length > 0
732
+ function $toRdf(_baseShaclCoreShape, options) {
733
+ const mutateGraph = options?.mutateGraph;
734
+ const resourceSet = options?.resourceSet ??
735
+ new rdfjsResource.MutableResourceSet({
736
+ dataFactory,
737
+ dataset: datasetFactory.dataset(),
738
+ });
739
+ const resource = resourceSet.mutableResource(_baseShaclCoreShape.$identifier, { mutateGraph });
740
+ resource.add(BaseShaclCoreShapeStatic.$properties.and["identifier"], _baseShaclCoreShape.and.map((item) => item.length > 0
494
741
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
495
742
  if (itemIndex === 0) {
496
743
  currentSubListResource = listResource;
@@ -510,13 +757,13 @@ export var BaseShaclCoreShapeStatic;
510
757
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
511
758
  }).listResource.identifier
512
759
  : $RdfVocabularies.rdf.nil));
513
- _resource.add(BaseShaclCoreShapeStatic.$properties.classes["identifier"], _baseShaclCoreShape.classes.map((item) => item));
514
- _resource.add(BaseShaclCoreShapeStatic.$properties.comments["identifier"], _baseShaclCoreShape.comments.map((item) => item));
515
- _resource.add(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], _baseShaclCoreShape.datatype);
516
- _resource.add(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], _baseShaclCoreShape.deactivated);
517
- _resource.add(BaseShaclCoreShapeStatic.$properties.flags["identifier"], _baseShaclCoreShape.flags.map((item) => item));
518
- _resource.add(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], _baseShaclCoreShape.hasValues.map((item) => item));
519
- _resource.add(BaseShaclCoreShapeStatic.$properties.in_["identifier"], _baseShaclCoreShape.in_.map((value) => value.length > 0
760
+ resource.add(BaseShaclCoreShapeStatic.$properties.classes["identifier"], _baseShaclCoreShape.classes.map((item) => item));
761
+ resource.add(BaseShaclCoreShapeStatic.$properties.comments["identifier"], _baseShaclCoreShape.comments.map((item) => item));
762
+ resource.add(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], _baseShaclCoreShape.datatype);
763
+ resource.add(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], _baseShaclCoreShape.deactivated);
764
+ resource.add(BaseShaclCoreShapeStatic.$properties.flags["identifier"], _baseShaclCoreShape.flags.map((item) => item));
765
+ resource.add(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], _baseShaclCoreShape.hasValues.map((item) => item));
766
+ resource.add(BaseShaclCoreShapeStatic.$properties.in_["identifier"], _baseShaclCoreShape.in_.map((value) => value.length > 0
520
767
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
521
768
  if (itemIndex === 0) {
522
769
  currentSubListResource = listResource;
@@ -536,9 +783,9 @@ export var BaseShaclCoreShapeStatic;
536
783
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
537
784
  }).listResource.identifier
538
785
  : $RdfVocabularies.rdf.nil));
539
- _resource.add(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], _baseShaclCoreShape.isDefinedBy);
540
- _resource.add(BaseShaclCoreShapeStatic.$properties.labels["identifier"], _baseShaclCoreShape.labels.map((item) => item));
541
- _resource.add(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], _baseShaclCoreShape.languageIn.map((value) => value.length > 0
786
+ resource.add(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], _baseShaclCoreShape.isDefinedBy);
787
+ resource.add(BaseShaclCoreShapeStatic.$properties.labels["identifier"], _baseShaclCoreShape.labels.map((item) => item));
788
+ resource.add(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], _baseShaclCoreShape.languageIn.map((value) => value.length > 0
542
789
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
543
790
  if (itemIndex === 0) {
544
791
  currentSubListResource = listResource;
@@ -558,18 +805,18 @@ export var BaseShaclCoreShapeStatic;
558
805
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
559
806
  }).listResource.identifier
560
807
  : $RdfVocabularies.rdf.nil));
561
- _resource.add(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], _baseShaclCoreShape.maxCount);
562
- _resource.add(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], _baseShaclCoreShape.maxExclusive);
563
- _resource.add(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], _baseShaclCoreShape.maxInclusive);
564
- _resource.add(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], _baseShaclCoreShape.maxLength);
565
- _resource.add(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], _baseShaclCoreShape.minCount);
566
- _resource.add(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], _baseShaclCoreShape.minExclusive);
567
- _resource.add(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], _baseShaclCoreShape.minInclusive);
568
- _resource.add(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], _baseShaclCoreShape.minLength);
569
- _resource.add(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], _baseShaclCoreShape.nodeKind);
570
- _resource.add(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], _baseShaclCoreShape.nodes.map((item) => item));
571
- _resource.add(BaseShaclCoreShapeStatic.$properties.not["identifier"], _baseShaclCoreShape.not.map((item) => item));
572
- _resource.add(BaseShaclCoreShapeStatic.$properties.or["identifier"], _baseShaclCoreShape.or.map((item) => item.length > 0
808
+ resource.add(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], _baseShaclCoreShape.maxCount);
809
+ resource.add(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], _baseShaclCoreShape.maxExclusive);
810
+ resource.add(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], _baseShaclCoreShape.maxInclusive);
811
+ resource.add(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], _baseShaclCoreShape.maxLength);
812
+ resource.add(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], _baseShaclCoreShape.minCount);
813
+ resource.add(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], _baseShaclCoreShape.minExclusive);
814
+ resource.add(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], _baseShaclCoreShape.minInclusive);
815
+ resource.add(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], _baseShaclCoreShape.minLength);
816
+ resource.add(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], _baseShaclCoreShape.nodeKind);
817
+ resource.add(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], _baseShaclCoreShape.nodes.map((item) => item));
818
+ resource.add(BaseShaclCoreShapeStatic.$properties.not["identifier"], _baseShaclCoreShape.not.map((item) => item));
819
+ resource.add(BaseShaclCoreShapeStatic.$properties.or["identifier"], _baseShaclCoreShape.or.map((item) => item.length > 0
573
820
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
574
821
  if (itemIndex === 0) {
575
822
  currentSubListResource = listResource;
@@ -589,8 +836,8 @@ export var BaseShaclCoreShapeStatic;
589
836
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
590
837
  }).listResource.identifier
591
838
  : $RdfVocabularies.rdf.nil));
592
- _resource.add(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], _baseShaclCoreShape.patterns.map((item) => item));
593
- _resource.add(BaseShaclCoreShapeStatic.$properties.xone["identifier"], _baseShaclCoreShape.xone.map((item) => item.length > 0
839
+ resource.add(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], _baseShaclCoreShape.patterns.map((item) => item));
840
+ resource.add(BaseShaclCoreShapeStatic.$properties.xone["identifier"], _baseShaclCoreShape.xone.map((item) => item.length > 0
594
841
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
595
842
  if (itemIndex === 0) {
596
843
  currentSubListResource = listResource;
@@ -610,7 +857,7 @@ export var BaseShaclCoreShapeStatic;
610
857
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
611
858
  }).listResource.identifier
612
859
  : $RdfVocabularies.rdf.nil));
613
- return _resource;
860
+ return resource;
614
861
  }
615
862
  BaseShaclCoreShapeStatic.$toRdf = $toRdf;
616
863
  BaseShaclCoreShapeStatic.$properties = {
@@ -691,13 +938,28 @@ export var ShaclCorePropertyShape;
691
938
  (function (ShaclCorePropertyShape) {
692
939
  ShaclCorePropertyShape.$fromRdfType = dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape");
693
940
  ShaclCorePropertyShape.$Identifier = BaseShaclCoreShapeStatic.$Identifier;
694
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSetParameter, resource: $resource,
941
+ function $fromRdf(resource, options) {
942
+ let { ignoreRdfType = false, languageIn, objectSet, ...context } = options ?? {};
943
+ if (!objectSet) {
944
+ objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
945
+ }
946
+ return ShaclCorePropertyShape.$propertiesFromRdf({
947
+ ...context,
948
+ ignoreRdfType,
949
+ languageIn,
950
+ objectSet,
951
+ resource,
952
+ });
953
+ }
954
+ ShaclCorePropertyShape.$fromRdf = $fromRdf;
955
+ function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSet, resource: $resource,
695
956
  // @ts-ignore
696
957
  ...$context }) {
697
958
  const $super0Either = BaseShaclCoreShapeStatic.$propertiesFromRdf({
698
959
  ...$context,
699
960
  ignoreRdfType: true,
700
961
  languageIn: $languageIn,
962
+ objectSet: $objectSet,
701
963
  resource: $resource,
702
964
  });
703
965
  if ($super0Either.isLeft()) {
@@ -712,10 +974,10 @@ export var ShaclCorePropertyShape;
712
974
  }
713
975
  const $identifier = $resource.identifier;
714
976
  const $type = "ShaclCorePropertyShape";
715
- const _defaultValueEither = $resource
716
- .values(ShaclCorePropertyShape.$properties.defaultValue["identifier"], { unique: true })
717
- .head()
718
- .chain((value) => purify.Either.of(value.toTerm()).chain((term) => {
977
+ const _defaultValueEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.defaultValue["identifier"], {
978
+ unique: true,
979
+ }))
980
+ .chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
719
981
  switch (term.termType) {
720
982
  case "Literal":
721
983
  case "NamedNode":
@@ -728,101 +990,168 @@ export var ShaclCorePropertyShape;
728
990
  predicate: ShaclCorePropertyShape.$properties.defaultValue["identifier"],
729
991
  }));
730
992
  }
731
- }))
732
- .map((value) => purify.Maybe.of(value))
733
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
734
- ? purify.Right(purify.Maybe.empty())
735
- : purify.Left(error));
993
+ })))
994
+ .map((values) => values.length > 0
995
+ ? values.map((value) => purify.Maybe.of(value))
996
+ : rdfjsResource.Resource.Values.fromValue({
997
+ object: purify.Maybe.empty(),
998
+ predicate: ShaclCorePropertyShape.$properties.defaultValue["identifier"],
999
+ subject: $resource,
1000
+ }))
1001
+ .chain((values) => values.head());
736
1002
  if (_defaultValueEither.isLeft()) {
737
1003
  return _defaultValueEither;
738
1004
  }
739
1005
  const defaultValue = _defaultValueEither.unsafeCoerce();
740
- const _descriptionsEither = purify.Either.sequence($resource
741
- .values(ShaclCorePropertyShape.$properties.descriptions["identifier"], { unique: true })
742
- .map((item) => item
743
- .toValues()
744
- .filter((_value) => {
745
- const _languageInOrDefault = $languageIn ?? [];
746
- if (_languageInOrDefault.length === 0) {
747
- return true;
748
- }
749
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
750
- if (typeof _valueLiteral === "undefined") {
751
- return false;
752
- }
753
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
1006
+ const _descriptionsEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.descriptions["identifier"], {
1007
+ unique: true,
1008
+ }))
1009
+ .chain((values) => {
1010
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
1011
+ if (literalValuesEither.isLeft()) {
1012
+ return literalValuesEither;
1013
+ }
1014
+ const literalValues = literalValuesEither.unsafeCoerce();
1015
+ const nonUniqueLanguageIn = $languageIn ?? [];
1016
+ if (nonUniqueLanguageIn.length === 0) {
1017
+ return purify.Either.of(literalValues);
1018
+ }
1019
+ let uniqueLanguageIn;
1020
+ if (nonUniqueLanguageIn.length === 1) {
1021
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
1022
+ }
1023
+ else {
1024
+ uniqueLanguageIn = [];
1025
+ for (const languageIn of nonUniqueLanguageIn) {
1026
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
1027
+ uniqueLanguageIn.push(languageIn);
1028
+ }
1029
+ }
1030
+ }
1031
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
1032
+ // Within a languageIn the literals may be in any order.
1033
+ let filteredLiteralValues;
1034
+ for (const languageIn of uniqueLanguageIn) {
1035
+ if (!filteredLiteralValues) {
1036
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
1037
+ }
1038
+ else {
1039
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1040
+ .filter((value) => value.language === languageIn)
1041
+ .toArray());
1042
+ }
1043
+ }
1044
+ return purify.Either.of(filteredLiteralValues);
754
1045
  })
755
- .head()
756
- .chain((value) => value.toLiteral())));
1046
+ .map((values) => values.toArray())
1047
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1048
+ object: valuesArray,
1049
+ predicate: ShaclCorePropertyShape.$properties.descriptions["identifier"],
1050
+ subject: $resource,
1051
+ }))
1052
+ .chain((values) => values.head());
757
1053
  if (_descriptionsEither.isLeft()) {
758
1054
  return _descriptionsEither;
759
1055
  }
760
1056
  const descriptions = _descriptionsEither.unsafeCoerce();
761
- const _groupsEither = purify.Either.sequence($resource
762
- .values(ShaclCorePropertyShape.$properties.groups["identifier"], { unique: true })
763
- .map((item) => item
764
- .toValues()
765
- .head()
766
- .chain((value) => value.toIdentifier())));
1057
+ const _groupsEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.groups["identifier"], { unique: true }))
1058
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1059
+ .map((values) => values.toArray())
1060
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1061
+ object: valuesArray,
1062
+ predicate: ShaclCorePropertyShape.$properties.groups["identifier"],
1063
+ subject: $resource,
1064
+ }))
1065
+ .chain((values) => values.head());
767
1066
  if (_groupsEither.isLeft()) {
768
1067
  return _groupsEither;
769
1068
  }
770
1069
  const groups = _groupsEither.unsafeCoerce();
771
- const _namesEither = purify.Either.sequence($resource
772
- .values(ShaclCorePropertyShape.$properties.names["identifier"], { unique: true })
773
- .map((item) => item
774
- .toValues()
775
- .filter((_value) => {
776
- const _languageInOrDefault = $languageIn ?? [];
777
- if (_languageInOrDefault.length === 0) {
778
- return true;
779
- }
780
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
781
- if (typeof _valueLiteral === "undefined") {
782
- return false;
783
- }
784
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
1070
+ const _namesEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.names["identifier"], { unique: true }))
1071
+ .chain((values) => {
1072
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
1073
+ if (literalValuesEither.isLeft()) {
1074
+ return literalValuesEither;
1075
+ }
1076
+ const literalValues = literalValuesEither.unsafeCoerce();
1077
+ const nonUniqueLanguageIn = $languageIn ?? [];
1078
+ if (nonUniqueLanguageIn.length === 0) {
1079
+ return purify.Either.of(literalValues);
1080
+ }
1081
+ let uniqueLanguageIn;
1082
+ if (nonUniqueLanguageIn.length === 1) {
1083
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
1084
+ }
1085
+ else {
1086
+ uniqueLanguageIn = [];
1087
+ for (const languageIn of nonUniqueLanguageIn) {
1088
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
1089
+ uniqueLanguageIn.push(languageIn);
1090
+ }
1091
+ }
1092
+ }
1093
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
1094
+ // Within a languageIn the literals may be in any order.
1095
+ let filteredLiteralValues;
1096
+ for (const languageIn of uniqueLanguageIn) {
1097
+ if (!filteredLiteralValues) {
1098
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
1099
+ }
1100
+ else {
1101
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1102
+ .filter((value) => value.language === languageIn)
1103
+ .toArray());
1104
+ }
1105
+ }
1106
+ return purify.Either.of(filteredLiteralValues);
785
1107
  })
786
- .head()
787
- .chain((value) => value.toLiteral())));
1108
+ .map((values) => values.toArray())
1109
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1110
+ object: valuesArray,
1111
+ predicate: ShaclCorePropertyShape.$properties.names["identifier"],
1112
+ subject: $resource,
1113
+ }))
1114
+ .chain((values) => values.head());
788
1115
  if (_namesEither.isLeft()) {
789
1116
  return _namesEither;
790
1117
  }
791
1118
  const names = _namesEither.unsafeCoerce();
792
- const _orderEither = $resource
793
- .values(ShaclCorePropertyShape.$properties.order["identifier"], { unique: true })
794
- .head()
795
- .chain((value) => value.toNumber())
796
- .map((value) => purify.Maybe.of(value))
797
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
798
- ? purify.Right(purify.Maybe.empty())
799
- : purify.Left(error));
1119
+ const _orderEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.order["identifier"], { unique: true }))
1120
+ .chain((values) => values.chainMap((value) => value.toNumber()))
1121
+ .map((values) => values.length > 0
1122
+ ? values.map((value) => purify.Maybe.of(value))
1123
+ : rdfjsResource.Resource.Values.fromValue({
1124
+ object: purify.Maybe.empty(),
1125
+ predicate: ShaclCorePropertyShape.$properties.order["identifier"],
1126
+ subject: $resource,
1127
+ }))
1128
+ .chain((values) => values.head());
800
1129
  if (_orderEither.isLeft()) {
801
1130
  return _orderEither;
802
1131
  }
803
1132
  const order = _orderEither.unsafeCoerce();
804
- const _pathEither = $resource
805
- .values(ShaclCorePropertyShape.$properties.path["identifier"], { unique: true })
806
- .head()
807
- .chain((value) => value.toResource())
808
- .chain((_resource) => PropertyPath.$fromRdf({
1133
+ const _pathEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.path["identifier"], { unique: true }))
1134
+ .chain((values) => values.chainMap((value) => value.toResource().chain((resource) => PropertyPath.$fromRdf(resource, {
809
1135
  ...$context,
810
1136
  ignoreRdfType: true,
811
1137
  languageIn: $languageIn,
812
- resource: _resource,
813
- }));
1138
+ objectSet: $objectSet,
1139
+ }))))
1140
+ .chain((values) => values.head());
814
1141
  if (_pathEither.isLeft()) {
815
1142
  return _pathEither;
816
1143
  }
817
1144
  const path = _pathEither.unsafeCoerce();
818
- const _uniqueLangEither = $resource
819
- .values(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], { unique: true })
820
- .head()
821
- .chain((value) => value.toBoolean())
822
- .map((value) => purify.Maybe.of(value))
823
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
824
- ? purify.Right(purify.Maybe.empty())
825
- : purify.Left(error));
1145
+ const _uniqueLangEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], { unique: true }))
1146
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
1147
+ .map((values) => values.length > 0
1148
+ ? values.map((value) => purify.Maybe.of(value))
1149
+ : rdfjsResource.Resource.Values.fromValue({
1150
+ object: purify.Maybe.empty(),
1151
+ predicate: ShaclCorePropertyShape.$properties.uniqueLang["identifier"],
1152
+ subject: $resource,
1153
+ }))
1154
+ .chain((values) => values.head());
826
1155
  if (_uniqueLangEither.isLeft()) {
827
1156
  return _uniqueLangEither;
828
1157
  }
@@ -841,31 +1170,34 @@ export var ShaclCorePropertyShape;
841
1170
  });
842
1171
  }
843
1172
  ShaclCorePropertyShape.$propertiesFromRdf = $propertiesFromRdf;
844
- function $fromRdf(parameters) {
845
- return ShaclCorePropertyShape.$propertiesFromRdf(parameters);
846
- }
847
- ShaclCorePropertyShape.$fromRdf = $fromRdf;
848
- function $toRdf(_shaclCorePropertyShape, { ignoreRdfType, mutateGraph, resourceSet, }) {
849
- const _resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCorePropertyShape, {
1173
+ function $toRdf(_shaclCorePropertyShape, options) {
1174
+ const ignoreRdfType = !!options?.ignoreRdfType;
1175
+ const mutateGraph = options?.mutateGraph;
1176
+ const resourceSet = options?.resourceSet ??
1177
+ new rdfjsResource.MutableResourceSet({
1178
+ dataFactory,
1179
+ dataset: datasetFactory.dataset(),
1180
+ });
1181
+ const resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCorePropertyShape, {
850
1182
  ignoreRdfType: true,
851
1183
  mutateGraph,
852
1184
  resourceSet,
853
1185
  });
854
1186
  if (!ignoreRdfType) {
855
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCorePropertyShape"));
856
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"));
857
- }
858
- _resource.add(ShaclCorePropertyShape.$properties.defaultValue["identifier"], _shaclCorePropertyShape.defaultValue);
859
- _resource.add(ShaclCorePropertyShape.$properties.descriptions["identifier"], _shaclCorePropertyShape.descriptions.map((item) => item));
860
- _resource.add(ShaclCorePropertyShape.$properties.groups["identifier"], _shaclCorePropertyShape.groups.map((item) => item));
861
- _resource.add(ShaclCorePropertyShape.$properties.names["identifier"], _shaclCorePropertyShape.names.map((item) => item));
862
- _resource.add(ShaclCorePropertyShape.$properties.order["identifier"], _shaclCorePropertyShape.order);
863
- _resource.add(ShaclCorePropertyShape.$properties.path["identifier"], PropertyPath.$toRdf(_shaclCorePropertyShape.path, {
1187
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCorePropertyShape"));
1188
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"));
1189
+ }
1190
+ resource.add(ShaclCorePropertyShape.$properties.defaultValue["identifier"], _shaclCorePropertyShape.defaultValue);
1191
+ resource.add(ShaclCorePropertyShape.$properties.descriptions["identifier"], _shaclCorePropertyShape.descriptions.map((item) => item));
1192
+ resource.add(ShaclCorePropertyShape.$properties.groups["identifier"], _shaclCorePropertyShape.groups.map((item) => item));
1193
+ resource.add(ShaclCorePropertyShape.$properties.names["identifier"], _shaclCorePropertyShape.names.map((item) => item));
1194
+ resource.add(ShaclCorePropertyShape.$properties.order["identifier"], _shaclCorePropertyShape.order);
1195
+ resource.add(ShaclCorePropertyShape.$properties.path["identifier"], PropertyPath.$toRdf(_shaclCorePropertyShape.path, {
864
1196
  mutateGraph: mutateGraph,
865
1197
  resourceSet: resourceSet,
866
1198
  }));
867
- _resource.add(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], _shaclCorePropertyShape.uniqueLang);
868
- return _resource;
1199
+ resource.add(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], _shaclCorePropertyShape.uniqueLang);
1200
+ return resource;
869
1201
  }
870
1202
  ShaclCorePropertyShape.$toRdf = $toRdf;
871
1203
  ShaclCorePropertyShape.$properties = {
@@ -907,7 +1239,21 @@ export var ShaclCorePropertyGroup;
907
1239
  $Identifier.fromString = fromString;
908
1240
  $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
909
1241
  })($Identifier = ShaclCorePropertyGroup.$Identifier || (ShaclCorePropertyGroup.$Identifier = {}));
910
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSetParameter, resource: $resource,
1242
+ function $fromRdf(resource, options) {
1243
+ let { ignoreRdfType = false, languageIn, objectSet, ...context } = options ?? {};
1244
+ if (!objectSet) {
1245
+ objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1246
+ }
1247
+ return ShaclCorePropertyGroup.$propertiesFromRdf({
1248
+ ...context,
1249
+ ignoreRdfType,
1250
+ languageIn,
1251
+ objectSet,
1252
+ resource,
1253
+ });
1254
+ }
1255
+ ShaclCorePropertyGroup.$fromRdf = $fromRdf;
1256
+ function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSet, resource: $resource,
911
1257
  // @ts-ignore
912
1258
  ...$context }) {
913
1259
  if (!$ignoreRdfType && !$resource.isInstanceOf(ShaclCorePropertyGroup.$fromRdfType)) {
@@ -918,44 +1264,100 @@ export var ShaclCorePropertyGroup;
918
1264
  }
919
1265
  const $identifier = $resource.identifier;
920
1266
  const $type = "ShaclCorePropertyGroup";
921
- const _commentsEither = purify.Either.sequence($resource
922
- .values(ShaclCorePropertyGroup.$properties.comments["identifier"], { unique: true })
923
- .map((item) => item
924
- .toValues()
925
- .filter((_value) => {
926
- const _languageInOrDefault = $languageIn ?? [];
927
- if (_languageInOrDefault.length === 0) {
928
- return true;
929
- }
930
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
931
- if (typeof _valueLiteral === "undefined") {
932
- return false;
933
- }
934
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
1267
+ const _commentsEither = purify.Either.of($resource.values(ShaclCorePropertyGroup.$properties.comments["identifier"], { unique: true }))
1268
+ .chain((values) => {
1269
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
1270
+ if (literalValuesEither.isLeft()) {
1271
+ return literalValuesEither;
1272
+ }
1273
+ const literalValues = literalValuesEither.unsafeCoerce();
1274
+ const nonUniqueLanguageIn = $languageIn ?? [];
1275
+ if (nonUniqueLanguageIn.length === 0) {
1276
+ return purify.Either.of(literalValues);
1277
+ }
1278
+ let uniqueLanguageIn;
1279
+ if (nonUniqueLanguageIn.length === 1) {
1280
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
1281
+ }
1282
+ else {
1283
+ uniqueLanguageIn = [];
1284
+ for (const languageIn of nonUniqueLanguageIn) {
1285
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
1286
+ uniqueLanguageIn.push(languageIn);
1287
+ }
1288
+ }
1289
+ }
1290
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
1291
+ // Within a languageIn the literals may be in any order.
1292
+ let filteredLiteralValues;
1293
+ for (const languageIn of uniqueLanguageIn) {
1294
+ if (!filteredLiteralValues) {
1295
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
1296
+ }
1297
+ else {
1298
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1299
+ .filter((value) => value.language === languageIn)
1300
+ .toArray());
1301
+ }
1302
+ }
1303
+ return purify.Either.of(filteredLiteralValues);
935
1304
  })
936
- .head()
937
- .chain((value) => value.toLiteral())));
1305
+ .map((values) => values.toArray())
1306
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1307
+ object: valuesArray,
1308
+ predicate: ShaclCorePropertyGroup.$properties.comments["identifier"],
1309
+ subject: $resource,
1310
+ }))
1311
+ .chain((values) => values.head());
938
1312
  if (_commentsEither.isLeft()) {
939
1313
  return _commentsEither;
940
1314
  }
941
1315
  const comments = _commentsEither.unsafeCoerce();
942
- const _labelsEither = purify.Either.sequence($resource
943
- .values(ShaclCorePropertyGroup.$properties.labels["identifier"], { unique: true })
944
- .map((item) => item
945
- .toValues()
946
- .filter((_value) => {
947
- const _languageInOrDefault = $languageIn ?? [];
948
- if (_languageInOrDefault.length === 0) {
949
- return true;
950
- }
951
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
952
- if (typeof _valueLiteral === "undefined") {
953
- return false;
954
- }
955
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
1316
+ const _labelsEither = purify.Either.of($resource.values(ShaclCorePropertyGroup.$properties.labels["identifier"], { unique: true }))
1317
+ .chain((values) => {
1318
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
1319
+ if (literalValuesEither.isLeft()) {
1320
+ return literalValuesEither;
1321
+ }
1322
+ const literalValues = literalValuesEither.unsafeCoerce();
1323
+ const nonUniqueLanguageIn = $languageIn ?? [];
1324
+ if (nonUniqueLanguageIn.length === 0) {
1325
+ return purify.Either.of(literalValues);
1326
+ }
1327
+ let uniqueLanguageIn;
1328
+ if (nonUniqueLanguageIn.length === 1) {
1329
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
1330
+ }
1331
+ else {
1332
+ uniqueLanguageIn = [];
1333
+ for (const languageIn of nonUniqueLanguageIn) {
1334
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
1335
+ uniqueLanguageIn.push(languageIn);
1336
+ }
1337
+ }
1338
+ }
1339
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
1340
+ // Within a languageIn the literals may be in any order.
1341
+ let filteredLiteralValues;
1342
+ for (const languageIn of uniqueLanguageIn) {
1343
+ if (!filteredLiteralValues) {
1344
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
1345
+ }
1346
+ else {
1347
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1348
+ .filter((value) => value.language === languageIn)
1349
+ .toArray());
1350
+ }
1351
+ }
1352
+ return purify.Either.of(filteredLiteralValues);
956
1353
  })
957
- .head()
958
- .chain((value) => value.toLiteral())));
1354
+ .map((values) => values.toArray())
1355
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1356
+ object: valuesArray,
1357
+ predicate: ShaclCorePropertyGroup.$properties.labels["identifier"],
1358
+ subject: $resource,
1359
+ }))
1360
+ .chain((values) => values.head());
959
1361
  if (_labelsEither.isLeft()) {
960
1362
  return _labelsEither;
961
1363
  }
@@ -963,18 +1365,21 @@ export var ShaclCorePropertyGroup;
963
1365
  return purify.Either.of({ $identifier, $type, comments, labels });
964
1366
  }
965
1367
  ShaclCorePropertyGroup.$propertiesFromRdf = $propertiesFromRdf;
966
- function $fromRdf(parameters) {
967
- return ShaclCorePropertyGroup.$propertiesFromRdf(parameters);
968
- }
969
- ShaclCorePropertyGroup.$fromRdf = $fromRdf;
970
- function $toRdf(_shaclCorePropertyGroup, { ignoreRdfType, mutateGraph, resourceSet, }) {
971
- const _resource = resourceSet.mutableResource(_shaclCorePropertyGroup.$identifier, { mutateGraph });
1368
+ function $toRdf(_shaclCorePropertyGroup, options) {
1369
+ const ignoreRdfType = !!options?.ignoreRdfType;
1370
+ const mutateGraph = options?.mutateGraph;
1371
+ const resourceSet = options?.resourceSet ??
1372
+ new rdfjsResource.MutableResourceSet({
1373
+ dataFactory,
1374
+ dataset: datasetFactory.dataset(),
1375
+ });
1376
+ const resource = resourceSet.mutableResource(_shaclCorePropertyGroup.$identifier, { mutateGraph });
972
1377
  if (!ignoreRdfType) {
973
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"));
1378
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"));
974
1379
  }
975
- _resource.add(ShaclCorePropertyGroup.$properties.comments["identifier"], _shaclCorePropertyGroup.comments.map((item) => item));
976
- _resource.add(ShaclCorePropertyGroup.$properties.labels["identifier"], _shaclCorePropertyGroup.labels.map((item) => item));
977
- return _resource;
1380
+ resource.add(ShaclCorePropertyGroup.$properties.comments["identifier"], _shaclCorePropertyGroup.comments.map((item) => item));
1381
+ resource.add(ShaclCorePropertyGroup.$properties.labels["identifier"], _shaclCorePropertyGroup.labels.map((item) => item));
1382
+ return resource;
978
1383
  }
979
1384
  ShaclCorePropertyGroup.$toRdf = $toRdf;
980
1385
  ShaclCorePropertyGroup.$properties = {
@@ -990,13 +1395,28 @@ export var ShaclCoreNodeShape;
990
1395
  (function (ShaclCoreNodeShape) {
991
1396
  ShaclCoreNodeShape.$fromRdfType = dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape");
992
1397
  ShaclCoreNodeShape.$Identifier = BaseShaclCoreShapeStatic.$Identifier;
993
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSetParameter, resource: $resource,
1398
+ function $fromRdf(resource, options) {
1399
+ let { ignoreRdfType = false, languageIn, objectSet, ...context } = options ?? {};
1400
+ if (!objectSet) {
1401
+ objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1402
+ }
1403
+ return ShaclCoreNodeShape.$propertiesFromRdf({
1404
+ ...context,
1405
+ ignoreRdfType,
1406
+ languageIn,
1407
+ objectSet,
1408
+ resource,
1409
+ });
1410
+ }
1411
+ ShaclCoreNodeShape.$fromRdf = $fromRdf;
1412
+ function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSet, resource: $resource,
994
1413
  // @ts-ignore
995
1414
  ...$context }) {
996
1415
  const $super0Either = BaseShaclCoreShapeStatic.$propertiesFromRdf({
997
1416
  ...$context,
998
1417
  ignoreRdfType: true,
999
1418
  languageIn: $languageIn,
1419
+ objectSet: $objectSet,
1000
1420
  resource: $resource,
1001
1421
  });
1002
1422
  if ($super0Either.isLeft()) {
@@ -1011,40 +1431,51 @@ export var ShaclCoreNodeShape;
1011
1431
  }
1012
1432
  const $identifier = $resource.identifier;
1013
1433
  const $type = "ShaclCoreNodeShape";
1014
- const _closedEither = $resource
1015
- .values(ShaclCoreNodeShape.$properties.closed["identifier"], { unique: true })
1016
- .head()
1017
- .chain((value) => value.toBoolean())
1018
- .map((value) => purify.Maybe.of(value))
1019
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
1020
- ? purify.Right(purify.Maybe.empty())
1021
- : purify.Left(error));
1434
+ const _closedEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.closed["identifier"], { unique: true }))
1435
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
1436
+ .map((values) => values.length > 0
1437
+ ? values.map((value) => purify.Maybe.of(value))
1438
+ : rdfjsResource.Resource.Values.fromValue({
1439
+ object: purify.Maybe.empty(),
1440
+ predicate: ShaclCoreNodeShape.$properties.closed["identifier"],
1441
+ subject: $resource,
1442
+ }))
1443
+ .chain((values) => values.head());
1022
1444
  if (_closedEither.isLeft()) {
1023
1445
  return _closedEither;
1024
1446
  }
1025
1447
  const closed = _closedEither.unsafeCoerce();
1026
- const _ignoredPropertiesEither = $resource
1027
- .values(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], { unique: true })
1028
- .head()
1029
- .chain((value) => value.toList())
1030
- .chain((values) => purify.Either.sequence(values.map((value) => value
1031
- .toValues()
1032
- .head()
1033
- .chain((value) => value.toIri()))))
1034
- .map((value) => purify.Maybe.of(value))
1035
- .chainLeft((error) => error instanceof rdfjsResource.Resource.MissingValueError
1036
- ? purify.Right(purify.Maybe.empty())
1037
- : purify.Left(error));
1448
+ const _ignoredPropertiesEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], {
1449
+ unique: true,
1450
+ }))
1451
+ .chain((values) => values.chainMap((value) => value.toList()))
1452
+ .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
1453
+ objects: valueList,
1454
+ predicate: ShaclCoreNodeShape.$properties.ignoredProperties["identifier"],
1455
+ subject: $resource,
1456
+ })).chain((values) => values.chainMap((value) => value.toIri()))))
1457
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
1458
+ .map((values) => values.length > 0
1459
+ ? values.map((value) => purify.Maybe.of(value))
1460
+ : rdfjsResource.Resource.Values.fromValue({
1461
+ object: purify.Maybe.empty(),
1462
+ predicate: ShaclCoreNodeShape.$properties.ignoredProperties["identifier"],
1463
+ subject: $resource,
1464
+ }))
1465
+ .chain((values) => values.head());
1038
1466
  if (_ignoredPropertiesEither.isLeft()) {
1039
1467
  return _ignoredPropertiesEither;
1040
1468
  }
1041
1469
  const ignoredProperties = _ignoredPropertiesEither.unsafeCoerce();
1042
- const _propertiesEither = purify.Either.sequence($resource
1043
- .values(ShaclCoreNodeShape.$properties.properties["identifier"], { unique: true })
1044
- .map((item) => item
1045
- .toValues()
1046
- .head()
1047
- .chain((value) => value.toIdentifier())));
1470
+ const _propertiesEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.properties["identifier"], { unique: true }))
1471
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1472
+ .map((values) => values.toArray())
1473
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1474
+ object: valuesArray,
1475
+ predicate: ShaclCoreNodeShape.$properties.properties["identifier"],
1476
+ subject: $resource,
1477
+ }))
1478
+ .chain((values) => values.head());
1048
1479
  if (_propertiesEither.isLeft()) {
1049
1480
  return _propertiesEither;
1050
1481
  }
@@ -1059,22 +1490,25 @@ export var ShaclCoreNodeShape;
1059
1490
  });
1060
1491
  }
1061
1492
  ShaclCoreNodeShape.$propertiesFromRdf = $propertiesFromRdf;
1062
- function $fromRdf(parameters) {
1063
- return ShaclCoreNodeShape.$propertiesFromRdf(parameters);
1064
- }
1065
- ShaclCoreNodeShape.$fromRdf = $fromRdf;
1066
- function $toRdf(_shaclCoreNodeShape, { ignoreRdfType, mutateGraph, resourceSet, }) {
1067
- const _resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCoreNodeShape, {
1493
+ function $toRdf(_shaclCoreNodeShape, options) {
1494
+ const ignoreRdfType = !!options?.ignoreRdfType;
1495
+ const mutateGraph = options?.mutateGraph;
1496
+ const resourceSet = options?.resourceSet ??
1497
+ new rdfjsResource.MutableResourceSet({
1498
+ dataFactory,
1499
+ dataset: datasetFactory.dataset(),
1500
+ });
1501
+ const resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCoreNodeShape, {
1068
1502
  ignoreRdfType: true,
1069
1503
  mutateGraph,
1070
1504
  resourceSet,
1071
1505
  });
1072
1506
  if (!ignoreRdfType) {
1073
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCoreNodeShape"));
1074
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"));
1507
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCoreNodeShape"));
1508
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"));
1075
1509
  }
1076
- _resource.add(ShaclCoreNodeShape.$properties.closed["identifier"], _shaclCoreNodeShape.closed);
1077
- _resource.add(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], _shaclCoreNodeShape.ignoredProperties.map((value) => value.length > 0
1510
+ resource.add(ShaclCoreNodeShape.$properties.closed["identifier"], _shaclCoreNodeShape.closed);
1511
+ resource.add(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], _shaclCoreNodeShape.ignoredProperties.map((value) => value.length > 0
1078
1512
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
1079
1513
  if (itemIndex === 0) {
1080
1514
  currentSubListResource = listResource;
@@ -1094,8 +1528,8 @@ export var ShaclCoreNodeShape;
1094
1528
  listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
1095
1529
  }).listResource.identifier
1096
1530
  : $RdfVocabularies.rdf.nil));
1097
- _resource.add(ShaclCoreNodeShape.$properties.properties["identifier"], _shaclCoreNodeShape.properties.map((item) => item));
1098
- return _resource;
1531
+ resource.add(ShaclCoreNodeShape.$properties.properties["identifier"], _shaclCoreNodeShape.properties.map((item) => item));
1532
+ return resource;
1099
1533
  }
1100
1534
  ShaclCoreNodeShape.$toRdf = $toRdf;
1101
1535
  ShaclCoreNodeShape.$properties = {
@@ -1125,7 +1559,21 @@ export var OwlOntology;
1125
1559
  $Identifier.fromString = fromString;
1126
1560
  $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
1127
1561
  })($Identifier = OwlOntology.$Identifier || (OwlOntology.$Identifier = {}));
1128
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSetParameter, resource: $resource,
1562
+ function $fromRdf(resource, options) {
1563
+ let { ignoreRdfType = false, languageIn, objectSet, ...context } = options ?? {};
1564
+ if (!objectSet) {
1565
+ objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1566
+ }
1567
+ return OwlOntology.$propertiesFromRdf({
1568
+ ...context,
1569
+ ignoreRdfType,
1570
+ languageIn,
1571
+ objectSet,
1572
+ resource,
1573
+ });
1574
+ }
1575
+ OwlOntology.$fromRdf = $fromRdf;
1576
+ function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, languageIn: $languageIn, objectSet: $objectSet, resource: $resource,
1129
1577
  // @ts-ignore
1130
1578
  ...$context }) {
1131
1579
  if (!$ignoreRdfType && !$resource.isInstanceOf(OwlOntology.$fromRdfType)) {
@@ -1136,23 +1584,51 @@ export var OwlOntology;
1136
1584
  }
1137
1585
  const $identifier = $resource.identifier;
1138
1586
  const $type = "OwlOntology";
1139
- const _labelsEither = purify.Either.sequence($resource
1140
- .values(OwlOntology.$properties.labels["identifier"], { unique: true })
1141
- .map((item) => item
1142
- .toValues()
1143
- .filter((_value) => {
1144
- const _languageInOrDefault = $languageIn ?? [];
1145
- if (_languageInOrDefault.length === 0) {
1146
- return true;
1147
- }
1148
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
1149
- if (typeof _valueLiteral === "undefined") {
1150
- return false;
1151
- }
1152
- return _languageInOrDefault.some((_languageIn) => _languageIn === _valueLiteral.language);
1587
+ const _labelsEither = purify.Either.of($resource.values(OwlOntology.$properties.labels["identifier"], { unique: true }))
1588
+ .chain((values) => {
1589
+ const literalValuesEither = values.chainMap((value) => value.toLiteral());
1590
+ if (literalValuesEither.isLeft()) {
1591
+ return literalValuesEither;
1592
+ }
1593
+ const literalValues = literalValuesEither.unsafeCoerce();
1594
+ const nonUniqueLanguageIn = $languageIn ?? [];
1595
+ if (nonUniqueLanguageIn.length === 0) {
1596
+ return purify.Either.of(literalValues);
1597
+ }
1598
+ let uniqueLanguageIn;
1599
+ if (nonUniqueLanguageIn.length === 1) {
1600
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
1601
+ }
1602
+ else {
1603
+ uniqueLanguageIn = [];
1604
+ for (const languageIn of nonUniqueLanguageIn) {
1605
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
1606
+ uniqueLanguageIn.push(languageIn);
1607
+ }
1608
+ }
1609
+ }
1610
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
1611
+ // Within a languageIn the literals may be in any order.
1612
+ let filteredLiteralValues;
1613
+ for (const languageIn of uniqueLanguageIn) {
1614
+ if (!filteredLiteralValues) {
1615
+ filteredLiteralValues = literalValues.filter((value) => value.language === languageIn);
1616
+ }
1617
+ else {
1618
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1619
+ .filter((value) => value.language === languageIn)
1620
+ .toArray());
1621
+ }
1622
+ }
1623
+ return purify.Either.of(filteredLiteralValues);
1153
1624
  })
1154
- .head()
1155
- .chain((value) => value.toLiteral())));
1625
+ .map((values) => values.toArray())
1626
+ .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1627
+ object: valuesArray,
1628
+ predicate: OwlOntology.$properties.labels["identifier"],
1629
+ subject: $resource,
1630
+ }))
1631
+ .chain((values) => values.head());
1156
1632
  if (_labelsEither.isLeft()) {
1157
1633
  return _labelsEither;
1158
1634
  }
@@ -1160,20 +1636,23 @@ export var OwlOntology;
1160
1636
  return purify.Either.of({ $identifier, $type, labels });
1161
1637
  }
1162
1638
  OwlOntology.$propertiesFromRdf = $propertiesFromRdf;
1163
- function $fromRdf(parameters) {
1164
- return OwlOntology.$propertiesFromRdf(parameters);
1165
- }
1166
- OwlOntology.$fromRdf = $fromRdf;
1167
- function $toRdf(_owlOntology, { ignoreRdfType, mutateGraph, resourceSet, }) {
1168
- const _resource = resourceSet.mutableResource(_owlOntology.$identifier, {
1639
+ function $toRdf(_owlOntology, options) {
1640
+ const ignoreRdfType = !!options?.ignoreRdfType;
1641
+ const mutateGraph = options?.mutateGraph;
1642
+ const resourceSet = options?.resourceSet ??
1643
+ new rdfjsResource.MutableResourceSet({
1644
+ dataFactory,
1645
+ dataset: datasetFactory.dataset(),
1646
+ });
1647
+ const resource = resourceSet.mutableResource(_owlOntology.$identifier, {
1169
1648
  mutateGraph,
1170
1649
  });
1171
1650
  if (!ignoreRdfType) {
1172
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#OwlOntology"));
1173
- _resource.add($RdfVocabularies.rdf.type, _resource.dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"));
1651
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#OwlOntology"));
1652
+ resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"));
1174
1653
  }
1175
- _resource.add(OwlOntology.$properties.labels["identifier"], _owlOntology.labels.map((item) => item));
1176
- return _resource;
1654
+ resource.add(OwlOntology.$properties.labels["identifier"], _owlOntology.labels.map((item) => item));
1655
+ return resource;
1177
1656
  }
1178
1657
  OwlOntology.$toRdf = $toRdf;
1179
1658
  OwlOntology.$properties = {
@@ -1184,10 +1663,13 @@ export var OwlOntology;
1184
1663
  })(OwlOntology || (OwlOntology = {}));
1185
1664
  export var ShaclCoreShape;
1186
1665
  (function (ShaclCoreShape) {
1187
- function $fromRdf({ ignoreRdfType, resource, ...context }) {
1188
- return ShaclCoreNodeShape.$fromRdf({ ...context, resource }).altLazy(() => ShaclCorePropertyShape.$fromRdf({
1189
- ...context,
1190
- resource,
1666
+ function $fromRdf(resource, options) {
1667
+ return ShaclCoreNodeShape.$fromRdf(resource, {
1668
+ ...options,
1669
+ ignoreRdfType: false,
1670
+ }).altLazy(() => ShaclCorePropertyShape.$fromRdf(resource, {
1671
+ ...options,
1672
+ ignoreRdfType: false,
1191
1673
  }));
1192
1674
  }
1193
1675
  ShaclCoreShape.$fromRdf = $fromRdf;
@@ -1392,9 +1874,7 @@ export class $RdfjsDatasetObjectSet {
1392
1874
  }
1393
1875
  const objects = [];
1394
1876
  for (const identifier of identifiers) {
1395
- const either = objectType.$fromRdf({
1396
- resource: this.resourceSet.resource(identifier),
1397
- });
1877
+ const either = objectType.$fromRdf(this.resourceSet.resource(identifier), { objectSet: this });
1398
1878
  if (either.isLeft()) {
1399
1879
  return either;
1400
1880
  }
@@ -1413,7 +1893,7 @@ export class $RdfjsDatasetObjectSet {
1413
1893
  const objects = [];
1414
1894
  let objectI = 0;
1415
1895
  for (const resource of resources) {
1416
- const either = objectType.$fromRdf({ resource });
1896
+ const either = objectType.$fromRdf(resource, { objectSet: this });
1417
1897
  if (either.isLeft()) {
1418
1898
  return either;
1419
1899
  }
@@ -1474,7 +1954,7 @@ export class $RdfjsDatasetObjectSet {
1474
1954
  const resource = this.resourceSet.resource(identifier);
1475
1955
  const lefts = [];
1476
1956
  for (const objectType of objectTypes) {
1477
- const either = objectType.$fromRdf({ resource });
1957
+ const either = objectType.$fromRdf(resource, { objectSet: this });
1478
1958
  if (either.isRight()) {
1479
1959
  objects.push(either.unsafeCoerce());
1480
1960
  break;
@@ -1502,7 +1982,7 @@ export class $RdfjsDatasetObjectSet {
1502
1982
  let objectI = 0;
1503
1983
  const objects = [];
1504
1984
  for (const { objectType, resource } of resources) {
1505
- const either = objectType.$fromRdf({ resource });
1985
+ const either = objectType.$fromRdf(resource, { objectSet: this });
1506
1986
  if (either.isLeft()) {
1507
1987
  return either;
1508
1988
  }