eyemind 0.5.4 → 0.5.6

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/README.md CHANGED
@@ -7,7 +7,7 @@ eyemind is a **JavaScript rule language** with forward and backward reasoning an
7
7
 
8
8
  [Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
9
9
 
10
- The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 99 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1353 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
10
+ The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 115 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1353 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
11
11
 
12
12
  ## Contents
13
13
 
@@ -191,30 +191,48 @@ eyemind --to trig rules.js data.trig # the conclusions as TriG
191
191
  | Triple term | `triple(S, P, O)`, which may nest |
192
192
  | Default graph, named graph | `'default_graph'`, `iri(Name)` |
193
193
 
194
- A reified triple `<< s p o >>` and an annotation `{| ... |}` become their reifier and its `rdf:reifies` triple, as RDF 1.2 defines. A Skolem term is written as a blank node, the same one for the same rule firing. The `rdf12-*` examples load Turtle or TriG data alongside eyemind rule scripts. They show triple terms, annotations, directional strings, typed numbers and named graphs. The W3C RDF test suites run in `npm test` from the mirror in `test/w3c/rdf-tests`: all 1055 tests of N-Triples, N-Quads, Turtle and TriG, in RDF 1.1 and 1.2, pass.
194
+ A reified triple `<< s p o >>` and an annotation `{| ... |}` become their reifier and its `rdf:reifies` triple, as RDF 1.2 defines. A Skolem term is written as a blank node, the same one for the same rule firing. The RDF examples load Turtle or TriG files from `examples/data/` alongside companion rules in `examples/`. They show triple terms, annotations, directional strings, typed numbers and named graphs. The W3C RDF test suites run in `npm test` from the mirror in `test/w3c/rdf-tests`: all 1055 tests of N-Triples, N-Quads, Turtle and TriG, in RDF 1.1 and 1.2, pass.
195
195
 
196
196
  ### Notation3
197
197
 
198
- A file ending in `.n3` is Notation3: eyemind compiles its facts and rules into a program, with the N3 built-ins it uses written as eyemind rules, and writes the conclusions back as N3. RDF data files join the N3 document as triples:
198
+ A file ending in `.n3` is Notation3: eyemind compiles its facts and rules into a program, with the N3 built-ins it uses written as eyemind rules, and writes the conclusions back as N3. RDF default-graph data joins the N3 document as triples:
199
199
 
200
200
  ```sh
201
- eyemind examples/n3-family.n3 # the derived triples as N3
202
- eyemind --program examples/n3-family.n3 > /tmp/family.js # the compiled program, to inspect
203
- eyemind -c examples/n3-family.n3 # a proof of it, checked
201
+ eyemind examples/family.n3 # the derived triples as N3
202
+ eyemind --program examples/family.n3 > /tmp/family.js # the compiled program, to inspect
203
+ eyemind -c examples/family.n3 # a proof of it, checked
204
204
  ```
205
205
 
206
206
  Triples are `rdf(Subject, Predicate, Object)`, with IRIs, blank nodes and literals written as in the RDF table above. N3 integers and decimals become eyemind numbers; float and double literals retain their RDF datatype, including numbers written with an exponent. Decimals use binary64 storage; `math:sum` adds their canonical decimal values before rounding its result. `=>` becomes `implies`, `<=` becomes `implied_by`, `{ ... } => false` becomes `contradiction`, and scoped negation and collection become `not` and `findall`, so an N3 run has a proof that eyemind checks like any other. Derived rules can trigger inference fuses too.
207
207
 
208
- Scoped calls can use formulas supplied by the document's stated lists, including RDF collections written with `rdf:first` and `rdf:rest`. These calls are specialized before reasoning so their dependencies remain available for stratification and proof checking; formulas constructed only during reasoning are not supported by this compilation.
208
+ N3 has no named-graph syntax. When RDF data joins an N3 run, eyemind represents
209
+ each named graph as a quoted formula through `graph:content`, where `graph:`
210
+ is `https://eyereasoner.github.io/eyemind/graph#`:
211
+
212
+ ```n3
213
+ @prefix : <https://example.org/> .
214
+ @prefix graph: <https://eyereasoner.github.io/eyemind/graph#> .
215
+
216
+ :family graph:content { :alice :parent :bob . :bob :parent :carol } .
217
+ ```
218
+
219
+ Default-graph triples remain ordinary assertions. Named-graph triples stay
220
+ inside their formulas; `?g graph:content ?data` and
221
+ `?data log:includes { ... }` inspect them. Contents with the same graph name
222
+ from several RDF inputs are combined, while blank nodes keep their source
223
+ scopes. Conclusions can attach further formulas to that name; the output
224
+ writes these as N3 formulas. See the [named graph example](https://eyereasoner.github.io/eyemind/examples/deck/trig-named-graph).
225
+
226
+ Scoped calls can use formulas supplied by the document's stated lists, including RDF collections written with `rdf:first` and `rdf:rest`, and the named-graph formulas loaded from RDF. These calls are specialized before reasoning so their dependencies remain available for stratification and proof checking; formulas constructed only during reasoning are not supported by this compilation.
209
227
 
210
228
  The documents `log:semantics`, `log:semanticsOrError` and `log:content` name are read before compiling. The command reads local files and HTTP(S) documents, with a ten-second fetch timeout and a 16 MiB response limit. The library uses the host callbacks `readFile(path)` and `readDocument(iri)`; without them it does not read external documents. Their contents become facts of the compiled program, which can be saved with `--program` for later proof checking.
211
229
 
212
- Five examples run directly from their N3 source in the playground and on the command line.
213
- [family queries](https://eyereasoner.github.io/eyemind/examples/deck/n3-family),
214
- [scoped negation](https://eyereasoner.github.io/eyemind/examples/deck/n3-scoped-negation),
215
- [invoice collection](https://eyereasoner.github.io/eyemind/examples/deck/n3-invoice),
216
- [French cities](https://eyereasoner.github.io/eyemind/examples/deck/n3-french-cities), and
217
- [existential witnesses](https://eyereasoner.github.io/eyemind/examples/deck/n3-witnesses).
230
+ Examples run directly from their N3 source in the playground and on the command line:
231
+ [family queries](https://eyereasoner.github.io/eyemind/examples/deck/family),
232
+ [scoped negation](https://eyereasoner.github.io/eyemind/examples/deck/scoped-negation),
233
+ [invoice collection](https://eyereasoner.github.io/eyemind/examples/deck/invoice),
234
+ [French cities](https://eyereasoner.github.io/eyemind/examples/deck/french-cities), and
235
+ [existential witnesses](https://eyereasoner.github.io/eyemind/examples/deck/witnesses-n3).
218
236
  Each deck shows the N3 result and what its saved proof establishes, including
219
237
  any remaining obligations.
220
238
 
@@ -230,6 +248,11 @@ eyemind -c rules.srl facts.ttl # a proof of it, checked
230
248
 
231
249
  Triples are `rdf(Subject, Predicate, Object)`, with `base/3` marking the base graph and `inf/3` the inference graph. A rule becomes `implies`, `NOT` becomes `not` of a helper, `GROUP` becomes `findall`, a blank node in a rule head becomes the Skolem term of its firing, and a SPARQL error is a goal that fails, so `FILTER` rejects the solution and `SET` drops it. The W3C SPARQL 1.2 RL test suite runs in `npm test` from the mirror in `test/w3c/sparql-rl`: all 241 tests pass. `NOW`, `UUID` and `STRUUID` are not supported, as eyemind has no clock or randomness; decimals and doubles are computed as binary64 floats.
232
250
 
251
+ The [example catalog](https://eyereasoner.github.io/eyemind/examples/) includes
252
+ SRL programs for deployment dependencies, route distances, ancestry, inventory,
253
+ invoices, provenance and Unicode strings. Each has saved Turtle output, a
254
+ proof, a check report and a deck, and runs in the playground.
255
+
233
256
  ## How eyemind reasons
234
257
 
235
258
  The statement chooses the direction:
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.4
5
+ Version: eyemind 0.5.6
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.4",
3
+ "version": "0.5.6",
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",
package/src/formats.js CHANGED
@@ -5,7 +5,8 @@
5
5
  //
6
6
  // .js and standard input an eyemind program
7
7
  // .ttl .trig .nt .nq RDF 1.2 data: with a program, rdf(S, P, O, G)
8
- // facts; with an N3 document, its triples; with a
8
+ // facts; with an N3 document, default triples and
9
+ // graph:content formulas for named graphs; with a
9
10
  // rule set, its base graph
10
11
  // .n3 Notation3, compiled to an eyemind program
11
12
  // .srl a SPARQL 1.2 RL rule set, compiled to one
package/src/n3.js CHANGED
@@ -23,6 +23,7 @@ import { documentIris, readDocuments } from './n3-documents.js';
23
23
  const MATH = 'http://www.w3.org/2000/10/swap/math#';
24
24
  const STRING = 'http://www.w3.org/2000/10/swap/string#';
25
25
  const LIST = 'http://www.w3.org/2000/10/swap/list#';
26
+ const GRAPH_CONTENT = 'https://eyereasoner.github.io/eyemind/graph#content';
26
27
  import { BUILTINS, HELPERS, UNSUPPORTED } from './n3-builtins.js';
27
28
 
28
29
  export class N3CompileError extends Error {}
@@ -797,15 +798,29 @@ function shortName(iri) {
797
798
 
798
799
  // N3 sources, given as [text, name] pairs, read as one document: { triples,
799
800
  // prefixes }. base resolves relative IRIs; blank-node labels are local to
800
- // each source. RDF sources, given as { quads, prefixes }, join as triples.
801
+ // each source. RDF sources, given as { quads, prefixes }, join as triples;
802
+ // named graphs become graph:content formulas, keeping their contents quoted.
801
803
  export function readSources(sources, { base = '', baseOf = () => '' } = {}) {
802
804
  if (typeof sources === 'string') sources = [[sources, 'input']];
803
805
  const docs = sources.map((source) => (Array.isArray(source)
804
806
  ? parseN3(source[0], { base: base || baseOf(source[1]) })
805
- : { triples: source.quads.map(rdfQuadToN3), prefixes: new Map(Object.entries(source.prefixes ?? {})) }));
807
+ : { triples: rdfQuadsToN3(source.quads), prefixes: new Map(Object.entries(source.prefixes ?? {})) }));
806
808
  const doc = { triples: [], prefixes: new Map() };
809
+ const graphs = new Map();
807
810
  docs.forEach((d, k) => {
808
- doc.triples.push(...(docs.length > 1 ? relabel(d.triples, `s${k}.`) : d.triples));
811
+ for (const triple of docs.length > 1 ? relabel(d.triples, `s${k}.`) : d.triples) {
812
+ // The same graph can be supplied by several RDF files. Merge after
813
+ // relabelling so their blank nodes keep their own source scopes.
814
+ if (!Array.isArray(sources[k]) && triple.p.v === GRAPH_CONTENT && triple.o.t === 'graph') {
815
+ const key = `${triple.s.t}:${triple.s.v}`;
816
+ if (graphs.has(key)) {
817
+ graphs.get(key).triples.push(...triple.o.triples);
818
+ continue;
819
+ }
820
+ graphs.set(key, triple.o);
821
+ }
822
+ doc.triples.push(triple);
823
+ }
809
824
  for (const [name, ns] of d.prefixes) if (!doc.prefixes.has(name)) doc.prefixes.set(name, ns);
810
825
  });
811
826
  return doc;
@@ -861,21 +876,37 @@ function relabel(triples, prefix) {
861
876
  return triples.map(triple);
862
877
  }
863
878
 
864
- // An RDF quad, read by rdf.js, as an N3 triple; N3 has no named graphs.
865
- function rdfQuadToN3([s, p, o, g]) {
866
- if (g !== 'default_graph') throw new N3CompileError('N3 has no named graphs; give the data as Turtle or N-Triples');
867
- const term = (t) => {
868
- if (typeof t === 'bigint') return { t: 'int', v: t };
869
- const [a, b, c] = t.args;
870
- switch (t.name) {
871
- case 'iri': return { t: 'iri', v: a };
872
- case 'bnode': return { t: 'bnode', v: `${a}.${b}`, scope: 0 };
873
- case 'triple': return { t: 'triple', s: term(a), p: term(b), o: term(c) };
874
- case 'literal':
875
- if (b.name === 'lang') return { t: 'literal', v: a, lang: b.args[0], dir: b.args[1] ?? null, dt: `${RDF_NS}langString` };
876
- return typedLiteral(a, b.args[0]);
877
- default: throw new N3CompileError(`${write(t)} is no RDF term`);
879
+ // N3 has no dataset syntax. A named graph's name points to its formula;
880
+ // the formula's triples remain separate from default-graph assertions.
881
+ function rdfQuadsToN3(quads) {
882
+ const triples = [];
883
+ const graphs = new Map();
884
+ for (const [s, p, o, g] of quads) {
885
+ const triple = { s: rdfTermToN3(s), p: rdfTermToN3(p), o: rdfTermToN3(o) };
886
+ if (g === 'default_graph') triples.push(triple);
887
+ else {
888
+ const key = write(g);
889
+ if (!graphs.has(key)) {
890
+ const formula = { t: 'graph', triples: [], scope: 0 };
891
+ graphs.set(key, formula);
892
+ triples.push({ s: rdfTermToN3(g), p: { t: 'iri', v: GRAPH_CONTENT }, o: formula });
893
+ }
894
+ graphs.get(key).triples.push(triple);
878
895
  }
879
- };
880
- return { s: term(s), p: term(p), o: term(o) };
896
+ }
897
+ return triples;
898
+ }
899
+
900
+ function rdfTermToN3(t) {
901
+ if (typeof t === 'bigint') return { t: 'int', v: t };
902
+ const [a, b, c] = t.args;
903
+ switch (t.name) {
904
+ case 'iri': return { t: 'iri', v: a };
905
+ case 'bnode': return { t: 'bnode', v: `${a}.${b}`, scope: 0 };
906
+ case 'triple': return { t: 'triple', s: rdfTermToN3(a), p: rdfTermToN3(b), o: rdfTermToN3(c) };
907
+ case 'literal':
908
+ if (b.name === 'lang') return { t: 'literal', v: a, lang: b.args[0], dir: b.args[1] ?? null, dt: `${RDF_NS}langString` };
909
+ return typedLiteral(a, b.args[0]);
910
+ default: throw new N3CompileError(`${write(t)} is no RDF term`);
911
+ }
881
912
  }
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.4';
2
+ export const VERSION = '0.5.6';