@coasys/ad4m 0.12.0-dev-whisper-lang → 0.12.0-rc1-dev

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.
Files changed (42) hide show
  1. package/lib/index.cjs +1742 -320
  2. package/lib/index.js +1741 -321
  3. package/lib/src/ai/AIClient.d.ts +1 -1
  4. package/lib/src/ai/AIClient.js +4 -5
  5. package/lib/src/ai/AIResolver.d.ts +1 -1
  6. package/lib/src/ai/AIResolver.js +2 -3
  7. package/lib/src/index.d.ts +2 -0
  8. package/lib/src/index.js +2 -0
  9. package/lib/src/model/Ad4mModel.js +17 -5
  10. package/lib/src/model/decorators.js +196 -6
  11. package/lib/src/model/util.d.ts +1 -1
  12. package/lib/src/model/util.js +15 -12
  13. package/lib/src/perspectives/PerspectiveClient.d.ts +11 -1
  14. package/lib/src/perspectives/PerspectiveClient.js +15 -4
  15. package/lib/src/perspectives/PerspectiveProxy.d.ts +124 -8
  16. package/lib/src/perspectives/PerspectiveProxy.js +573 -274
  17. package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -1
  18. package/lib/src/perspectives/PerspectiveResolver.js +5 -4
  19. package/lib/src/schema.gql +2 -2
  20. package/lib/src/shacl/SHACLFlow.d.ts +171 -0
  21. package/lib/src/shacl/SHACLFlow.js +370 -0
  22. package/lib/src/shacl/SHACLFlow.test.d.ts +1 -0
  23. package/lib/src/shacl/SHACLFlow.test.js +205 -0
  24. package/lib/src/shacl/SHACLShape.d.ts +108 -0
  25. package/lib/src/shacl/SHACLShape.js +566 -0
  26. package/lib/src/shacl/SHACLShape.test.d.ts +1 -0
  27. package/lib/src/shacl/SHACLShape.test.js +336 -0
  28. package/lib/src/typeDefs.js +2 -2
  29. package/package.json +1 -2
  30. package/src/ai/AIClient.ts +4 -6
  31. package/src/ai/AIResolver.ts +1 -2
  32. package/src/index.ts +2 -0
  33. package/src/model/Ad4mModel.ts +19 -5
  34. package/src/model/decorators.ts +221 -5
  35. package/src/model/util.ts +15 -12
  36. package/src/perspectives/PerspectiveClient.ts +15 -4
  37. package/src/perspectives/PerspectiveProxy.ts +588 -304
  38. package/src/perspectives/PerspectiveResolver.ts +1 -1
  39. package/src/shacl/SHACLFlow.test.ts +237 -0
  40. package/src/shacl/SHACLFlow.ts +503 -0
  41. package/src/shacl/SHACLShape.test.ts +400 -0
  42. package/src/shacl/SHACLShape.ts +755 -0
@@ -0,0 +1,566 @@
1
+ /**
2
+ * Extract namespace from a URI
3
+ * Examples:
4
+ * - "recipe://name" -> "recipe://"
5
+ * - "https://example.com/vocab#term" -> "https://example.com/vocab#"
6
+ * - "https://example.com/vocab/term" -> "https://example.com/vocab/"
7
+ * - "recipe:Recipe" -> "recipe:"
8
+ */
9
+ function extractNamespace(uri) {
10
+ // Handle hash fragments first (highest priority)
11
+ const hashIndex = uri.lastIndexOf('#');
12
+ if (hashIndex !== -1) {
13
+ return uri.substring(0, hashIndex + 1);
14
+ }
15
+ // Handle protocol-style URIs with paths
16
+ const protocolMatch = uri.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)(.*)$/);
17
+ if (protocolMatch) {
18
+ const afterScheme = protocolMatch[2];
19
+ const lastSlash = afterScheme.lastIndexOf('/');
20
+ if (lastSlash !== -1) {
21
+ // Has path segments - namespace includes up to last slash
22
+ return protocolMatch[1] + afterScheme.substring(0, lastSlash + 1);
23
+ }
24
+ // Simple protocol URI without path (e.g., "recipe://name")
25
+ return protocolMatch[1];
26
+ }
27
+ // Handle colon-separated (namespace:localName)
28
+ const colonMatch = uri.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:)/);
29
+ if (colonMatch) {
30
+ return colonMatch[1];
31
+ }
32
+ // Fallback: no clear namespace
33
+ return '';
34
+ }
35
+ /**
36
+ * Escape special characters for Turtle string literals
37
+ * Handles backslashes, quotes, newlines, and other control characters
38
+ */
39
+ function escapeTurtleString(value) {
40
+ return value
41
+ .replace(/\\/g, '\\\\') // Backslash must be first
42
+ .replace(/"/g, '\\"') // Double quotes
43
+ .replace(/\n/g, '\\n') // Newlines
44
+ .replace(/\r/g, '\\r') // Carriage returns
45
+ .replace(/\t/g, '\\t') // Tabs
46
+ .replace(/\b/g, '\\b') // Backspace
47
+ .replace(/\f/g, '\\f'); // Form feed
48
+ }
49
+ /**
50
+ * Extract local name from a URI
51
+ * Examples:
52
+ * - "recipe://name" -> "name"
53
+ * - "https://example.com/vocab#term" -> "term"
54
+ * - "https://example.com/vocab/term" -> "term"
55
+ * - "recipe:Recipe" -> "Recipe"
56
+ */
57
+ function extractLocalName(uri) {
58
+ // Handle hash fragments
59
+ const hashIndex = uri.lastIndexOf('#');
60
+ if (hashIndex !== -1) {
61
+ return uri.substring(hashIndex + 1);
62
+ }
63
+ // Handle slash-based namespaces
64
+ const lastSlash = uri.lastIndexOf('/');
65
+ if (lastSlash !== -1 && lastSlash < uri.length - 1) {
66
+ return uri.substring(lastSlash + 1);
67
+ }
68
+ // Handle colon-separated
69
+ const colonMatch = uri.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:(.+)$/);
70
+ if (colonMatch) {
71
+ return colonMatch[1];
72
+ }
73
+ // Fallback: entire URI
74
+ return uri;
75
+ }
76
+ /**
77
+ * SHACL Node Shape
78
+ * Defines constraints for instances of a class
79
+ */
80
+ export class SHACLShape {
81
+ /**
82
+ * Create a new SHACL Shape
83
+ * @param targetClassOrShapeUri - If one argument: the target class (shape URI auto-derived as {class}Shape)
84
+ * If two arguments: first is shape URI, second is target class
85
+ * @param targetClass - Optional target class when first arg is shape URI
86
+ */
87
+ constructor(targetClassOrShapeUri, targetClass) {
88
+ if (targetClass !== undefined) {
89
+ // Two arguments: explicit shape URI and target class
90
+ this.nodeShapeUri = targetClassOrShapeUri;
91
+ this.targetClass = targetClass;
92
+ }
93
+ else {
94
+ // One argument: derive shape URI from target class
95
+ this.targetClass = targetClassOrShapeUri;
96
+ // Derive shape URI by appending "Shape" to the local name
97
+ const namespace = extractNamespace(targetClassOrShapeUri);
98
+ const localName = extractLocalName(targetClassOrShapeUri);
99
+ this.nodeShapeUri = `${namespace}${localName}Shape`;
100
+ }
101
+ this.properties = [];
102
+ }
103
+ /**
104
+ * Add a property constraint to this shape
105
+ */
106
+ addProperty(prop) {
107
+ this.properties.push(prop);
108
+ }
109
+ /**
110
+ * Set constructor actions for this shape
111
+ */
112
+ setConstructorActions(actions) {
113
+ this.constructor_actions = actions;
114
+ }
115
+ /**
116
+ * Set destructor actions for this shape
117
+ */
118
+ setDestructorActions(actions) {
119
+ this.destructor_actions = actions;
120
+ }
121
+ /**
122
+ * Serialize shape to Turtle (RDF) format
123
+ */
124
+ toTurtle() {
125
+ let turtle = `@prefix sh: <http://www.w3.org/ns/shacl#> .\n`;
126
+ turtle += `@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n`;
127
+ turtle += `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n`;
128
+ turtle += `@prefix ad4m: <ad4m://> .\n\n`;
129
+ turtle += `<${this.nodeShapeUri}>\n`;
130
+ turtle += ` a sh:NodeShape ;\n`;
131
+ if (this.targetClass) {
132
+ turtle += ` sh:targetClass <${this.targetClass}> ;\n`;
133
+ }
134
+ // Add property shapes
135
+ for (let i = 0; i < this.properties.length; i++) {
136
+ const prop = this.properties[i];
137
+ const isLast = i === this.properties.length - 1;
138
+ turtle += ` sh:property [\n`;
139
+ turtle += ` sh:path <${prop.path}> ;\n`;
140
+ if (prop.datatype) {
141
+ turtle += ` sh:datatype <${prop.datatype}> ;\n`;
142
+ }
143
+ if (prop.nodeKind) {
144
+ turtle += ` sh:nodeKind sh:${prop.nodeKind} ;\n`;
145
+ }
146
+ if (prop.minCount !== undefined) {
147
+ turtle += ` sh:minCount ${prop.minCount} ;\n`;
148
+ }
149
+ if (prop.maxCount !== undefined) {
150
+ turtle += ` sh:maxCount ${prop.maxCount} ;\n`;
151
+ }
152
+ if (prop.pattern) {
153
+ turtle += ` sh:pattern "${escapeTurtleString(prop.pattern)}" ;\n`;
154
+ }
155
+ if (prop.minInclusive !== undefined) {
156
+ turtle += ` sh:minInclusive ${prop.minInclusive} ;\n`;
157
+ }
158
+ if (prop.maxInclusive !== undefined) {
159
+ turtle += ` sh:maxInclusive ${prop.maxInclusive} ;\n`;
160
+ }
161
+ if (prop.hasValue) {
162
+ turtle += ` sh:hasValue "${escapeTurtleString(prop.hasValue)}" ;\n`;
163
+ }
164
+ // AD4M-specific metadata
165
+ if (prop.local !== undefined) {
166
+ turtle += ` ad4m:local ${prop.local} ;\n`;
167
+ }
168
+ if (prop.writable !== undefined) {
169
+ turtle += ` ad4m:writable ${prop.writable} ;\n`;
170
+ }
171
+ // Remove trailing semicolon and close bracket
172
+ turtle = turtle.slice(0, -2) + '\n';
173
+ turtle += isLast ? ` ] .\n` : ` ] ;\n`;
174
+ }
175
+ return turtle;
176
+ }
177
+ /**
178
+ * Serialize shape to AD4M Links (RDF triples)
179
+ * Stores the shape as a graph of links in a Perspective
180
+ */
181
+ toLinks() {
182
+ const links = [];
183
+ // Shape type declaration
184
+ links.push({
185
+ source: this.nodeShapeUri,
186
+ predicate: "rdf://type",
187
+ target: "sh://NodeShape"
188
+ });
189
+ // Target class
190
+ if (this.targetClass) {
191
+ links.push({
192
+ source: this.nodeShapeUri,
193
+ predicate: "sh://targetClass",
194
+ target: this.targetClass
195
+ });
196
+ }
197
+ // Constructor actions
198
+ if (this.constructor_actions && this.constructor_actions.length > 0) {
199
+ links.push({
200
+ source: this.nodeShapeUri,
201
+ predicate: "ad4m://constructor",
202
+ target: `literal://string:${JSON.stringify(this.constructor_actions)}`
203
+ });
204
+ }
205
+ // Destructor actions
206
+ if (this.destructor_actions && this.destructor_actions.length > 0) {
207
+ links.push({
208
+ source: this.nodeShapeUri,
209
+ predicate: "ad4m://destructor",
210
+ target: `literal://string:${JSON.stringify(this.destructor_actions)}`
211
+ });
212
+ }
213
+ // Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
214
+ for (let i = 0; i < this.properties.length; i++) {
215
+ const prop = this.properties[i];
216
+ // Generate named property shape URI
217
+ let propShapeId;
218
+ if (prop.name && this.targetClass) {
219
+ // Extract namespace from targetClass
220
+ const namespace = extractNamespace(this.targetClass);
221
+ const className = extractLocalName(this.targetClass);
222
+ // Use format: {namespace}{ClassName}.{propertyName}
223
+ propShapeId = `${namespace}${className}.${prop.name}`;
224
+ }
225
+ else {
226
+ // Fallback to blank node if name is missing
227
+ propShapeId = `_:propShape${i}`;
228
+ }
229
+ // Link shape to property shape
230
+ links.push({
231
+ source: this.nodeShapeUri,
232
+ predicate: "sh://property",
233
+ target: propShapeId
234
+ });
235
+ // Property path
236
+ links.push({
237
+ source: propShapeId,
238
+ predicate: "sh://path",
239
+ target: prop.path
240
+ });
241
+ // Constraints
242
+ if (prop.datatype) {
243
+ links.push({
244
+ source: propShapeId,
245
+ predicate: "sh://datatype",
246
+ target: prop.datatype
247
+ });
248
+ }
249
+ if (prop.nodeKind) {
250
+ links.push({
251
+ source: propShapeId,
252
+ predicate: "sh://nodeKind",
253
+ target: `sh://${prop.nodeKind}`
254
+ });
255
+ }
256
+ if (prop.minCount !== undefined) {
257
+ links.push({
258
+ source: propShapeId,
259
+ predicate: "sh://minCount",
260
+ target: `literal://${prop.minCount}^^xsd:integer`
261
+ });
262
+ }
263
+ if (prop.maxCount !== undefined) {
264
+ links.push({
265
+ source: propShapeId,
266
+ predicate: "sh://maxCount",
267
+ target: `literal://${prop.maxCount}^^xsd:integer`
268
+ });
269
+ }
270
+ if (prop.pattern) {
271
+ links.push({
272
+ source: propShapeId,
273
+ predicate: "sh://pattern",
274
+ target: `literal://${prop.pattern}`
275
+ });
276
+ }
277
+ if (prop.minInclusive !== undefined) {
278
+ links.push({
279
+ source: propShapeId,
280
+ predicate: "sh://minInclusive",
281
+ target: `literal://${prop.minInclusive}`
282
+ });
283
+ }
284
+ if (prop.maxInclusive !== undefined) {
285
+ links.push({
286
+ source: propShapeId,
287
+ predicate: "sh://maxInclusive",
288
+ target: `literal://${prop.maxInclusive}`
289
+ });
290
+ }
291
+ if (prop.hasValue) {
292
+ links.push({
293
+ source: propShapeId,
294
+ predicate: "sh://hasValue",
295
+ target: `literal://${prop.hasValue}`
296
+ });
297
+ }
298
+ // AD4M-specific metadata
299
+ if (prop.local !== undefined) {
300
+ links.push({
301
+ source: propShapeId,
302
+ predicate: "ad4m://local",
303
+ target: `literal://${prop.local}`
304
+ });
305
+ }
306
+ if (prop.writable !== undefined) {
307
+ links.push({
308
+ source: propShapeId,
309
+ predicate: "ad4m://writable",
310
+ target: `literal://${prop.writable}`
311
+ });
312
+ }
313
+ if (prop.resolveLanguage) {
314
+ links.push({
315
+ source: propShapeId,
316
+ predicate: "ad4m://resolveLanguage",
317
+ target: `literal://string:${prop.resolveLanguage}`
318
+ });
319
+ }
320
+ // AD4M-specific actions
321
+ if (prop.setter && prop.setter.length > 0) {
322
+ links.push({
323
+ source: propShapeId,
324
+ predicate: "ad4m://setter",
325
+ target: `literal://string:${JSON.stringify(prop.setter)}`
326
+ });
327
+ }
328
+ if (prop.adder && prop.adder.length > 0) {
329
+ links.push({
330
+ source: propShapeId,
331
+ predicate: "ad4m://adder",
332
+ target: `literal://string:${JSON.stringify(prop.adder)}`
333
+ });
334
+ }
335
+ if (prop.remover && prop.remover.length > 0) {
336
+ links.push({
337
+ source: propShapeId,
338
+ predicate: "ad4m://remover",
339
+ target: `literal://string:${JSON.stringify(prop.remover)}`
340
+ });
341
+ }
342
+ }
343
+ return links;
344
+ }
345
+ /**
346
+ * Reconstruct shape from AD4M Links
347
+ */
348
+ static fromLinks(links, shapeUri) {
349
+ // Find target class
350
+ const targetClassLink = links.find(l => l.source === shapeUri && l.predicate === "sh://targetClass");
351
+ const shape = new SHACLShape(shapeUri, targetClassLink?.target);
352
+ // Find constructor actions
353
+ const constructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://constructor");
354
+ if (constructorLink) {
355
+ try {
356
+ const jsonStr = constructorLink.target.replace('literal://string:', '');
357
+ shape.constructor_actions = JSON.parse(jsonStr);
358
+ }
359
+ catch (e) {
360
+ // Ignore parse errors
361
+ }
362
+ }
363
+ // Find destructor actions
364
+ const destructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://destructor");
365
+ if (destructorLink) {
366
+ try {
367
+ const jsonStr = destructorLink.target.replace('literal://string:', '');
368
+ shape.destructor_actions = JSON.parse(jsonStr);
369
+ }
370
+ catch (e) {
371
+ // Ignore parse errors
372
+ }
373
+ }
374
+ // Find all property shapes
375
+ const propShapeLinks = links.filter(l => l.source === shapeUri && l.predicate === "sh://property");
376
+ for (const propLink of propShapeLinks) {
377
+ const propShapeId = propLink.target;
378
+ // Reconstruct property from its links
379
+ const pathLink = links.find(l => l.source === propShapeId && l.predicate === "sh://path");
380
+ if (!pathLink)
381
+ continue;
382
+ // Extract property name from propShapeId if it's a named URI
383
+ // Format: {namespace}{ClassName}.{propertyName}
384
+ let propertyName;
385
+ if (!propShapeId.startsWith('_:')) {
386
+ const lastDotIndex = propShapeId.lastIndexOf('.');
387
+ if (lastDotIndex !== -1) {
388
+ propertyName = propShapeId.substring(lastDotIndex + 1);
389
+ }
390
+ }
391
+ const prop = {
392
+ name: propertyName,
393
+ path: pathLink.target
394
+ };
395
+ // Extract constraints
396
+ const datatypeLink = links.find(l => l.source === propShapeId && l.predicate === "sh://datatype");
397
+ if (datatypeLink)
398
+ prop.datatype = datatypeLink.target;
399
+ const nodeKindLink = links.find(l => l.source === propShapeId && l.predicate === "sh://nodeKind");
400
+ if (nodeKindLink) {
401
+ prop.nodeKind = nodeKindLink.target.replace('sh://', '');
402
+ }
403
+ const minCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minCount");
404
+ if (minCountLink) {
405
+ // Handle both formats: literal://5^^xsd:integer and literal://number:5
406
+ let val = minCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
407
+ if (val.startsWith('number:'))
408
+ val = val.substring(7);
409
+ prop.minCount = parseInt(val);
410
+ }
411
+ const maxCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxCount");
412
+ if (maxCountLink) {
413
+ // Handle both formats: literal://5^^xsd:integer and literal://number:5
414
+ let val = maxCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
415
+ if (val.startsWith('number:'))
416
+ val = val.substring(7);
417
+ prop.maxCount = parseInt(val);
418
+ }
419
+ const patternLink = links.find(l => l.source === propShapeId && l.predicate === "sh://pattern");
420
+ if (patternLink) {
421
+ prop.pattern = patternLink.target.replace('literal://', '');
422
+ }
423
+ const minInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minInclusive");
424
+ if (minInclusiveLink) {
425
+ // Handle both formats: literal://5 and literal://number:5
426
+ let val = minInclusiveLink.target.replace('literal://', '');
427
+ if (val.startsWith('number:'))
428
+ val = val.substring(7);
429
+ prop.minInclusive = parseFloat(val);
430
+ }
431
+ const maxInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxInclusive");
432
+ if (maxInclusiveLink) {
433
+ // Handle both formats: literal://5 and literal://number:5
434
+ let val = maxInclusiveLink.target.replace('literal://', '');
435
+ if (val.startsWith('number:'))
436
+ val = val.substring(7);
437
+ prop.maxInclusive = parseFloat(val);
438
+ }
439
+ const hasValueLink = links.find(l => l.source === propShapeId && l.predicate === "sh://hasValue");
440
+ if (hasValueLink) {
441
+ prop.hasValue = hasValueLink.target.replace('literal://', '');
442
+ }
443
+ // AD4M-specific
444
+ const localLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://local");
445
+ if (localLink) {
446
+ // Handle both formats: literal://true and literal://boolean:true
447
+ let val = localLink.target.replace('literal://', '');
448
+ if (val.startsWith('boolean:'))
449
+ val = val.substring(8);
450
+ prop.local = val === 'true';
451
+ }
452
+ const writableLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://writable");
453
+ if (writableLink) {
454
+ // Handle both formats: literal://true and literal://boolean:true
455
+ let val = writableLink.target.replace('literal://', '');
456
+ if (val.startsWith('boolean:'))
457
+ val = val.substring(8);
458
+ prop.writable = val === 'true';
459
+ }
460
+ const resolveLangLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
461
+ if (resolveLangLink) {
462
+ prop.resolveLanguage = resolveLangLink.target.replace('literal://string:', '');
463
+ }
464
+ // Parse action arrays
465
+ const setterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://setter");
466
+ if (setterLink) {
467
+ try {
468
+ const jsonStr = setterLink.target.replace('literal://string:', '');
469
+ prop.setter = JSON.parse(jsonStr);
470
+ }
471
+ catch (e) {
472
+ // Ignore parse errors
473
+ }
474
+ }
475
+ const adderLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://adder");
476
+ if (adderLink) {
477
+ try {
478
+ const jsonStr = adderLink.target.replace('literal://string:', '');
479
+ prop.adder = JSON.parse(jsonStr);
480
+ }
481
+ catch (e) {
482
+ // Ignore parse errors
483
+ }
484
+ }
485
+ const removerLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://remover");
486
+ if (removerLink) {
487
+ try {
488
+ const jsonStr = removerLink.target.replace('literal://string:', '');
489
+ prop.remover = JSON.parse(jsonStr);
490
+ }
491
+ catch (e) {
492
+ // Ignore parse errors
493
+ }
494
+ }
495
+ shape.addProperty(prop);
496
+ }
497
+ return shape;
498
+ }
499
+ /**
500
+ * Convert the shape to a JSON-serializable object.
501
+ * Useful for passing to addSdna() as shaclJson parameter.
502
+ *
503
+ * @returns JSON-serializable object representing the shape
504
+ */
505
+ toJSON() {
506
+ return {
507
+ node_shape_uri: this.nodeShapeUri,
508
+ target_class: this.targetClass,
509
+ properties: this.properties.map(p => ({
510
+ path: p.path,
511
+ name: p.name,
512
+ datatype: p.datatype,
513
+ node_kind: p.nodeKind,
514
+ min_count: p.minCount,
515
+ max_count: p.maxCount,
516
+ min_inclusive: p.minInclusive,
517
+ max_inclusive: p.maxInclusive,
518
+ pattern: p.pattern,
519
+ has_value: p.hasValue,
520
+ local: p.local,
521
+ writable: p.writable,
522
+ resolve_language: p.resolveLanguage,
523
+ setter: p.setter,
524
+ adder: p.adder,
525
+ remover: p.remover,
526
+ })),
527
+ constructor_actions: this.constructor_actions,
528
+ destructor_actions: this.destructor_actions,
529
+ };
530
+ }
531
+ /**
532
+ * Create a shape from a JSON object (inverse of toJSON)
533
+ */
534
+ static fromJSON(json) {
535
+ const shape = json.node_shape_uri
536
+ ? new SHACLShape(json.node_shape_uri, json.target_class)
537
+ : new SHACLShape(json.target_class);
538
+ for (const p of json.properties || []) {
539
+ shape.addProperty({
540
+ path: p.path,
541
+ name: p.name,
542
+ datatype: p.datatype,
543
+ nodeKind: p.node_kind,
544
+ minCount: p.min_count,
545
+ maxCount: p.max_count,
546
+ minInclusive: p.min_inclusive,
547
+ maxInclusive: p.max_inclusive,
548
+ pattern: p.pattern,
549
+ hasValue: p.has_value,
550
+ local: p.local,
551
+ writable: p.writable,
552
+ resolveLanguage: p.resolve_language,
553
+ setter: p.setter,
554
+ adder: p.adder,
555
+ remover: p.remover,
556
+ });
557
+ }
558
+ if (json.constructor_actions) {
559
+ shape.constructor_actions = json.constructor_actions;
560
+ }
561
+ if (json.destructor_actions) {
562
+ shape.destructor_actions = json.destructor_actions;
563
+ }
564
+ return shape;
565
+ }
566
+ }
@@ -0,0 +1 @@
1
+ export {};