@coasys/ad4m 0.13.0-test-9 → 0.13.0-test-interpretation-1

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 (44) hide show
  1. package/lib/index.cjs +370 -8
  2. package/lib/index.js +371 -9
  3. package/lib/src/ai/AIClient.js +3 -1
  4. package/lib/src/apiClient.d.ts +4 -1
  5. package/lib/src/apiClient.js +7 -3
  6. package/lib/src/generated/api/RunInterpretationRequest.d.ts +19 -0
  7. package/lib/src/generated/api/RunInterpretationRequest.js +1 -0
  8. package/lib/src/generated/api/TranscriptTurn.d.ts +7 -0
  9. package/lib/src/generated/api/TranscriptTurn.js +2 -0
  10. package/lib/src/generated/api/index.d.ts +2 -0
  11. package/lib/src/index.d.ts +2 -0
  12. package/lib/src/index.js +2 -0
  13. package/lib/src/model/ModelQueryBuilder.js +1 -1
  14. package/lib/src/model/decorators.d.ts +25 -0
  15. package/lib/src/model/decorators.js +1 -1
  16. package/lib/src/model/shacl-gen.d.ts +8 -1
  17. package/lib/src/model/shacl-gen.js +21 -1
  18. package/lib/src/perspectives/AutoProcessor.d.ts +89 -0
  19. package/lib/src/perspectives/AutoProcessor.js +5 -0
  20. package/lib/src/perspectives/InterpretationModels.d.ts +71 -0
  21. package/lib/src/perspectives/InterpretationModels.js +190 -0
  22. package/lib/src/perspectives/PerspectiveClient.d.ts +37 -0
  23. package/lib/src/perspectives/PerspectiveClient.js +54 -0
  24. package/lib/src/perspectives/PerspectiveProxy.d.ts +43 -1
  25. package/lib/src/perspectives/PerspectiveProxy.js +53 -1
  26. package/lib/src/shacl/SHACLShape.d.ts +14 -0
  27. package/lib/src/shacl/SHACLShape.js +45 -0
  28. package/package.json +6 -2
  29. package/src/ai/AIClient.ts +3 -1
  30. package/src/apiClient.ts +7 -3
  31. package/src/generated/api/RunInterpretationRequest.ts +18 -0
  32. package/src/generated/api/TranscriptTurn.ts +6 -0
  33. package/src/generated/api/index.ts +2 -0
  34. package/src/index.ts +2 -0
  35. package/src/model/ModelQueryBuilder.ts +1 -1
  36. package/src/model/decorators.ts +29 -0
  37. package/src/model/shacl-gen.ts +22 -0
  38. package/src/model/shacl-roundtrip.test.ts +76 -0
  39. package/src/perspectives/AutoProcessor.ts +107 -0
  40. package/src/perspectives/InterpretationModels.ts +145 -0
  41. package/src/perspectives/PerspectiveClient.ts +75 -0
  42. package/src/perspectives/PerspectiveProxy.ts +61 -1
  43. package/src/shacl/SHACLShape.test.ts +26 -0
  44. package/src/shacl/SHACLShape.ts +82 -4
@@ -0,0 +1,145 @@
1
+ /**
2
+ * TypeScript @Model classes mirroring the Rust-side SDNA for the generic
3
+ * interpretation subsystem. Apps can import these to query the perspective
4
+ * graph for interpretation history and pending overlay proposals without
5
+ * knowing the raw link predicates.
6
+ *
7
+ * Registration:
8
+ * await InterpretationOverlay.register(perspective);
9
+ * await InterpretationRun.register(perspective);
10
+ * await AutoProcessorConfig.register(perspective);
11
+ *
12
+ * Querying:
13
+ * const pending = await InterpretationOverlay.findAll(perspective);
14
+ * const runs = await InterpretationRun.findAll(perspective);
15
+ * const configs = await AutoProcessorConfig.findAll(perspective);
16
+ */
17
+
18
+ import { Ad4mModel } from "../model/Ad4mModel";
19
+ import { Flag, HasMany, Optional, Property } from "../model/decorators";
20
+ import { Model } from "../model/decorators";
21
+
22
+ // ── AutoProcessorConfig ─────────────────────────────────────────────────────
23
+ // Mirrors the Rust `auto_processor::config::AutoProcessorConfig` SDNA.
24
+ // One node per registered processor; the node URI is
25
+ // `ad4m://autoprocessor/<processorId>`.
26
+
27
+ @Model({ name: "AutoProcessorConfig" })
28
+ export class AutoProcessorConfig extends Ad4mModel {
29
+ @Flag({ through: "rdf://type", value: "ad4m://AutoProcessor" })
30
+ type: string = "ad4m://AutoProcessor";
31
+
32
+ /** Unique processor id — the dedup key for auto-processor instances. */
33
+ @Property({ through: "ad4m://processor_id", required: true, identity: true })
34
+ processorId: string = "";
35
+
36
+ /** SPARQL SELECT that gathers source items each pass. */
37
+ @Property({ through: "ad4m://source_scope_query", required: true })
38
+ sourceScopeQuery: string = "";
39
+
40
+ /** URI prefix for minted instances; omit for the per-processor default. */
41
+ @Optional({ through: "ad4m://base_prefix", resolveLanguage: "literal" })
42
+ basePrefix?: string;
43
+
44
+ /** Class URIs (SHACL targetClass) to materialise each pass. */
45
+ @HasMany({ through: "ad4m://interpretation_class" })
46
+ interpretationClasses: string[] = [];
47
+
48
+ /** Quiet-window (ms) after the last new item before a pass runs. */
49
+ @Property({ through: "ad4m://debounce_ms", required: true })
50
+ debounceMs: string = "200";
51
+
52
+ /** Minimum batch size before a pass runs (default 1). */
53
+ @Optional({ through: "ad4m://batch_min", resolveLanguage: "literal" })
54
+ batchMin?: string;
55
+
56
+ /** Maximum items per pass. */
57
+ @Property({ through: "ad4m://batch_max", required: true })
58
+ batchMax: string = "32";
59
+
60
+ /** Safety flush (ms) for a sub-`batchMin` batch; absent = wait indefinitely. */
61
+ @Optional({ through: "ad4m://max_wait_ms", resolveLanguage: "literal" })
62
+ maxWaitMs?: string;
63
+
64
+ /** How long a won claim is authoritative before peers may re-claim (ms). */
65
+ @Property({ through: "ad4m://claim_ttl_ms", required: true })
66
+ claimTtlMs: string = "60000";
67
+
68
+ /** How far back (ms) each pass looks; absent = unbounded. */
69
+ @Optional({ through: "ad4m://source_window_ms", resolveLanguage: "literal" })
70
+ sourceWindowMs?: string;
71
+
72
+ /** Serialised `DedupStrategy` JSON (absent = NormalizedString). */
73
+ @Optional({ through: "ad4m://dedup_strategy", resolveLanguage: "literal" })
74
+ dedupStrategy?: string;
75
+ }
76
+
77
+ // ── InterpretationRun ───────────────────────────────────────────────────────
78
+ // Mirrors the Rust `interpretation::overlay::InterpretationRun` SDNA.
79
+ // One node per completed pass; the node URI is `ad4m://interp/run/<runId>`.
80
+
81
+ @Model({ name: "InterpretationRun" })
82
+ export class InterpretationRun extends Ad4mModel {
83
+ @Flag({ through: "ad4m://type", value: "ad4m://interpretation-run" })
84
+ type: string = "ad4m://interpretation-run";
85
+
86
+ /** UUID for this run — the dedup key across run nodes. */
87
+ @Property({ through: "ad4m://interp/run_id", required: true, identity: true })
88
+ runId: string = "";
89
+
90
+ /** LLM model id used for this run. */
91
+ @Optional({ through: "ad4m://interp/model", resolveLanguage: "literal" })
92
+ model?: string;
93
+
94
+ /** SHA-256 hex of the system prompt + few-shots at the time of the run. */
95
+ @Optional({ through: "ad4m://interp/prompt_version", resolveLanguage: "literal" })
96
+ promptVersion?: string;
97
+
98
+ /** RFC3339 timestamp when the run completed. */
99
+ @Optional({ through: "ad4m://interp/ran_at", resolveLanguage: "literal" })
100
+ ranAt?: string;
101
+
102
+ /** URI of the AutoProcessorConfig node that triggered this run. */
103
+ @Optional({ through: "ad4m://interp/processor", resolveLanguage: "literal" })
104
+ processor?: string;
105
+
106
+ /**
107
+ * Source item IDs consumed by this pass.
108
+ * Stored as multiple links with the same predicate; the processed-turn
109
+ * cursor uses these to avoid re-interpreting a turn.
110
+ */
111
+ @HasMany({ through: "ad4m://interp/sources" })
112
+ sources: string[] = [];
113
+ }
114
+
115
+ // ── InterpretationOverlay ───────────────────────────────────────────────────
116
+ // Mirrors the Rust `interpretation::overlay::InterpretationOverlay` SDNA.
117
+ // An overlay sits on the *same* base URI as the proposed instance — it is a
118
+ // pending LLM suggestion awaiting human accept/reject.
119
+ //
120
+ // The dynamic "inferred" values are stored as links with predicates of the
121
+ // form `ad4m://interp/inferred/<realPredicate>` and are NOT captured here as
122
+ // fixed @Property fields because the predicates vary per class. Read them
123
+ // directly via perspective.get({ source: overlay.baseExpression }).
124
+ //
125
+ // Accept → perspective.acceptInterpretationOverlay(base) [deletes the overlay]
126
+ // Reject → perspective.rejectInterpretationOverlay(base) [drops the suggestion]
127
+ //
128
+ // Note: `findAll` finds ALL nodes that currently carry a `kind` link, i.e.
129
+ // all pending proposals. Accepted/rejected overlays are removed from the
130
+ // graph and will not appear.
131
+
132
+ @Model({ name: "InterpretationOverlay" })
133
+ export class InterpretationOverlay extends Ad4mModel {
134
+ /**
135
+ * Whether the LLM authored the whole instance (`"create"`) or proposed
136
+ * changes to an existing one (`"update"`). This is the discriminator link
137
+ * that makes a node identifiable as an overlay.
138
+ */
139
+ @Property({ through: "ad4m://interp/kind", required: true, resolveLanguage: "literal" })
140
+ kind: string = "";
141
+
142
+ /** URI of the InterpretationRun that last wrote this overlay, if present. */
143
+ @Optional({ through: "ad4m://interp/run", resolveLanguage: "literal" })
144
+ run?: string;
145
+ }
@@ -10,6 +10,8 @@ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
10
10
  import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
11
11
  import { AIClient } from "../ai/AIClient";
12
12
  import { AllInstancesResult } from "../model/types";
13
+ import type { TranscriptTurn } from "../generated/api";
14
+ import type { AddAutoProcessorConfig, AutoProcessorEvent, InterpretationOverlayInfo } from "./AutoProcessor";
13
15
 
14
16
  export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null
15
17
  export type UuidCallback = (uuid: string) => null
@@ -249,6 +251,79 @@ export class PerspectiveClient {
249
251
  )
250
252
  }
251
253
 
254
+ /**
255
+ * Run generic LLM interpretation over a transcript into this perspective's own
256
+ * SHACL subject classes. The target shapes are resolved server-side from the
257
+ * perspective's registered subject classes, so you pass only the transcript.
258
+ * Returns the freshly minted instances (their base URIs + the links written).
259
+ *
260
+ * The server-side call prompts an LLM (up to `INTERPRETATION_MAX_ATTEMPTS`
261
+ * retries on parse failure), so it can legitimately take minutes on slower
262
+ * or CPU-only models. We raise the default 30s RPC timeout here to 20 min
263
+ * (matches the CI `--timeout 1200000` for the interpretation tests).
264
+ */
265
+ async runInterpretation(uuid: string, transcript: TranscriptTurn[], basePrefix: string, classes?: string[]): Promise<string[]> {
266
+ const RUN_INTERPRETATION_TIMEOUT_MS = 20 * 60 * 1000
267
+ return this.#apiClient.call<string[]>(
268
+ 'perspective.runInterpretation', { uuid, transcript, basePrefix, classes },
269
+ RUN_INTERPRETATION_TIMEOUT_MS,
270
+ )
271
+ }
272
+
273
+ /**
274
+ * Register a neighbourhood auto-processor on this perspective. The executor's
275
+ * watch loop then runs interpretation automatically over new source items
276
+ * (like Flux per channel), coordinating which peer processes each batch via
277
+ * the shared-graph ProcessingClaim, and emits step signals on the events
278
+ * WebSocket (subscribe via {@link addAutoProcessorEventListener}).
279
+ * Returns the processor id.
280
+ */
281
+ async addAutoProcessor(uuid: string, config: AddAutoProcessorConfig): Promise<string> {
282
+ return this.#apiClient.call<string>(
283
+ 'perspective.addAutoProcessor', { uuid, ...config },
284
+ )
285
+ }
286
+
287
+ /** Pending interpretation overlays (LLM suggestions awaiting human accept/reject). */
288
+ async interpretationOverlays(uuid: string): Promise<InterpretationOverlayInfo[]> {
289
+ return this.#apiClient.call<InterpretationOverlayInfo[]>(
290
+ 'perspective.interpretationOverlays', { uuid },
291
+ )
292
+ }
293
+
294
+ /** Accept an overlay's suggestion(s): the LLM value becomes the real value and
295
+ * the overlay is deleted. Omit `property` to accept the whole base. */
296
+ async acceptInterpretation(uuid: string, base: string, property?: string): Promise<boolean> {
297
+ return this.#apiClient.call<boolean>(
298
+ 'perspective.acceptInterpretation', { uuid, base, property },
299
+ )
300
+ }
301
+
302
+ /** Reject an overlay's suggestion(s). Omit `property` to reject the whole base
303
+ * (a rejected `create` deletes the suggested instance). */
304
+ async rejectInterpretation(uuid: string, base: string, property?: string): Promise<boolean> {
305
+ return this.#apiClient.call<boolean>(
306
+ 'perspective.rejectInterpretation', { uuid, base, property },
307
+ )
308
+ }
309
+
310
+ /**
311
+ * Subscribe to auto-processor step signals. `cb` fires for every
312
+ * `auto-processor-event` on `uuid` (BatchReady → Claimed/BackedOff/… →
313
+ * Processed), letting a UI show progress and await the next batch.
314
+ */
315
+ async addAutoProcessorEventListener(uuid: String, cb: (event: AutoProcessorEvent) => void): Promise<void> {
316
+ const unsub = this.#apiClient.subscribe(
317
+ (data) => {
318
+ if (data.type === 'auto-processor-event' && data.perspectiveUuid === uuid) {
319
+ cb(data as unknown as AutoProcessorEvent)
320
+ }
321
+ }
322
+ )
323
+ this.#unsubscribers.push(unsub)
324
+ await this.#apiClient.waitForSubscription()
325
+ }
326
+
252
327
  async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
253
328
  return this.#apiClient.call<LinkExpression>(
254
329
  'perspective.addLinkExpression', { uuid, link, status, batchId }
@@ -12,9 +12,11 @@ import { AIClient } from "../ai/AIClient";
12
12
  import { getPropertiesMetadata, getRelationsMetadata } from "../model/decorators";
13
13
  import { getCachedResult, setCachedResult, invalidatePerspectiveCache } from "../model/query-cache";
14
14
  import { AllInstancesResult } from "../model/types";
15
+ import type { TranscriptTurn } from "../generated/api";
15
16
 
16
17
  import { SHACLShape } from "../shacl/SHACLShape";
17
18
  import { SHACLFlow, LinkPattern } from "../shacl/SHACLFlow";
19
+ import type { AddAutoProcessorConfig, AutoProcessorEvent, InterpretationOverlayInfo } from "./AutoProcessor";
18
20
 
19
21
  type QueryCallback = (result: AllInstancesResult) => void;
20
22
 
@@ -546,6 +548,64 @@ export class PerspectiveProxy {
546
548
  return await this.#client.queryLinks(this.#handle.uuid, query)
547
549
  }
548
550
 
551
+ /**
552
+ * Runs generic LLM interpretation over a conversation transcript, turning it
553
+ * into typed instances of this perspective's own SHACL subject classes
554
+ * (steered by each class's `@InterpretationHint`). The target shapes are
555
+ * resolved automatically from the perspective's registered classes, so you
556
+ * pass only the transcript. New instances are written as links into this
557
+ * perspective; the returned placements list each instance's base URI and
558
+ * the links written for it.
559
+ *
560
+ * @param transcript ordered `{ speaker, text }` turns
561
+ * @param basePrefix URI namespace for new instance identities, e.g. `soa://ext/`
562
+ * @param classes local names of the subject classes to extract into; omit for all
563
+ */
564
+ async runInterpretation(transcript: TranscriptTurn[], basePrefix: string, classes?: string[]): Promise<string[]> {
565
+ return await this.#client.runInterpretation(this.#handle.uuid, transcript, basePrefix, classes)
566
+ }
567
+
568
+ /**
569
+ * Register a neighbourhood auto-processor on this perspective. The executor
570
+ * then runs interpretation automatically over new source items (like Flux
571
+ * per channel), coordinating which peer processes each batch. Returns the
572
+ * processor id. Subscribe to progress via {@link addAutoProcessorEventListener}.
573
+ */
574
+ async addAutoProcessor(config: AddAutoProcessorConfig): Promise<string> {
575
+ return await this.#client.addAutoProcessor(this.#handle.uuid, config)
576
+ }
577
+
578
+ /**
579
+ * Pending interpretation overlays on this perspective — LLM suggestions the
580
+ * §4 divergence gate staged rather than applied, awaiting human accept/reject.
581
+ */
582
+ async interpretationOverlays(): Promise<InterpretationOverlayInfo[]> {
583
+ return await this.#client.interpretationOverlays(this.#handle.uuid)
584
+ }
585
+
586
+ /**
587
+ * Accept an interpretation overlay's suggestion(s): the LLM's staged value
588
+ * becomes the real, human-owned value and the overlay is deleted. Pass
589
+ * `property` to accept a single predicate; omit it for the whole base.
590
+ */
591
+ async acceptInterpretation(base: string, property?: string): Promise<boolean> {
592
+ return await this.#client.acceptInterpretation(this.#handle.uuid, base, property)
593
+ }
594
+
595
+ /**
596
+ * Reject an interpretation overlay's suggestion(s). Omit `property` to reject
597
+ * the whole base — a rejected `create` deletes the suggested instance, a
598
+ * rejected `update` drops the overlay and keeps the real value.
599
+ */
600
+ async rejectInterpretation(base: string, property?: string): Promise<boolean> {
601
+ return await this.#client.rejectInterpretation(this.#handle.uuid, base, property)
602
+ }
603
+
604
+ /** Subscribe to this perspective's auto-processor step signals. */
605
+ async addAutoProcessorEventListener(cb: (event: AutoProcessorEvent) => void): Promise<void> {
606
+ return await this.#client.addAutoProcessorEventListener(this.#handle.uuid, cb)
607
+ }
608
+
549
609
  /**
550
610
  * Executes a Prolog query against the perspective's knowledge base.
551
611
  * This is a powerful way to find complex patterns in the graph.
@@ -639,7 +699,7 @@ export class PerspectiveProxy {
639
699
  * internally in Rust, registers a subscription, runs the initial query, and
640
700
  * pushes updated results when relevant links change.
641
701
  *
642
- * The subscription reuses the same GraphQL subscription channel as subscribeQuery().
702
+ * The subscription reuses the same WS-RPC subscription channel as subscribeQuery().
643
703
  * Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
644
704
  *
645
705
  * @param className - The model class name
@@ -601,6 +601,32 @@ describe('SHACLShape', () => {
601
601
  expect(prop.wherePredicates).toEqual({ status: 'ns://status' });
602
602
  expect(prop.filter).toBe(false);
603
603
  });
604
+
605
+ // Regression: identity is the interpretation-engine dedup key. If it goes
606
+ // missing on the ORM registration path (Ad4mModel.registerAll → toJSON),
607
+ // the interpreter loses "already exists" awareness and re-mints instances
608
+ // on every pass — very costly for AutoProcessor watches. toLinks/fromLinks
609
+ // already carry identity; toJSON/fromJSON must too.
610
+ it('preserves identity through toJSON() → fromJSON()', () => {
611
+ const original = new SHACLShape('ns://Task');
612
+ original.addProperty({
613
+ name: 'title',
614
+ path: 'ns://title',
615
+ datatype: 'xsd:string',
616
+ identity: true,
617
+ });
618
+ original.addProperty({
619
+ name: 'body',
620
+ path: 'ns://body',
621
+ datatype: 'xsd:string',
622
+ });
623
+
624
+ const json = original.toJSON();
625
+ const reconstructed = SHACLShape.fromJSON(json);
626
+
627
+ expect(reconstructed.properties[0].identity).toBe(true);
628
+ expect(reconstructed.properties[1].identity).toBeUndefined();
629
+ });
604
630
  });
605
631
 
606
632
  describe('transform property emission', () => {
@@ -209,6 +209,17 @@ export interface SHACLPropertyShape {
209
209
  * Applied to resolved property values in the Rust model query engine.
210
210
  * Only used for properties with resolveLanguage set. */
211
211
  transform?: NodeExpression;
212
+
213
+ /** AD4M-specific: Natural-language hint that steers the generic LLM
214
+ * extractor when producing typed instances from a transcript. Emitted
215
+ * as an `ad4m://interpretation_hint` link on the property shape node and
216
+ * surfaced on `ShapeProperty.interpretation_hint` by the Rust model query. */
217
+ interpretationHint?: string;
218
+
219
+ /** AD4M-specific: marks this property as the class's identity (dedup key)
220
+ * for the generic LLM interpreter. Emitted as an `ad4m://identity` link
221
+ * (`literal:string:true`) and read back on `ShapeProperty.identity`. */
222
+ identity?: boolean;
212
223
  }
213
224
 
214
225
  /**
@@ -234,6 +245,12 @@ export class SHACLShape {
234
245
  /** Parent shape URIs for model inheritance (sh:node references) */
235
246
  parentShapes: string[];
236
247
 
248
+ /** AD4M-specific: Natural-language hint that steers the generic LLM
249
+ * extractor when producing instances of this class. Emitted as an
250
+ * `ad4m://interpretation_hint` link on the shape node itself and surfaced
251
+ * on `ModelShape.interpretation_hint` by the Rust model query. */
252
+ interpretationHint?: string;
253
+
237
254
  /**
238
255
  * Create a new SHACL Shape
239
256
  * @param targetClassOrShapeUri - If one argument: the target class (shape URI auto-derived as {class}Shape)
@@ -410,7 +427,17 @@ export class SHACLShape {
410
427
  target: `literal:string:${JSON.stringify(this.destructor_actions)}`
411
428
  });
412
429
  }
413
-
430
+
431
+ // Class-level interpretation hint — read by the Rust model query as
432
+ // `ModelShape.interpretation_hint` and fed to the generic LLM extractor.
433
+ if (this.interpretationHint) {
434
+ links.push({
435
+ source: this.nodeShapeUri,
436
+ predicate: "ad4m://interpretation_hint",
437
+ target: `literal:string:${this.interpretationHint}`
438
+ });
439
+ }
440
+
414
441
  // Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
415
442
  for (let i = 0; i < this.properties.length; i++) {
416
443
  const prop = this.properties[i];
@@ -636,6 +663,22 @@ export class SHACLShape {
636
663
  target: `literal:string:${JSON.stringify(prop.transform)}`
637
664
  });
638
665
  }
666
+
667
+ if (prop.interpretationHint) {
668
+ links.push({
669
+ source: propShapeId,
670
+ predicate: "ad4m://interpretation_hint",
671
+ target: `literal:string:${prop.interpretationHint}`
672
+ });
673
+ }
674
+
675
+ if (prop.identity) {
676
+ links.push({
677
+ source: propShapeId,
678
+ predicate: "ad4m://identity",
679
+ target: `literal:string:true`
680
+ });
681
+ }
639
682
  }
640
683
 
641
684
  return links;
@@ -678,8 +721,18 @@ export class SHACLShape {
678
721
  }
679
722
  }
680
723
 
724
+ // Class-level interpretation hint (mirror of the emit in toLinks())
725
+ const classHintLink = links.find(l =>
726
+ l.source === shapeUri && l.predicate === "ad4m://interpretation_hint"
727
+ );
728
+ if (classHintLink) {
729
+ shape.interpretationHint = classHintLink.target.replace(
730
+ /^literal:\/\/string:|^literal:string:/, ''
731
+ );
732
+ }
733
+
681
734
  // Find all property shapes
682
- const propShapeLinks = links.filter(l =>
735
+ const propShapeLinks = links.filter(l =>
683
736
  l.source === shapeUri && l.predicate === "sh://property"
684
737
  );
685
738
 
@@ -930,6 +983,23 @@ export class SHACLShape {
930
983
  prop.filter = val === 'true';
931
984
  }
932
985
 
986
+ const interpretationHintLink = links.find(l =>
987
+ l.source === propShapeId && l.predicate === "ad4m://interpretation_hint"
988
+ );
989
+ if (interpretationHintLink) {
990
+ prop.interpretationHint = interpretationHintLink.target.replace(
991
+ /^literal:\/\/string:|^literal:string:/, ''
992
+ );
993
+ }
994
+
995
+ const identityLink = links.find(l =>
996
+ l.source === propShapeId && l.predicate === "ad4m://identity"
997
+ );
998
+ if (identityLink) {
999
+ prop.identity =
1000
+ identityLink.target.replace(/^literal:\/\/string:|^literal:string:/, '') === 'true';
1001
+ }
1002
+
933
1003
  const transformLink = links.find(l =>
934
1004
  l.source === propShapeId && l.predicate === "ad4m://transform"
935
1005
  );
@@ -969,6 +1039,7 @@ export class SHACLShape {
969
1039
  node_shape_uri: this.nodeShapeUri,
970
1040
  target_class: this.targetClass,
971
1041
  parent_shapes: this.parentShapes.length > 0 ? this.parentShapes : undefined,
1042
+ interpretation_hint: this.interpretationHint,
972
1043
  properties: this.properties.map(p => ({
973
1044
  path: p.path,
974
1045
  name: p.name,
@@ -996,6 +1067,8 @@ export class SHACLShape {
996
1067
  where_predicates: p.wherePredicates,
997
1068
  filter: p.filter,
998
1069
  transform: p.transform,
1070
+ interpretation_hint: p.interpretationHint,
1071
+ identity: p.identity,
999
1072
  })),
1000
1073
  constructor_actions: this.constructor_actions,
1001
1074
  destructor_actions: this.destructor_actions,
@@ -1046,9 +1119,11 @@ export class SHACLShape {
1046
1119
  wherePredicates: p.where_predicates,
1047
1120
  filter: p.filter,
1048
1121
  transform: p.transform,
1122
+ interpretationHint: p.interpretation_hint,
1123
+ identity: p.identity,
1049
1124
  });
1050
1125
  }
1051
-
1126
+
1052
1127
  if (json.constructor_actions) {
1053
1128
  shape.constructor_actions = json.constructor_actions;
1054
1129
  }
@@ -1060,7 +1135,10 @@ export class SHACLShape {
1060
1135
  shape.addParentShape(ps);
1061
1136
  }
1062
1137
  }
1063
-
1138
+ if (json.interpretation_hint) {
1139
+ shape.interpretationHint = json.interpretation_hint;
1140
+ }
1141
+
1064
1142
  return shape;
1065
1143
  }
1066
1144
  }