mdld-parse 0.9.2 → 0.9.3

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 (60) hide show
  1. package/dist/.nojekyll +0 -0
  2. package/dist/CNAME +1 -0
  3. package/dist/README.md +425 -0
  4. package/dist/docs/API.md +397 -0
  5. package/dist/docs/Architecture.md +190 -0
  6. package/dist/docs/Guide.md +322 -0
  7. package/dist/docs/LLM-MDLD-Inducer.md +550 -0
  8. package/dist/docs/Parser.md +654 -0
  9. package/dist/docs/Performance.md +238 -0
  10. package/dist/docs/Spec-render.md +1439 -0
  11. package/dist/docs/Subject.md +180 -0
  12. package/dist/docs/Syntax.md +463 -0
  13. package/dist/docs/TodoList.md +215 -0
  14. package/dist/docs/Use-Cases.md +354 -0
  15. package/dist/docs/index.html +108 -0
  16. package/dist/docs/index.md +56 -0
  17. package/dist/docs/origin.md +459 -0
  18. package/dist/docs/polarity.md +586 -0
  19. package/dist/docs/primary-subject.md +199 -0
  20. package/dist/docs/statements.md +226 -0
  21. package/dist/docs/tokenization-performance-report.md +164 -0
  22. package/dist/examples/Cookbook.md +32 -0
  23. package/dist/examples/Status-SHACL.md +33 -0
  24. package/dist/examples/demo/index.md +35 -0
  25. package/dist/examples/demo/journal.md +18 -0
  26. package/dist/examples/demo/minimal.md +11 -0
  27. package/dist/examples/demo/project.md +15 -0
  28. package/dist/examples/demo/recipe.md +31 -0
  29. package/dist/examples/demo/research.md +46 -0
  30. package/dist/examples/demo/space-mission.md +48 -0
  31. package/dist/examples/dogfood.md +288 -0
  32. package/dist/examples/few-shot.md +309 -0
  33. package/dist/examples/graph/rdf-graph.html +473 -0
  34. package/dist/examples/graph/rdf_force_graph_web_component.html +506 -0
  35. package/dist/examples/index.md +45 -0
  36. package/dist/examples/llm-time-workflow.md +173 -0
  37. package/dist/examples/prov-o.md +2367 -0
  38. package/dist/examples/rdf.md +827 -0
  39. package/dist/examples/shacl.md +3399 -0
  40. package/dist/examples/statements.md +43 -0
  41. package/dist/examples/workflow.md +150 -0
  42. package/dist/index.html +2827 -0
  43. package/dist/index.js +1548 -0
  44. package/dist/logo.svg +7 -0
  45. package/dist/spec/Spec-compact.md +363 -0
  46. package/dist/spec/Spec-ultra.md +221 -0
  47. package/dist/spec/Spec.md +1068 -0
  48. package/dist/spec/index.md +46 -0
  49. package/package.json +7 -8
  50. package/src/constants.js +0 -31
  51. package/src/generate.js +0 -245
  52. package/src/highlight.js +0 -362
  53. package/src/index.js +0 -13
  54. package/src/locate.js +0 -23
  55. package/src/merge.js +0 -157
  56. package/src/parse.js +0 -711
  57. package/src/render.js +0 -576
  58. package/src/shared.js +0 -577
  59. package/src/tokenizers.js +0 -594
  60. package/src/utils.js +0 -430
@@ -0,0 +1,506 @@
1
+ <style>
2
+ rdf-graph {
3
+ display: block;
4
+ width: 100%;
5
+ font-family: var(--font-mono, monospace)
6
+ }
7
+
8
+ rdf-graph svg {
9
+ width: 100%;
10
+ height: 100%;
11
+ cursor: default
12
+ }
13
+
14
+ .rdf-wrap {
15
+ position: relative;
16
+ border: 0.5px solid var(--color-border-tertiary);
17
+ border-radius: var(--border-radius-lg, 12px);
18
+ overflow: hidden;
19
+ background: var(--color-background-primary)
20
+ }
21
+
22
+ .rdf-hud {
23
+ position: absolute;
24
+ top: 8px;
25
+ right: 8px;
26
+ display: flex;
27
+ gap: 6px;
28
+ align-items: center
29
+ }
30
+
31
+ .rdf-hud span {
32
+ font-size: 11px;
33
+ color: var(--color-text-secondary);
34
+ background: var(--color-background-secondary);
35
+ padding: 2px 7px;
36
+ border-radius: 20px;
37
+ border: 0.5px solid var(--color-border-tertiary)
38
+ }
39
+
40
+ .rdf-energy {
41
+ width: 48px;
42
+ height: 6px;
43
+ border-radius: 3px;
44
+ border: 0.5px solid var(--color-border-tertiary);
45
+ overflow: hidden;
46
+ background: var(--color-background-secondary)
47
+ }
48
+
49
+ .rdf-ebar {
50
+ height: 100%;
51
+ border-radius: 3px;
52
+ transition: width .4s, background .4s
53
+ }
54
+ </style>
55
+
56
+ <script>
57
+ (() => {
58
+ const PALETTES = [
59
+ ['#534AB7', '#AFA9EC'], ['#0F6E56', '#5DCAA5'], ['#993C1D', '#F0997B'],
60
+ ['#993556', '#ED93B1'], ['#185FA5', '#85B7EB'], ['#3B6D11', '#97C459'],
61
+ ['#854F0B', '#EF9F27'], ['#A32D2D', '#F09595']
62
+ ];
63
+ const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
64
+ const SVG_NS = 'http://www.w3.org/2000/svg';
65
+
66
+ function curie(iri, ctx) {
67
+ if (!iri || typeof iri !== 'string') return iri;
68
+ if (ctx) {
69
+ for (const [pfx, ns] of Object.entries(ctx)) {
70
+ if (iri.startsWith(ns)) return pfx + ':' + iri.slice(ns.length);
71
+ }
72
+ }
73
+ const m = iri.match(/[#\/:]([^#\/:]+)$/);
74
+ return m ? m[1] : iri;
75
+ }
76
+
77
+ function hashStr(s) { let h = 5381; for (let i = 0; i < s.length; i++)h = (h * 33 ^ s.charCodeAt(i)) >>> 0; return h; }
78
+
79
+ class RdfGraph extends HTMLElement {
80
+ static get observedAttributes() { return ['height', 'charge', 'link-dist']; }
81
+ constructor() {
82
+ super();
83
+ this._quads = []; this._ctx = {}; this._nodes = []; this._links = [];
84
+ this._sim = null; this._raf = null; this._alpha = 0; this._sleeping = false;
85
+ this._drag = null;
86
+ }
87
+ connectedCallback() { this._build(); }
88
+ attributeChangedCallback() { if (this._svg) this._restart(); }
89
+
90
+ set quads(q) { this._quads = q || []; this._build(); }
91
+ set context(c) { this._ctx = c || {}; this._build(); }
92
+
93
+ _build() {
94
+ // --- parse quads ---
95
+ const nodeMap = new Map();
96
+ const typeMap = new Map();
97
+ const literalSize = new Map();
98
+ const links = [];
99
+
100
+ for (const q of this._quads) {
101
+ if (!q || q.termType !== 'Quad') continue;
102
+ const s = q.subject.value, p = q.predicate.value, o = q.object;
103
+ if (!nodeMap.has(s)) nodeMap.set(s, { id: s, size: 10, r: 10 });
104
+ if (p === RDF_TYPE && o.termType === 'NamedNode') {
105
+ typeMap.set(s, o.value);
106
+ if (!nodeMap.has(o.value)) nodeMap.set(o.value, { id: o.value, size: 8, r: 8 });
107
+ links.push({ source: s, target: o.value, label: curie(p, this._ctx) });
108
+ } else if (o.termType === 'NamedNode') {
109
+ if (!nodeMap.has(o.value)) nodeMap.set(o.value, { id: o.value, size: 8, r: 8 });
110
+ links.push({ source: s, target: o.value, label: curie(p, this._ctx) });
111
+ } else if (o.termType === 'Literal') {
112
+ const cur = literalSize.get(s) || 0;
113
+ literalSize.set(s, cur + 1);
114
+ }
115
+ }
116
+ for (const [id, cnt] of literalSize) {
117
+ const n = nodeMap.get(id);
118
+ if (n) n.size = Math.min(10 + cnt * 3, 26);
119
+ }
120
+
121
+ // assign colors by type
122
+ const typeColors = new Map();
123
+ let ci = 0;
124
+ for (const [, t] of typeMap) {
125
+ if (!typeColors.has(t)) typeColors.set(t, PALETTES[ci++ % PALETTES.length]);
126
+ }
127
+ for (const [id, n] of nodeMap) {
128
+ const t = typeMap.get(id);
129
+ n.color = t ? typeColors.get(t) : PALETTES[7];
130
+ n.r = n.size;
131
+ }
132
+
133
+ this._nodes = [...nodeMap.values()];
134
+ this._links = links;
135
+ this._typeColors = typeColors;
136
+ this._renderSvg();
137
+ this._initSim();
138
+ }
139
+
140
+ _renderSvg() {
141
+ this.innerHTML = '';
142
+ const h = parseInt(this.getAttribute('height') || '480');
143
+ const wrap = document.createElement('div');
144
+ wrap.className = 'rdf-wrap';
145
+ wrap.style.height = h + 'px';
146
+
147
+ const hud = document.createElement('div');
148
+ hud.className = 'rdf-hud';
149
+ this._statEl = document.createElement('span');
150
+ this._statEl.textContent = this._nodes.length + 'n · ' + this._links.length + 'e';
151
+ const energyWrap = document.createElement('div');
152
+ energyWrap.className = 'rdf-energy';
153
+ this._ebar = document.createElement('div');
154
+ this._ebar.className = 'rdf-ebar';
155
+ this._ebar.style.width = '100%';
156
+ energyWrap.appendChild(this._ebar);
157
+ hud.appendChild(this._statEl);
158
+ hud.appendChild(energyWrap);
159
+ wrap.appendChild(hud);
160
+
161
+ const svg = document.createElementNS(SVG_NS, 'svg');
162
+ svg.setAttribute('width', '100%');
163
+ svg.setAttribute('height', '100%');
164
+
165
+ const defs = document.createElementNS(SVG_NS, 'defs');
166
+ // arrowhead per color
167
+ const usedColors = new Set([...this._typeColors.values()].map(p => p[0]));
168
+ usedColors.add('#888');
169
+ for (const c of usedColors) {
170
+ const mk = document.createElementNS(SVG_NS, 'marker');
171
+ const mid = 'arr' + hashStr(c);
172
+ mk.setAttribute('id', mid);
173
+ mk.setAttribute('viewBox', '0 0 10 10');
174
+ mk.setAttribute('refX', '9'); mk.setAttribute('refY', '5');
175
+ mk.setAttribute('markerWidth', '5'); mk.setAttribute('markerHeight', '5');
176
+ mk.setAttribute('orient', 'auto-start-reverse');
177
+ const mp = document.createElementNS(SVG_NS, 'path');
178
+ mp.setAttribute('d', 'M2 1L8 5L2 9');
179
+ mp.setAttribute('fill', 'none'); mp.setAttribute('stroke', c);
180
+ mp.setAttribute('stroke-width', '1.5'); mp.setAttribute('stroke-linecap', 'round');
181
+ mk.appendChild(mp); defs.appendChild(mk);
182
+ }
183
+ svg.appendChild(defs);
184
+
185
+ this._gLinks = document.createElementNS(SVG_NS, 'g');
186
+ this._gLinkLabels = document.createElementNS(SVG_NS, 'g');
187
+ this._gNodes = document.createElementNS(SVG_NS, 'g');
188
+
189
+ // build link elements
190
+ this._linkEls = this._links.map(l => {
191
+ const line = document.createElementNS(SVG_NS, 'line');
192
+ const sc = this._nodeById(l.source);
193
+ const c = sc && sc.color ? sc.color[0] : '#888';
194
+ const mid = 'arr' + hashStr(c);
195
+ line.setAttribute('stroke', c);
196
+ line.setAttribute('stroke-width', '0.8');
197
+ line.setAttribute('stroke-opacity', '0.55');
198
+ line.setAttribute('marker-end', 'url(#' + mid + ')');
199
+ this._gLinks.appendChild(line);
200
+ if (l.label) {
201
+ const lt = document.createElementNS(SVG_NS, 'text');
202
+ lt.setAttribute('font-size', '8');
203
+ lt.setAttribute('fill', 'var(--color-text-tertiary,#999)');
204
+ lt.setAttribute('text-anchor', 'middle');
205
+ lt.setAttribute('dominant-baseline', 'central');
206
+ lt.setAttribute('pointer-events', 'none');
207
+ lt.setAttribute('opacity', '0.7');
208
+ lt.textContent = l.label;
209
+ this._gLinkLabels.appendChild(lt);
210
+ l._labelEl = lt;
211
+ }
212
+ l._el = line;
213
+ return line;
214
+ });
215
+
216
+ // build node elements
217
+ this._nodeElMap = new Map();
218
+ for (const n of this._nodes) {
219
+ const g = document.createElementNS(SVG_NS, 'g');
220
+ g.style.cursor = 'grab';
221
+ const c = document.createElementNS(SVG_NS, 'circle');
222
+ c.setAttribute('r', n.r);
223
+ c.setAttribute('fill', n.color ? n.color[0] : '#888');
224
+ c.setAttribute('stroke', n.color ? n.color[1] : '#aaa');
225
+ c.setAttribute('stroke-width', '1.2');
226
+ c.setAttribute('fill-opacity', '0.85');
227
+ const t = document.createElementNS(SVG_NS, 'text');
228
+ t.setAttribute('font-size', '8');
229
+ t.setAttribute('fill', 'var(--color-text-primary)');
230
+ t.setAttribute('text-anchor', 'middle');
231
+ t.setAttribute('dominant-baseline', 'central');
232
+ t.setAttribute('dy', n.r + 10);
233
+ t.setAttribute('pointer-events', 'none');
234
+ t.setAttribute('opacity', '0.75');
235
+ t.textContent = curie(n.id, this._ctx);
236
+ g.appendChild(c); g.appendChild(t);
237
+ this._gNodes.appendChild(g);
238
+ this._nodeElMap.set(n.id, g);
239
+ n._el = g; n._c = c;
240
+ // drag events
241
+ g.addEventListener('pointerdown', e => this._dragStart(e, n));
242
+ }
243
+
244
+ svg.appendChild(this._gLinks);
245
+ svg.appendChild(this._gLinkLabels);
246
+ svg.appendChild(this._gNodes);
247
+ svg.addEventListener('pointermove', e => this._dragMove(e));
248
+ svg.addEventListener('pointerup', e => this._dragEnd(e));
249
+ svg.addEventListener('pointerleave', e => this._dragEnd(e));
250
+ wrap.appendChild(svg);
251
+ this.appendChild(wrap);
252
+ this._svg = svg; this._wrap = wrap;
253
+ }
254
+
255
+ _nodeById(id) { return this._nodes.find(n => n.id === id); }
256
+
257
+ _initSim() {
258
+ const W = this._wrap.clientWidth || 600;
259
+ const H = this._wrap.clientHeight || 480;
260
+ for (const n of this._nodes) {
261
+ if (n.x == null) { n.x = W / 2 + (Math.random() - .5) * 200; n.y = H / 2 + (Math.random() - .5) * 200; }
262
+ n.vx = n.vx || 0; n.vy = n.vy || 0;
263
+ // Add mass proportional to node size (larger nodes = more mass)
264
+ n.mass = Math.max(1, n.size / 8);
265
+ }
266
+ this._W = W; this._H = H;
267
+ this._alpha = 1; this._sleeping = false;
268
+ this._wake();
269
+ }
270
+
271
+ _restart() { this._alpha = Math.max(this._alpha, 0.8); this._sleeping = false; this._wake(); }
272
+
273
+ _wake() {
274
+ if (this._raf) return;
275
+ this._raf = requestAnimationFrame(() => { this._raf = null; this._tick(); });
276
+ }
277
+
278
+ _tick() {
279
+ if (this._sleeping) { this._raf = null; return; }
280
+ const charge = parseFloat(this.getAttribute('charge') || -120);
281
+ const ld = parseFloat(this.getAttribute('link-dist') || 80);
282
+ const nodes = this._nodes, links = this._links;
283
+ const W = this._W, H = this._H;
284
+ const alpha = this._alpha, decay = 0.985; // Slower decay for more stable simulation
285
+
286
+ // Reset forces
287
+ for (const n of nodes) {
288
+ n.fx = 0;
289
+ n.fy = 0;
290
+ }
291
+
292
+ // repulsion O(n²) — small graphs only
293
+ for (let i = 0; i < nodes.length; i++) {
294
+ for (let j = i + 1; j < nodes.length; j++) {
295
+ const a = nodes[i], b = nodes[j];
296
+ let dx = b.x - a.x, dy = b.y - a.y;
297
+ const d2 = dx * dx + dy * dy || 1;
298
+ const f = charge * alpha / d2;
299
+ const d = Math.sqrt(d2) || 1;
300
+ dx /= d; dy /= d;
301
+ // Apply forces based on mass (F = ma, so a = F/m)
302
+ a.fx -= dx * f / a.mass;
303
+ a.fy -= dy * f / a.mass;
304
+ b.fx += dx * f / b.mass;
305
+ b.fy += dy * f / b.mass;
306
+ }
307
+ }
308
+ // link attraction
309
+ for (const l of links) {
310
+ const s = typeof l.source === 'object' ? l.source : this._nodeById(l.source);
311
+ const t = typeof l.target === 'object' ? l.target : this._nodeById(l.target);
312
+ if (!s || !t) continue;
313
+ l.source = s; l.target = t;
314
+ const dx = t.x - s.x, dy = t.y - s.y;
315
+ const d = Math.sqrt(dx * dx + dy * dy) || 1;
316
+ const f = (d - ld) * 0.02 * alpha; // Reduced spring strength
317
+ const nx = dx / d, ny = dy / d;
318
+ s.fx += nx * f / s.mass;
319
+ s.fy += ny * f / s.mass;
320
+ t.fx -= nx * f / t.mass;
321
+ t.fy -= ny * f / t.mass;
322
+ }
323
+ // gentler centering
324
+ let cx = 0, cy = 0;
325
+ for (const n of nodes) { cx += n.x; cy += n.y; }
326
+ cx /= nodes.length || 1; cy /= nodes.length || 1;
327
+ const gcx = W / 2 - cx, gcy = H / 2 - cy;
328
+ for (const n of nodes) {
329
+ n.fx += (gcx) * 0.008 * alpha; // Reduced centering force
330
+ n.fy += (gcy) * 0.008 * alpha;
331
+ }
332
+ // integrate + bounds
333
+ let ke = 0;
334
+ for (const n of nodes) {
335
+ if (n._pinned) { n.vx = 0; n.vy = 0; n.fx = 0; n.fy = 0; continue; }
336
+ // Apply forces to velocity with better damping
337
+ n.vx = (n.vx + n.fx) * 0.85; // Increased damping
338
+ n.vy = (n.vy + n.fy) * 0.85;
339
+
340
+ // Limit maximum velocity to prevent jitter
341
+ const maxV = 8;
342
+ const v = Math.sqrt(n.vx * n.vx + n.vy * n.vy);
343
+ if (v > maxV) {
344
+ n.vx = (n.vx / v) * maxV;
345
+ n.vy = (n.vy / v) * maxV;
346
+ }
347
+
348
+ n.x += n.vx; n.y += n.vy;
349
+ n.x = Math.max(n.r + 5, Math.min(W - n.r - 5, n.x));
350
+ n.y = Math.max(n.r + 5, Math.min(H - n.r - 5, n.y));
351
+ ke += n.vx * n.vx + n.vy * n.vy;
352
+ }
353
+ this._alpha *= decay;
354
+ const energy = Math.min(1, Math.sqrt(ke / Math.max(nodes.length, 1)) / 3); // Adjusted energy calculation
355
+
356
+ // HUD
357
+ const pct = Math.round(energy * 100);
358
+ const col = energy > 0.3 ? '#1D9E75' : energy > 0.08 ? '#BA7517' : '#888780';
359
+ this._ebar.style.width = pct + '%';
360
+ this._ebar.style.background = col;
361
+
362
+ this._draw();
363
+
364
+ if (this._alpha < 0.002 && !this._drag) {
365
+ this._sleeping = true;
366
+ this._ebar.style.width = '0%';
367
+ this._raf = null; return;
368
+ }
369
+ this._raf = requestAnimationFrame(() => { this._raf = null; this._tick(); });
370
+ }
371
+
372
+ _draw() {
373
+ for (const l of this._links) {
374
+ const s = l.source, t = l.target;
375
+ if (!s || !t || typeof s !== 'object') continue;
376
+ const dx = t.x - s.x, dy = t.y - s.y;
377
+ const d = Math.sqrt(dx * dx + dy * dy) || 1;
378
+ const nx = dx / d, ny = dy / d;
379
+ const x1 = s.x + nx * (s.r + 1);
380
+ const y1 = s.y + ny * (s.r + 1);
381
+ const x2 = t.x - nx * (t.r + 6);
382
+ const y2 = t.y - ny * (t.r + 6);
383
+ const el = l._el;
384
+ el.setAttribute('x1', x1); el.setAttribute('y1', y1);
385
+ el.setAttribute('x2', x2); el.setAttribute('y2', y2);
386
+ if (l._labelEl) {
387
+ l._labelEl.setAttribute('x', (x1 + x2) / 2);
388
+ l._labelEl.setAttribute('y', (y1 + y2) / 2 - 4);
389
+ }
390
+ }
391
+ for (const n of this._nodes) {
392
+ if (!n._el) continue;
393
+ n._el.setAttribute('transform', 'translate(' + n.x + ',' + n.y + ')');
394
+ }
395
+ }
396
+
397
+ _dragStart(e, n) {
398
+ e.preventDefault();
399
+ this._drag = { node: n, id: e.pointerId };
400
+ this._svg.setPointerCapture(e.pointerId);
401
+ n._pinned = true;
402
+ n._el.style.cursor = 'grabbing';
403
+ // REVIVE sim on drag
404
+ this._sleeping = false;
405
+ this._alpha = Math.max(this._alpha, 0.5);
406
+ this._wake();
407
+ }
408
+ _dragMove(e) {
409
+ if (!this._drag || e.pointerId !== this._drag.id) return;
410
+ const r = this._svg.getBoundingClientRect();
411
+ const sx = this._svg.viewBox?.baseVal?.width || this._W;
412
+ const sy = this._svg.viewBox?.baseVal?.height || this._H;
413
+ const scaleX = (sx || this._W) / r.width;
414
+ const scaleY = (sy || this._H) / r.height;
415
+ const n = this._drag.node;
416
+ n.x = (e.clientX - r.left) * scaleX;
417
+ n.y = (e.clientY - r.top) * scaleY;
418
+ n.vx = 0; n.vy = 0;
419
+ if (this._sleeping) { this._sleeping = false; this._alpha = 0.3; this._wake(); }
420
+ }
421
+ _dragEnd(e) {
422
+ if (!this._drag) return;
423
+ this._drag.node._pinned = false;
424
+ this._drag.node._el.style.cursor = 'grab';
425
+ // smaller thermal kick on release for more stability
426
+ this._drag.node.vx = (Math.random() - .5) * 0.5;
427
+ this._drag.node.vy = (Math.random() - .5) * 0.5;
428
+ this._alpha = Math.max(this._alpha, 0.25);
429
+ this._drag = null;
430
+ this._wake();
431
+ }
432
+ }
433
+
434
+ customElements.define('rdf-graph', RdfGraph);
435
+ })();
436
+ </script>
437
+
438
+ <!-- DEMO -->
439
+ <div style="padding:12px 0 0">
440
+ <rdf-graph id="g1" height="420" charge="-140" link-dist="190"></rdf-graph>
441
+ </div>
442
+ <div style="display:flex;gap:8px;margin:10px 0 4px;flex-wrap:wrap">
443
+ <button onclick="loadDemo()" style="font-size:12px">Load demo quads</button>
444
+ <button onclick="wakeGraph()" style="font-size:12px">↻ Revive</button>
445
+ <button onclick="addNode()" style="font-size:12px">+ Random node</button>
446
+ <span style="font-size:11px;color:var(--color-text-secondary);align-self:center">drag nodes · click Revive if
447
+ dormant</span>
448
+ </div>
449
+ <script>
450
+ const demoCtx = { 'prov': 'http://www.w3.org/ns/prov#', 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'hr': 'tag:hr@example.com,2026:' };
451
+
452
+ function mkQ(s, p, o, oType = 'NamedNode') {
453
+ return { termType: 'Quad', subject: { termType: 'NamedNode', value: s }, predicate: { termType: 'NamedNode', value: p }, object: { termType: oType === 'Literal' ? 'Literal' : 'NamedNode', value: o } };
454
+ }
455
+ const BASE = 'tag:me@example.com,2026:';
456
+ const PROV = 'http://www.w3.org/ns/prov#';
457
+ const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
458
+ const RDFS = 'http://www.w3.org/2000/01/rdf-schema#';
459
+
460
+ const demoQuads = [
461
+ mkQ(BASE + 'day-2024-07-18', RDF + 'type', PROV + 'Activity'),
462
+ mkQ(BASE + 'day-2024-07-18', RDFS + 'label', '2024-07-18 — A good day', 'Literal'),
463
+ mkQ(BASE + 'day-2024-07-18', RDFS + 'comment', 'Productive day.', 'Literal'),
464
+ mkQ(BASE + 'day-2024-07-18', PROV + 'wasAssociatedWith', BASE + 'agent-alice'),
465
+ mkQ(BASE + 'agent-alice', RDF + 'type', PROV + 'Agent'),
466
+ mkQ(BASE + 'agent-alice', RDFS + 'label', 'Alice', 'Literal'),
467
+ mkQ(BASE + 'run-2024-07-18', RDF + 'type', PROV + 'Activity'),
468
+ mkQ(BASE + 'run-2024-07-18', PROV + 'wasStartedBy', BASE + 'agent-alice'),
469
+ mkQ(BASE + 'run-2024-07-18', PROV + 'used', BASE + 'dataset-01'),
470
+ mkQ(BASE + 'dataset-01', RDF + 'type', PROV + 'Entity'),
471
+ mkQ(BASE + 'dataset-01', RDFS + 'label', 'Dataset 01', 'Literal'),
472
+ mkQ(BASE + 'dataset-01', RDFS + 'label', 'Alt label', 'Literal'),
473
+ mkQ(BASE + 'result-01', RDF + 'type', PROV + 'Entity'),
474
+ mkQ(BASE + 'result-01', PROV + 'wasDerivedFrom', BASE + 'dataset-01'),
475
+ mkQ(BASE + 'run-2024-07-18', PROV + 'generated', BASE + 'result-01'),
476
+ mkQ(BASE + 'plan-01', RDF + 'type', PROV + 'Plan'),
477
+ mkQ(BASE + 'run-2024-07-18', PROV + 'hadPlan', BASE + 'plan-01'),
478
+ mkQ(BASE + 'agent-bob', RDF + 'type', PROV + 'Agent'),
479
+ mkQ(BASE + 'agent-bob', PROV + 'actedOnBehalfOf', BASE + 'agent-alice'),
480
+ mkQ(BASE + 'day-2024-07-18', PROV + 'wasInformedBy', BASE + 'run-2024-07-18'),
481
+ ];
482
+
483
+ function loadDemo() {
484
+ const g = document.getElementById('g1');
485
+ g.context = demoCtx;
486
+ g.quads = demoQuads;
487
+ }
488
+ function wakeGraph() {
489
+ const g = document.getElementById('g1');
490
+ g._sleeping = false;
491
+ g._alpha = 0.8;
492
+ for (const n of g._nodes) { n.vx = (Math.random() - .5) * 1; n.vy = (Math.random() - .5) * 1; }
493
+ g._wake();
494
+ }
495
+ function addNode() {
496
+ const g = document.getElementById('g1');
497
+ if (!g._quads.length) { loadDemo(); return; }
498
+ const id = BASE + 'node-' + Math.floor(Math.random() * 999);
499
+ const targets = [BASE + 'agent-alice', BASE + 'dataset-01', BASE + 'result-01'];
500
+ const t = targets[Math.floor(Math.random() * targets.length)];
501
+ const extra = [mkQ(id, RDF + 'type', PROV + 'Entity'), mkQ(id, PROV + 'wasDerivedFrom', t), mkQ(id, RDFS + 'label', 'new', 'Literal')];
502
+ g.context = demoCtx;
503
+ g.quads = [...g._quads, ...extra];
504
+ }
505
+ loadDemo();
506
+ </script>
@@ -0,0 +1,45 @@
1
+ # MD-LD Examples
2
+
3
+ A collection of example documents demonstrating MD-LD capabilities and patterns.
4
+
5
+ ## Examples by Category
6
+
7
+ ### � Quick Start Examples
8
+ - **[minimal.md](demo/minimal.md)** - Minimal document with subject and author
9
+
10
+ ### � Cooking & Recipes
11
+ - **[Cookbook.md](./Cookbook.md)** - Complete recipe with ingredients, equipment, and nutritional information using explicit list annotations
12
+ - **[dogfood.md](./dogfood.md)** - Comprehensive example showing complex relationships, nested structures, and various MD-LD features
13
+
14
+ ### 🔧 Validation & SHACL
15
+ - **[Status-SHACL.md](./Status-SHACL.md)** - SHACL validation patterns with self-validating constraint definitions
16
+
17
+ ### 🤖 LLM & AI Workflows
18
+ - **[few-shot.md](./few-shot.md)** - Few-shot learning examples and MD-LD grammar reference
19
+ - **[llm-time-workflow.md](./llm-time-workflow.md)** - Complete LLM workflow with provenance tracking using PROV-O
20
+ - **[workflow.md](./workflow.md)** - Research workflow demonstration with PROV-O activities and SHACL validation
21
+
22
+ ## Key Features Demonstrated
23
+
24
+ - ✅ **Explicit Annotations** - All semantic data comes from `{...}` blocks
25
+ - ✅ **Subject Chaining** - Using `{=IRI}` and `{+IRI}` for context
26
+ - ✅ **Prefix Folding** - Hierarchical namespace building
27
+ - ✅ **PROV-O Integration** - Complete provenance tracking
28
+ - ✅ **SHACL Validation** - Self-validating constraint definitions
29
+ - ✅ **Fragment Subjects** - Document structuring with `{=#fragment}`
30
+ - ✅ **Reverse Relations** - Using `!p` for inverse relationships
31
+ - ✅ **Datatypes & Languages** - `^^xsd:types` and `@lang` tags
32
+ - ✅ **Round-trip Safety** - Documents that serialize back to valid MD-LD
33
+
34
+ ## Use Cases Reference
35
+
36
+ - [Personal Knowledge Management](../docs/Use-Cases.md#personal-knowledge-management)
37
+ - [Developer Documentation](../docs/Use-Cases.md#developer-documentation)
38
+ - [Academic Research](../docs/Use-Cases.md#academic-research)
39
+ - [Content Management](../docs/Use-Cases.md#content-management)
40
+ - [Data Integration](../docs/Use-Cases.md#data-integration)
41
+ - [Business Processes](../docs/Use-Cases.md#workflow-automation)
42
+
43
+ ---
44
+
45
+ *Each example is a complete, working MD-LD document that can be parsed and round-tripped safely.*