@coasys/ad4m 0.12.0-dev-whisper-lang → 0.12.0-rc1-dev.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 (42) hide show
  1. package/lib/index.cjs +1746 -322
  2. package/lib/index.js +1745 -323
  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 +21 -7
  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 +23 -7
  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,205 @@
1
+ import { SHACLFlow } from './SHACLFlow';
2
+ describe('SHACLFlow', () => {
3
+ describe('basic construction', () => {
4
+ it('creates a flow with name and namespace', () => {
5
+ const flow = new SHACLFlow('TODO', 'todo://');
6
+ expect(flow.name).toBe('TODO');
7
+ expect(flow.namespace).toBe('todo://');
8
+ expect(flow.flowUri).toBe('todo://TODOFlow');
9
+ });
10
+ it('generates correct state URIs', () => {
11
+ const flow = new SHACLFlow('TODO', 'todo://');
12
+ expect(flow.stateUri('ready')).toBe('todo://TODO.ready');
13
+ expect(flow.stateUri('done')).toBe('todo://TODO.done');
14
+ });
15
+ it('generates correct transition URIs', () => {
16
+ const flow = new SHACLFlow('TODO', 'todo://');
17
+ expect(flow.transitionUri('ready', 'doing')).toBe('todo://TODO.readyTodoing');
18
+ });
19
+ });
20
+ describe('state management', () => {
21
+ it('adds and retrieves states', () => {
22
+ const flow = new SHACLFlow('TODO', 'todo://');
23
+ flow.addState({
24
+ name: 'ready',
25
+ value: 0,
26
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
27
+ });
28
+ flow.addState({
29
+ name: 'done',
30
+ value: 1,
31
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
32
+ });
33
+ expect(flow.states.length).toBe(2);
34
+ expect(flow.states[0].name).toBe('ready');
35
+ expect(flow.states[1].name).toBe('done');
36
+ });
37
+ });
38
+ describe('transition management', () => {
39
+ it('adds and retrieves transitions', () => {
40
+ const flow = new SHACLFlow('TODO', 'todo://');
41
+ flow.addTransition({
42
+ actionName: 'Complete',
43
+ fromState: 'ready',
44
+ toState: 'done',
45
+ actions: [
46
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' },
47
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
48
+ ]
49
+ });
50
+ expect(flow.transitions.length).toBe(1);
51
+ expect(flow.transitions[0].actionName).toBe('Complete');
52
+ expect(flow.transitions[0].actions.length).toBe(2);
53
+ });
54
+ });
55
+ describe('toLinks()', () => {
56
+ it('serializes flow to links', () => {
57
+ const flow = new SHACLFlow('TODO', 'todo://');
58
+ flow.flowable = 'any';
59
+ flow.startAction = [
60
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
61
+ ];
62
+ flow.addState({
63
+ name: 'ready',
64
+ value: 0,
65
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
66
+ });
67
+ flow.addTransition({
68
+ actionName: 'Start',
69
+ fromState: 'ready',
70
+ toState: 'doing',
71
+ actions: [{ action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' }]
72
+ });
73
+ const links = flow.toLinks();
74
+ // Check flow type link
75
+ const typeLink = links.find(l => l.predicate === 'rdf://type' && l.target === 'ad4m://Flow');
76
+ expect(typeLink).toBeDefined();
77
+ expect(typeLink.source).toBe('todo://TODOFlow');
78
+ // Check flowable link
79
+ const flowableLink = links.find(l => l.predicate === 'ad4m://flowable');
80
+ expect(flowableLink).toBeDefined();
81
+ expect(flowableLink.target).toBe('ad4m://any');
82
+ // Check start action link
83
+ const startActionLink = links.find(l => l.predicate === 'ad4m://startAction');
84
+ expect(startActionLink).toBeDefined();
85
+ expect(startActionLink.target).toContain('addLink');
86
+ // Check state link
87
+ const stateLink = links.find(l => l.predicate === 'ad4m://hasState');
88
+ expect(stateLink).toBeDefined();
89
+ expect(stateLink.target).toBe('todo://TODO.ready');
90
+ // Check transition link
91
+ const transitionLink = links.find(l => l.predicate === 'ad4m://hasTransition');
92
+ expect(transitionLink).toBeDefined();
93
+ });
94
+ });
95
+ describe('fromLinks()', () => {
96
+ it('reconstructs flow from links', () => {
97
+ const original = new SHACLFlow('TODO', 'todo://');
98
+ original.flowable = 'any';
99
+ original.startAction = [
100
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
101
+ ];
102
+ original.addState({
103
+ name: 'ready',
104
+ value: 0,
105
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
106
+ });
107
+ original.addState({
108
+ name: 'done',
109
+ value: 1,
110
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
111
+ });
112
+ original.addTransition({
113
+ actionName: 'Complete',
114
+ fromState: 'ready',
115
+ toState: 'done',
116
+ actions: [{ action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' }]
117
+ });
118
+ const links = original.toLinks();
119
+ const reconstructed = SHACLFlow.fromLinks(links, 'todo://TODOFlow');
120
+ expect(reconstructed.name).toBe('TODO');
121
+ expect(reconstructed.namespace).toBe('todo://');
122
+ expect(reconstructed.flowable).toBe('any');
123
+ expect(reconstructed.startAction.length).toBe(1);
124
+ expect(reconstructed.states.length).toBe(2);
125
+ expect(reconstructed.transitions.length).toBe(1);
126
+ expect(reconstructed.transitions[0].actionName).toBe('Complete');
127
+ });
128
+ });
129
+ describe('JSON serialization', () => {
130
+ it('converts to and from JSON', () => {
131
+ const original = new SHACLFlow('TODO', 'todo://');
132
+ original.addState({
133
+ name: 'ready',
134
+ value: 0,
135
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
136
+ });
137
+ original.addTransition({
138
+ actionName: 'Start',
139
+ fromState: 'ready',
140
+ toState: 'doing',
141
+ actions: []
142
+ });
143
+ const json = original.toJSON();
144
+ const reconstructed = SHACLFlow.fromJSON(json);
145
+ expect(reconstructed.name).toBe('TODO');
146
+ expect(reconstructed.states.length).toBe(1);
147
+ expect(reconstructed.transitions.length).toBe(1);
148
+ });
149
+ });
150
+ describe('full TODO example', () => {
151
+ it('creates complete TODO flow matching Prolog example', () => {
152
+ const flow = new SHACLFlow('TODO', 'todo://');
153
+ flow.flowable = 'any';
154
+ // Start action - renders expression as TODO in 'ready' state
155
+ flow.startAction = [
156
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
157
+ ];
158
+ // Three states
159
+ flow.addState({
160
+ name: 'ready',
161
+ value: 0,
162
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
163
+ });
164
+ flow.addState({
165
+ name: 'doing',
166
+ value: 0.5,
167
+ stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
168
+ });
169
+ flow.addState({
170
+ name: 'done',
171
+ value: 1,
172
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
173
+ });
174
+ // Transitions
175
+ flow.addTransition({
176
+ actionName: 'Start',
177
+ fromState: 'ready',
178
+ toState: 'doing',
179
+ actions: [
180
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
181
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
182
+ ]
183
+ });
184
+ flow.addTransition({
185
+ actionName: 'Finish',
186
+ fromState: 'doing',
187
+ toState: 'done',
188
+ actions: [
189
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' },
190
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' }
191
+ ]
192
+ });
193
+ // Verify structure
194
+ expect(flow.states.length).toBe(3);
195
+ expect(flow.transitions.length).toBe(2);
196
+ // Verify links generation
197
+ const links = flow.toLinks();
198
+ expect(links.length).toBeGreaterThan(15); // Flow + 3 states + 2 transitions = many links
199
+ // Verify round-trip
200
+ const reconstructed = SHACLFlow.fromLinks(links, flow.flowUri);
201
+ expect(reconstructed.states.length).toBe(3);
202
+ expect(reconstructed.transitions.length).toBe(2);
203
+ });
204
+ });
205
+ });
@@ -0,0 +1,108 @@
1
+ import { Link } from "../links/Links";
2
+ /**
3
+ * AD4M Action - represents a link operation
4
+ */
5
+ export interface AD4MAction {
6
+ action: string;
7
+ source: string;
8
+ predicate: string;
9
+ target: string;
10
+ local?: boolean;
11
+ }
12
+ /**
13
+ * SHACL Property Shape
14
+ * Represents constraints on a single property path
15
+ */
16
+ export interface SHACLPropertyShape {
17
+ /** Property name (e.g., "name", "ingredients") - used for generating named URIs */
18
+ name?: string;
19
+ /** The property path (predicate URI) */
20
+ path: string;
21
+ /** Expected datatype (e.g., xsd:string, xsd:integer) */
22
+ datatype?: string;
23
+ /** Node kind constraint (IRI, Literal, BlankNode) */
24
+ nodeKind?: 'IRI' | 'Literal' | 'BlankNode';
25
+ /** Minimum cardinality (required if >= 1) */
26
+ minCount?: number;
27
+ /** Maximum cardinality (single-valued if 1, omit for collections) */
28
+ maxCount?: number;
29
+ /** Regex pattern for string validation */
30
+ pattern?: string;
31
+ /** Minimum value (inclusive) for numeric properties */
32
+ minInclusive?: number;
33
+ /** Maximum value (inclusive) for numeric properties */
34
+ maxInclusive?: number;
35
+ /** Fixed value constraint (for Flag properties) */
36
+ hasValue?: string;
37
+ /** AD4M-specific: Local-only property */
38
+ local?: boolean;
39
+ /** AD4M-specific: Writable property */
40
+ writable?: boolean;
41
+ /** AD4M-specific: Language to resolve property values through */
42
+ resolveLanguage?: string;
43
+ /** AD4M-specific: Setter action for this property */
44
+ setter?: AD4MAction[];
45
+ /** AD4M-specific: Adder action for collection properties */
46
+ adder?: AD4MAction[];
47
+ /** AD4M-specific: Remover action for collection properties */
48
+ remover?: AD4MAction[];
49
+ }
50
+ /**
51
+ * SHACL Node Shape
52
+ * Defines constraints for instances of a class
53
+ */
54
+ export declare class SHACLShape {
55
+ /** URI of this shape (e.g., recipe:RecipeShape) */
56
+ nodeShapeUri: string;
57
+ /** Target class this shape applies to (e.g., recipe:Recipe) */
58
+ targetClass?: string;
59
+ /** Property constraints */
60
+ properties: SHACLPropertyShape[];
61
+ /** AD4M-specific: Constructor actions for creating instances */
62
+ constructor_actions?: AD4MAction[];
63
+ /** AD4M-specific: Destructor actions for removing instances */
64
+ destructor_actions?: AD4MAction[];
65
+ /**
66
+ * Create a new SHACL Shape
67
+ * @param targetClassOrShapeUri - If one argument: the target class (shape URI auto-derived as {class}Shape)
68
+ * If two arguments: first is shape URI, second is target class
69
+ * @param targetClass - Optional target class when first arg is shape URI
70
+ */
71
+ constructor(targetClassOrShapeUri: string, targetClass?: string);
72
+ /**
73
+ * Add a property constraint to this shape
74
+ */
75
+ addProperty(prop: SHACLPropertyShape): void;
76
+ /**
77
+ * Set constructor actions for this shape
78
+ */
79
+ setConstructorActions(actions: AD4MAction[]): void;
80
+ /**
81
+ * Set destructor actions for this shape
82
+ */
83
+ setDestructorActions(actions: AD4MAction[]): void;
84
+ /**
85
+ * Serialize shape to Turtle (RDF) format
86
+ */
87
+ toTurtle(): string;
88
+ /**
89
+ * Serialize shape to AD4M Links (RDF triples)
90
+ * Stores the shape as a graph of links in a Perspective
91
+ */
92
+ toLinks(): Link[];
93
+ /**
94
+ * Reconstruct shape from AD4M Links
95
+ */
96
+ static fromLinks(links: Link[], shapeUri: string): SHACLShape;
97
+ /**
98
+ * Convert the shape to a JSON-serializable object.
99
+ * Useful for passing to addSdna() as shaclJson parameter.
100
+ *
101
+ * @returns JSON-serializable object representing the shape
102
+ */
103
+ toJSON(): object;
104
+ /**
105
+ * Create a shape from a JSON object (inverse of toJSON)
106
+ */
107
+ static fromJSON(json: any): SHACLShape;
108
+ }