eyemind 0.5.27 → 0.5.28

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/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The eyemind Rule Language and Proof Format
5
- Version: eyemind 0.5.27
5
+ Version: eyemind 0.5.28
6
6
  ```
7
7
 
8
8
  This document specifies the syntax and meaning of eyemind programs and data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.5.27",
3
+ "version": "0.5.28",
4
4
  "description": "A dependency-free JavaScript rule language with forward and backward reasoning and checkable proofs.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -189,18 +189,22 @@ function srlData(document) {
189
189
  if (t.t === 'iri' && t.v === `${RDF}nil`) return { t: 'list', items: [] };
190
190
  if (t.t === 'triple') return { ...t, s: expand(t.s, ancestors), p: expand(t.p, ancestors), o: expand(t.o, ancestors) };
191
191
  if (t.t !== 'bnode' || !cells.has(t.v)) return t;
192
- const path = new Set(ancestors);
192
+ // Keep only the active path: copying all ancestors for each nested list
193
+ // makes a long list of encoded terms quadratic. Siblings may share cells.
194
+ const path = [];
193
195
  const items = [];
194
196
  while (t.t === 'bnode' && cells.has(t.v)) {
195
- if (path.has(t.v)) fail('cyclic collection');
196
- path.add(t.v);
197
+ if (ancestors.has(t.v)) fail('cyclic collection');
198
+ ancestors.add(t.v);
199
+ path.push(t.v);
197
200
  const cell = cells.get(t.v);
198
201
  if (cell.size !== 2) fail('an RDF collection needs first and rest');
199
202
  used.add(t.v);
200
- items.push(expand(cell.get(`${RDF}first`), path));
203
+ items.push(expand(cell.get(`${RDF}first`), ancestors));
201
204
  t = cell.get(`${RDF}rest`);
202
205
  }
203
206
  if (t.t !== 'iri' || t.v !== `${RDF}nil`) fail('an RDF collection must end in rdf:nil');
207
+ for (const id of path) ancestors.delete(id);
204
208
  return { t: 'list', items };
205
209
  };
206
210
  const out = triples.filter((t) => !(t.s.t === 'bnode' && cells.has(t.s.v) && [`${RDF}first`, `${RDF}rest`].includes(t.p.v)))
@@ -246,6 +250,21 @@ function compare(actual, expected) {
246
250
  for (const [key, value] of e) if (!same(a.get(key), value)) fail(`a displayed proof property differs from its record: ${key}`);
247
251
  }
248
252
 
253
+ // Read the graph reconstructed from records with N3's direct collections,
254
+ // avoiding SRL's expansion into first/rest cells and folding them back again.
255
+ // SRL folds every rdf:nil, including an explicit IRI, to ().
256
+ function expectedData(terms, format) {
257
+ const parsed = parseN3(writeN3(graph(terms, format), { strings: false }), { preserveNumericLiterals: true });
258
+ if (format === 'n3') return parsed;
259
+ const fold = (t) => {
260
+ if (t.t === 'iri' && t.v === `${RDF}nil`) return { t: 'list', items: [] };
261
+ if (t.t === 'list') return { ...t, items: t.items.map(fold) };
262
+ if (t.t === 'triple') return { ...t, s: fold(t.s), p: fold(t.p), o: fold(t.o) };
263
+ return t;
264
+ };
265
+ return { triples: parsed.triples.map((t) => ({ s: fold(t.s), p: fold(t.p), o: fold(t.o) })) };
266
+ }
267
+
249
268
  function readNative(document) {
250
269
  let parsed, format;
251
270
  try { parsed = parseN3(document, { preserveNumericLiterals: true }); format = 'n3'; }
@@ -271,7 +290,7 @@ function readNative(document) {
271
290
  if (id.t !== 'iri' || id.v !== `${ROOT}#record${i + 1}`) fail('proof records must be numbered in document order');
272
291
  return decode(property(id.v, `${TERM_NS}term`));
273
292
  });
274
- const expected = format === 'n3' ? parseN3(render(terms, format), { preserveNumericLiterals: true }) : srlData(render(terms, format));
293
+ const expected = expectedData(terms, format);
275
294
  compare(parsed.triples, expected.triples);
276
295
  return terms;
277
296
  }
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The release this checkout is; ./release keeps it in step with package.json.
2
- export const VERSION = '0.5.27';
2
+ export const VERSION = '0.5.28';