eyemind 0.5.0 → 0.5.2
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 +47 -13
- package/SPEC.md +598 -343
- package/package.json +1 -1
- package/src/cli.js +37 -5
- package/src/formats.js +149 -0
- package/src/n3-builtins.js +590 -0
- package/src/n3-documents.js +66 -0
- package/src/n3-parser.js +463 -0
- package/src/n3-writer.js +199 -0
- package/src/n3.js +814 -0
- package/src/node.js +4 -0
- package/src/proof.js +1 -1
- package/src/rdf-lexer.js +2025 -0
- package/src/rdf-parser.js +827 -0
- package/src/rdf-prelude.js +808 -0
- package/src/rdf-rules.js +106 -0
- package/src/rdf-syntax.js +249 -0
- package/src/rdf.js +429 -0
- package/src/srl-analyze.js +703 -0
- package/src/srl-assignments.js +40 -0
- package/src/srl-builtin-names.js +78 -0
- package/src/srl-functions.js +584 -0
- package/src/srl-parser.js +816 -0
- package/src/srl-term.js +288 -0
- package/src/srl-tokenizer.js +341 -0
- package/src/srl.js +649 -0
- package/src/version.js +1 -1
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
|
|
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).
|
|
11
11
|
|
|
12
12
|
## Contents
|
|
13
13
|
|
|
@@ -20,6 +20,7 @@ The playground runs programs in your browser; the specification defines the lang
|
|
|
20
20
|
- [Inspecting rules](#inspecting-rules)
|
|
21
21
|
- [RDF 1.2](#rdf-12)
|
|
22
22
|
- [Notation3](#notation3)
|
|
23
|
+
- [SPARQL 1.2 RL](#sparql-12-rl)
|
|
23
24
|
- [How eyemind reasons](#how-eyemind-reasons)
|
|
24
25
|
- [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
|
|
25
26
|
- [Why negation and collection are safe](#why-negation-and-collection-are-safe)
|
|
@@ -59,7 +60,7 @@ Prolog, Datalog, N3 and SRL already exist, and eyemind adds no new logic: rules
|
|
|
59
60
|
When eyemind is not the right tool:
|
|
60
61
|
|
|
61
62
|
- If you do not need proofs, use the mature tools: SWI-Prolog and XSB have tabling, and Soufflé is fast at scale.
|
|
62
|
-
- N3 and SRL are designed around RDF and Web data. eyemind does not compete there: RDF
|
|
63
|
+
- N3 and SRL are designed around RDF and Web data. eyemind does not compete there: RDF is read as data (see [RDF 1.2](#rdf-12)), and N3 programs and SRL rule sets compile to eyemind (see [Notation3](#notation3) and [SPARQL 1.2 RL](#sparql-12-rl)).
|
|
63
64
|
- eyemind is for cases where someone else has to be able to check why a conclusion holds: audits, compliance, and decisions between parties that do not trust each other.
|
|
64
65
|
|
|
65
66
|
## Install and run
|
|
@@ -173,30 +174,58 @@ The answer is `test(a(A), c(A))`, with the shared variable preserved. Inspection
|
|
|
173
174
|
|
|
174
175
|
### RDF 1.2
|
|
175
176
|
|
|
176
|
-
eyemind
|
|
177
|
+
eyemind reads RDF 1.2 itself, with no dependency: a file ending in `.ttl`, `.trig`, `.nt` or `.nq` is Turtle, TriG, N-Triples or N-Quads, read by [eyeling](https://github.com/eyereasoner/eyeling)'s parser with the formats' own grammars, and given with a program its quads become `rdf(Subject, Predicate, Object, Graph)` facts, read as data through `facts_from` and never run. `--to turtle`, `trig`, `n-triples` or `n-quads` writes a run's `rdf` and `result_rdf` conclusions back as RDF:
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
eyemind rules.js data.ttl # rdf/4 facts for the rules
|
|
181
|
+
eyemind --to trig rules.js data.trig # the conclusions as TriG
|
|
182
|
+
```
|
|
177
183
|
|
|
178
184
|
| RDF 1.2 | eyemind term |
|
|
179
185
|
| --- | --- |
|
|
180
186
|
| IRI | `iri('https://example.org/bob')` |
|
|
181
|
-
| Blank node | `bnode(Scope, Label)
|
|
182
|
-
|
|
|
187
|
+
| Blank node | `bnode(Scope, Label)`, the scope naming the file |
|
|
188
|
+
| `xsd:integer` with a canonical lexical form | an integer, `42`, exact at any size |
|
|
189
|
+
| Other typed literal | `literal('1.50', datatype('http://www.w3.org/2001/XMLSchema#decimal'))`, its lexical form kept |
|
|
183
190
|
| Language string | `literal('chat', lang('fr'))`, or `lang('ar', 'rtl')` with a direction |
|
|
184
191
|
| Triple term | `triple(S, P, O)`, which may nest |
|
|
185
192
|
| Default graph, named graph | `'default_graph'`, `iri(Name)` |
|
|
186
193
|
|
|
187
|
-
A Skolem term
|
|
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 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.
|
|
188
195
|
|
|
189
196
|
### Notation3
|
|
190
197
|
|
|
191
|
-
|
|
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:
|
|
199
|
+
|
|
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
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Triples are `rdf(Subject, Predicate, Object)`, with IRIs, blank nodes and literals written as in the RDF table above and N3 numbers as eyemind numbers. `=>` 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. The documents `log:semantics` and `log:content` name are read before compiling, from local files only.
|
|
207
|
+
|
|
208
|
+
Five examples pair the original N3 with a compiled JavaScript program:
|
|
209
|
+
[family queries](https://eyereasoner.github.io/eyemind/examples/deck/n3-family),
|
|
210
|
+
[scoped negation](https://eyereasoner.github.io/eyemind/examples/deck/n3-scoped-negation),
|
|
211
|
+
[invoice collection](https://eyereasoner.github.io/eyemind/examples/deck/n3-invoice),
|
|
212
|
+
[French cities](https://eyereasoner.github.io/eyemind/examples/deck/n3-french-cities), and
|
|
213
|
+
[existential witnesses](https://eyereasoner.github.io/eyemind/examples/deck/n3-witnesses).
|
|
214
|
+
The saved `.js` programs run directly in the playground and with eyemind.
|
|
215
|
+
Each deck shows the N3 result and what its saved proof establishes, including
|
|
216
|
+
any remaining obligations.
|
|
217
|
+
|
|
218
|
+
### SPARQL 1.2 RL
|
|
219
|
+
|
|
220
|
+
A file ending in `.srl` is a [SPARQL 1.2 RL](https://www.w3.org/TR/sparql12-rl/) rule set, read with [eyeleng](https://github.com/eyereasoner/eyeleng)'s parser and analysis: eyemind compiles it into a program, with the SPARQL functions and aggregates it uses written as eyemind rules, and RDF data files given with it are its base graph. The result is the inference graph, as Turtle:
|
|
192
221
|
|
|
193
222
|
```sh
|
|
194
|
-
|
|
195
|
-
eyemind
|
|
196
|
-
|
|
223
|
+
eyemind rules.srl facts.ttl # the inference graph as Turtle
|
|
224
|
+
eyemind --all rules.srl facts.ttl # the base graph too
|
|
225
|
+
eyemind -c rules.srl facts.ttl # a proof of it, checked
|
|
197
226
|
```
|
|
198
227
|
|
|
199
|
-
Triples are `rdf(Subject, Predicate, Object)`, with
|
|
228
|
+
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.
|
|
200
229
|
|
|
201
230
|
## How eyemind reasons
|
|
202
231
|
|
|
@@ -306,7 +335,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
306
335
|
|
|
307
336
|
| Option | Meaning |
|
|
308
337
|
| --- | --- |
|
|
309
|
-
| (none) | Load the files, or standard input, as one program and print its conclusions. |
|
|
338
|
+
| (none) | Load the files, or standard input, as one program and print its conclusions. `.ttl`, `.trig`, `.nt` and `.nq` files are RDF data, `.n3` Notation3 and `.srl` a SPARQL 1.2 RL rule set. |
|
|
310
339
|
| `-p`, `--proof` | Print the proof instead. |
|
|
311
340
|
| `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
|
|
312
341
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
@@ -315,7 +344,11 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
315
344
|
| `--strict-proof` | With a checking mode, reject proofs with any obligation. |
|
|
316
345
|
| `--unused` | List the clauses that make no difference to the conclusions. |
|
|
317
346
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
318
|
-
| `--max-depth N`, `--max-iterations N`, `--max-inferences N` | Bound backward depth (1000000), forward rounds per stratum (1000) and goals started (1000000). |
|
|
347
|
+
| `--max-depth N`, `--max-iterations N`, `--max-inferences N` | Bound backward depth (1000000), forward rounds per stratum (1000) and goals started (1000000); a compiled N3 or SRL program has 1000000, 100000 and 1000000000. |
|
|
348
|
+
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3` or `eyemind`; by default N3 for N3, Turtle for SRL, eyemind otherwise. |
|
|
349
|
+
| `--all` | With RDF or N3 output, write the given data too. |
|
|
350
|
+
| `--program` | Print the program the inputs compile to. |
|
|
351
|
+
| `--base IRI` | Resolve relative IRIs of the inputs against `IRI` instead of each file's location. |
|
|
319
352
|
| `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
|
|
320
353
|
|
|
321
354
|
Exit codes: 0 success, 1 error, 2 a proof that is not valid, 65 a contradiction.
|
|
@@ -363,6 +396,7 @@ npm test -- unit examples # only these sections
|
|
|
363
396
|
npm test -- -k skolem # only tests whose line contains "skolem"
|
|
364
397
|
EYEMIND_PROPERTY_SCALE=20 npm test -- -k properties # deeper generated tests
|
|
365
398
|
node tools/update-examples.js # regenerate example artifacts after an intended change
|
|
399
|
+
node tools/report.js # the table npm test ends with, into REPORT.md
|
|
366
400
|
node conformance/run.js --command "my-eyemind" # run the conformance suite against another implementation
|
|
367
401
|
```
|
|
368
402
|
|