eyemind 0.9.19 → 0.9.21
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/LS-SPEC.md +1 -1
- package/README.md +29 -19
- package/bin/eyemind.js +2 -1
- package/package.json +1 -1
- package/src/cli.js +13 -9
- package/src/formats.js +15 -5
- package/src/jelly.js +974 -0
- package/src/messages.js +41 -10
- package/src/node-messages.js +5 -3
- package/src/node.js +3 -1
- package/src/qudt.js +5 -1
- package/src/rdf-logic.js +11 -7
- package/src/rdf.js +29 -17
- package/src/specialize.js +3 -3
- package/src/version.js +1 -1
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ program, a JavaScript library and a browser application.
|
|
|
13
13
|
- [Playground](https://eyereasoner.github.io/eyemind/playground/): run any
|
|
14
14
|
example or your own program in the browser, with its proof and check report.
|
|
15
15
|
- [Examples](https://eyereasoner.github.io/eyemind/examples/): the
|
|
16
|
-
|
|
17
|
-
the
|
|
16
|
+
177 runnable programs, each with a card deck and saved conclusions; all but
|
|
17
|
+
the three streamed examples also save proofs and check reports.
|
|
18
18
|
- [Specification](https://eyereasoner.github.io/eyemind/LS-SPEC): the
|
|
19
19
|
language, the proof format and how a proof is checked.
|
|
20
20
|
- [Logic Script conformance](https://eyereasoner.github.io/eyemind/conformance/)
|
|
@@ -289,12 +289,15 @@ the [Pythagorean theorem](https://eyereasoner.github.io/eyemind/examples/deck/py
|
|
|
289
289
|
|
|
290
290
|
### RDF 1.2
|
|
291
291
|
|
|
292
|
-
`.ttl`, `.trig`, `.nt`, `.nq`, `.rdf` (RDF/XML)
|
|
293
|
-
are read with the formats' own grammars, as data:
|
|
294
|
-
`rdf(Subject, Predicate, Object, Graph)` facts.
|
|
295
|
-
`n-triples`, `n-quads`, `rdf-xml
|
|
296
|
-
Turtle, N-Triples and RDF/XML refuse named
|
|
297
|
-
and JSON-LD refuses triple terms.
|
|
292
|
+
`.ttl`, `.trig`, `.nt`, `.nq`, `.rdf` (RDF/XML), `.jsonld` (JSON-LD) and
|
|
293
|
+
`.jelly` (Jelly) files are read with the formats' own grammars, as data:
|
|
294
|
+
their quads become `rdf(Subject, Predicate, Object, Graph)` facts.
|
|
295
|
+
`--to turtle`, `trig`, `n-triples`, `n-quads`, `rdf-xml`, `json-ld` or `jelly`
|
|
296
|
+
writes the conclusions back; Turtle, N-Triples and RDF/XML refuse named
|
|
297
|
+
graphs, which they cannot hold, and JSON-LD refuses triple terms.
|
|
298
|
+
[Jelly](https://w3id.org/jelly/) is a binary format of Protocol Buffers,
|
|
299
|
+
read and written without a library: eyemind reads Jelly-RDF 1.2 (the column
|
|
300
|
+
layout) and Jelly-RDF 1.0 and 1.1 (the row layout), and writes Jelly-RDF 1.2. JSON-LD follows the JSON-LD 1.2 draft of
|
|
298
301
|
the Processing Algorithms and API, in the processing mode `json-ld-1.2`, or
|
|
299
302
|
`json-ld-1.1` or `json-ld-1.0` through `parseRdf` of `eyemind/rdf`, which also
|
|
300
303
|
takes `expandContext`, `rdfDirection` and `produceGeneralizedRdf`; a JSON-LD
|
|
@@ -313,8 +316,9 @@ expanded JSON-LD, with the `useNativeTypes`, `useRdfType` and
|
|
|
313
316
|
| Triple term | `triple(S, P, O)` |
|
|
314
317
|
| Default graph, named graph | `'default_graph'`, `iri(Name)` |
|
|
315
318
|
|
|
316
|
-
All 1262 W3C RDF 1.1 and 1.2 tests pass, RDF/XML included,
|
|
317
|
-
`toRdf` and `fromRdf` tests of the W3C JSON-LD API
|
|
319
|
+
All 1262 W3C RDF 1.1 and 1.2 tests pass, RDF/XML included, all 522
|
|
320
|
+
`toRdf` and `fromRdf` tests of the W3C JSON-LD API, and all 367
|
|
321
|
+
[Jelly-RDF conformance tests](https://w3id.org/jelly/dev/conformance/rdf-test-cases/).
|
|
318
322
|
|
|
319
323
|
### Notation3
|
|
320
324
|
|
|
@@ -338,8 +342,9 @@ eyemind -c examples/family-n3.n3 # with a checked proof
|
|
|
338
342
|
|
|
339
343
|
eyemind reads [RDF Message](https://w3c-cg.github.io/rsp/spec/messages) logs
|
|
340
344
|
in Turtle, TriG, N-Triples, N-Quads, RDF/XML, where an `rdfm:MessageLog`
|
|
341
|
-
holds one `rdf:RDF` per message,
|
|
342
|
-
line
|
|
345
|
+
holds one `rdf:RDF` per message, NDJSON-LD (`.ndjson`), a JSON object per
|
|
346
|
+
line, and Jelly streams of RDF Messages; `writeRdfMessages` of
|
|
347
|
+
`eyemind/messages` writes them. By default rules see the whole log replayed as
|
|
343
348
|
ordered envelopes in the `eymsg:` vocabulary, with proofs;
|
|
344
349
|
`--stream-messages` instead runs the rules once per message, reading files,
|
|
345
350
|
standard input or HTTP(S) incrementally. See the
|
|
@@ -359,10 +364,13 @@ the same as running the whole program over the background and the message,
|
|
|
359
364
|
and the whole program runs instead when new triples could have any property,
|
|
360
365
|
as `owl:sameAs` between individuals makes, or when a negation could retract
|
|
361
366
|
a background conclusion. With `--qudt`, the compiler reads the units and
|
|
362
|
-
metadata of each message
|
|
363
|
-
|
|
367
|
+
metadata of each message: a message whose units need catalog facts the
|
|
368
|
+
background lacks runs the whole program, compiled with its own units, and the
|
|
369
|
+
others, such as those of QUDT's builtin units, use the specialized rules.
|
|
364
370
|
`--program` prints the specialized program of each new shape, and `--stats`
|
|
365
|
-
says whether each message used one.
|
|
371
|
+
says whether each message used one. `--to` writes each message's triples as
|
|
372
|
+
`turtle`, `trig`, `n-triples`, `n-quads` or `jelly`; Jelly messages, one per
|
|
373
|
+
message, form one Jelly stream. Streamed messages have no proofs.
|
|
366
374
|
|
|
367
375
|
An [output contract](#rdf-logic-profiles) prunes the specialized rules to
|
|
368
376
|
those that can contribute to a triple it asks for, following premises back
|
|
@@ -392,7 +400,9 @@ property or class in a rule takes the values its schema premise has in the
|
|
|
392
400
|
background, as partial evaluation gives them. Planned rules derive what the shapes lead to,
|
|
393
401
|
not every OWL 2 RL consequence: equality that the output does not ask for is
|
|
394
402
|
not derived. See the
|
|
395
|
-
[shape-planning](https://eyereasoner.github.io/eyemind/examples/deck/shape-planning-owl2rl) deck
|
|
403
|
+
[shape-planning](https://eyereasoner.github.io/eyemind/examples/deck/shape-planning-owl2rl) deck,
|
|
404
|
+
and the [readings](https://eyereasoner.github.io/eyemind/examples/deck/readings-skos-qudt)
|
|
405
|
+
deck for SKOS and QUDT over messages in Jelly.
|
|
396
406
|
|
|
397
407
|
```sh
|
|
398
408
|
eyemind --owl2rl --stream-messages ontology.ttl messages.trig # each message's new triples
|
|
@@ -649,7 +659,7 @@ A clause is listed when no conclusion's proof uses it; a clause only a negation
|
|
|
649
659
|
|
|
650
660
|
## Examples and the playground
|
|
651
661
|
|
|
652
|
-
The [examples](https://eyereasoner.github.io/eyemind/examples/) range from classics (Ackermann, the zebra puzzle) to planning, policy reasoning, mathematics, RDF 1.2 data and a hundred-thousand-level taxonomy. Each has its conclusions saved in `examples/output/`, all but the
|
|
662
|
+
The [examples](https://eyereasoner.github.io/eyemind/examples/) range from classics (Ackermann, the zebra puzzle) to planning, policy reasoning, mathematics, RDF 1.2 data and a hundred-thousand-level taxonomy. Each has its conclusions saved in `examples/output/`, all but the three streamed examples their proof and check report in `examples/proof/` and `examples/check/`, and each a card deck for a wide audience. Change a fact, run it, and compare with the saved output.
|
|
653
663
|
|
|
654
664
|
The [playground](https://eyereasoner.github.io/eyemind/playground/) runs eyemind in a worker in your browser, so **Stop** ends a long run. Choose an example, edit it, pick an output (conclusions, proof, checked answers, check of a saved proof, unused clauses, Logical English answers explained, or independent RDF Messages) and press **Run** or Ctrl+Enter. A line an error names is marked red, the options panel shows the equivalent command, and **Share link** copies a link with the program and options.
|
|
655
665
|
|
|
@@ -661,7 +671,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
661
671
|
|
|
662
672
|
| Option | Meaning |
|
|
663
673
|
| --- | --- |
|
|
664
|
-
| (none) | Load the files, or standard input, as one program and print its conclusions. `.js` files and standard input are Logic Script, `.ttl`, `.trig`, `.nt`, `.nq`, `.rdf` (RDF/XML), `.jsonld` (JSON-LD)
|
|
674
|
+
| (none) | Load the files, or standard input, as one program and print its conclusions. `.js` files and standard input are Logic Script, `.ttl`, `.trig`, `.nt`, `.nq`, `.rdf` (RDF/XML), `.jsonld` (JSON-LD), `.ndjson` (NDJSON-LD message log) and `.jelly` (Jelly) files RDF data, `.n3` Notation3, `.srl` a SPARQL 1.2 RL rule set and `.le` Logical English. |
|
|
665
675
|
| `-p`, `--proof` | Print the proof instead. |
|
|
666
676
|
| `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
|
|
667
677
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
@@ -674,7 +684,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
674
684
|
| `--shacl-out FILE` | With an RDF logic profile, plan only the rules that conclude triples the SHACL shapes in `FILE` describe, or what those rules read, and write only those triples. |
|
|
675
685
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
676
686
|
| `--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, SRL, ODRL or RDF profile program has 1000000, 100000 and 1000000000. |
|
|
677
|
-
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `rdf-xml`, `json-ld`, `n3`, `le` or `eyemind`; `n3` only for an N3 run and `le` only for an LE run; by default LE for LE, N3 for N3, Turtle for SRL, ODRL and RDF profiles, eyemind otherwise. |
|
|
687
|
+
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `rdf-xml`, `json-ld`, `jelly`, `n3`, `le` or `eyemind`; `n3` only for an N3 run and `le` only for an LE run; by default LE for LE, N3 for N3, Turtle for SRL, ODRL and RDF profiles, eyemind otherwise. |
|
|
678
688
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
679
689
|
| `--program` | Print the program the inputs compile to. |
|
|
680
690
|
| `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input; with RDF logic profiles, the snapshot also reads what they entail about its states. Not with `--stream-messages`, `--shacl-in` or `--shacl-out`. |
|
package/bin/eyemind.js
CHANGED
|
@@ -7,7 +7,8 @@ import { streamMessages } from '../src/node-messages.js';
|
|
|
7
7
|
|
|
8
8
|
function write(fd, text) {
|
|
9
9
|
// Written synchronously, so a large proof is complete before the exit.
|
|
10
|
-
|
|
10
|
+
// Jelly output is bytes, any other output text.
|
|
11
|
+
const buffer = typeof text === 'string' ? Buffer.from(text, 'utf8') : Buffer.from(text);
|
|
11
12
|
let offset = 0;
|
|
12
13
|
while (offset < buffer.length) {
|
|
13
14
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
4
4
|
"description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// The eyemind command line.
|
|
2
2
|
import { COMPILED_LIMITS, run, unusedClauses } from './engine.js';
|
|
3
|
-
import { OUTPUT_FORMATS, RDF_PROFILES, defaultFormat, inputKind, loadInputs, loadMessageReasoner, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
|
|
3
|
+
import { OUTPUT_FORMATS, RDF_PROFILES, defaultFormat, inputKind, isLog, loadInputs, loadMessageReasoner, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
|
|
4
4
|
import { explainLe } from './le-explain.js';
|
|
5
|
-
import {
|
|
5
|
+
import { replayMessages, RdfMessageReader, writeRdfMessages } from './messages.js';
|
|
6
6
|
import { checkProof, checkReport, publicReport } from './proof.js';
|
|
7
7
|
import { writeRdf } from './rdf.js';
|
|
8
8
|
import { programText } from './specialize.js';
|
|
@@ -13,8 +13,9 @@ import { srlContextFromProof } from './srl.js';
|
|
|
13
13
|
export const HELP = `Usage: eyemind [OPTION ...] [FILE ...]
|
|
14
14
|
Logic Script (LS) programs use JavaScript syntax. Forward rules run to a fixpoint.
|
|
15
15
|
Files are read by extension: .js as LS, .ttl, .trig, .nt, .nq, .rdf (RDF/XML),
|
|
16
|
-
.jsonld (JSON-LD)
|
|
17
|
-
.srl as SPARQL 1.2 RL and .le as Logical English, all
|
|
16
|
+
.jsonld (JSON-LD), .ndjson (NDJSON-LD log) and .jelly (Jelly) as RDF 1.2 data,
|
|
17
|
+
.n3 as Notation3, .srl as SPARQL 1.2 RL and .le as Logical English, all
|
|
18
|
+
compiled to LS.
|
|
18
19
|
-p, --proof Print a proof of the conclusions
|
|
19
20
|
-c, --prove-and-check Generate a proof and check it against the input program
|
|
20
21
|
--check-proof FILE Check a proof and print its answers and verdict (- for stdin)
|
|
@@ -29,7 +30,7 @@ Files are read by extension: .js as LS, .ttl, .trig, .nt, .nq, .rdf (RDF/XML),
|
|
|
29
30
|
--max-iterations N Bound forward rounds per stratum (default 1000)
|
|
30
31
|
--max-inferences N Bound reasoning work (default 1000000)
|
|
31
32
|
--to FORMAT Write the conclusions as turtle, trig, n-triples, n-quads,
|
|
32
|
-
rdf-xml, json-ld, n3, le or eyemind (default: le for LE, n3 for N3, turtle
|
|
33
|
+
rdf-xml, json-ld, jelly, n3, le or eyemind (default: le for LE, n3 for N3, turtle
|
|
33
34
|
for SRL, ODRL or RDF logic profiles, eyemind otherwise or with --goal)
|
|
34
35
|
--all With RDF or N3 output, write the given data too
|
|
35
36
|
--program Print the program the inputs compile to
|
|
@@ -53,7 +54,7 @@ Exit codes: 0 success, 1 error, 2 invalid proof, 65 contradiction.
|
|
|
53
54
|
const LIMITS = { '--max-depth': 'maxDepth', '--max-iterations': 'maxIterations', '--max-inferences': 'maxInferences' };
|
|
54
55
|
const ALIASES = new Map([['-p', '--proof'], ['-c', '--prove-and-check'], ['-v', '--version'], ['-h', '--help']]);
|
|
55
56
|
|
|
56
|
-
const RDF_FORMATS = ['turtle', 'trig', 'n-triples', 'n-quads'];
|
|
57
|
+
const RDF_FORMATS = ['turtle', 'trig', 'n-triples', 'n-quads', 'jelly'];
|
|
57
58
|
|
|
58
59
|
class UsageError extends Error {}
|
|
59
60
|
|
|
@@ -196,7 +197,10 @@ export function main(argv, io) {
|
|
|
196
197
|
else if (!result.specialized && messageNumber === 1) stdout(`// These rules are not specialized: ${reasoner.reason ?? 'a message has a shape they cannot be specialized to'}.\n`);
|
|
197
198
|
return 0;
|
|
198
199
|
}
|
|
199
|
-
|
|
200
|
+
const prefixes = { ...reasoner.prefixes, ...message.prefixes };
|
|
201
|
+
// A Jelly log per message, all of quads, so that they concatenate.
|
|
202
|
+
stdout(format === 'jelly' ? writeRdfMessages([result.quads], { format, prefixes, physicalType: 'quads' })
|
|
203
|
+
: writeRdf(result.quads, { format: format ?? 'turtle', prefixes, blankNodePrefix: `m${messageNumber}_` }));
|
|
200
204
|
if (stats) stderr(`${JSON.stringify({ message: message.index, specialized: result.specialized, dropped: result.dropped, conforms: result.conforms, ...result.stats })}\n`);
|
|
201
205
|
return result.haltCode || 0;
|
|
202
206
|
};
|
|
@@ -217,8 +221,8 @@ export function main(argv, io) {
|
|
|
217
221
|
// Hosts such as the playground already hold their inputs as text.
|
|
218
222
|
// Node supplies the incremental file/HTTP implementation instead.
|
|
219
223
|
const sources = files.map((name, index) => ({ name, index, text: readSource(name, io) }));
|
|
220
|
-
const logs = sources.filter(({ name, text }) =>
|
|
221
|
-
if (!logs.length) throw new UsageError('--stream-messages needs an RDF Message Log: VERSION "*-messages", an rdfm:MessageLog in RDF/XML,
|
|
224
|
+
const logs = sources.filter(({ name, text }) => isLog(text, name));
|
|
225
|
+
if (!logs.length) throw new UsageError('--stream-messages needs an RDF Message Log: VERSION "*-messages", an rdfm:MessageLog in RDF/XML, NDJSON-LD (.ndjson), or Jelly messages');
|
|
222
226
|
const inputs = sources.filter((source) => !logs.includes(source)).map(({ name, text }) => [name, text]);
|
|
223
227
|
for (const { name, text, index } of logs) {
|
|
224
228
|
let code = 0;
|
package/src/formats.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
//
|
|
6
6
|
// .js and standard input a Logic Script (LS) program
|
|
7
7
|
// .ttl .trig .nt .nq RDF 1.2 data, and RDF/XML (.rdf), JSON-LD
|
|
8
|
-
// .rdf .jsonld .ndjson (.jsonld)
|
|
9
|
-
//
|
|
10
|
-
// document, default triples and
|
|
8
|
+
// .rdf .jsonld .ndjson (.jsonld), NDJSON-LD logs (.ndjson) and Jelly
|
|
9
|
+
// .jelly (.jelly): with a program, rdf(S, P, O, G) facts;
|
|
10
|
+
// with an N3 document, default triples and
|
|
11
11
|
// graph:content formulas for named graphs; with a
|
|
12
12
|
// rule set, its base graph
|
|
13
13
|
// .n3 Notation3, compiled to an LS program
|
|
@@ -33,8 +33,9 @@ import { compileRdfLogic, messageReasoner, RDF_PROFILES, shaclIn as shaclInPatte
|
|
|
33
33
|
import { compileLe, writeLe } from './le.js';
|
|
34
34
|
import { write } from './writer.js';
|
|
35
35
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
36
|
+
import { isJellyMessages } from './jelly.js';
|
|
36
37
|
|
|
37
|
-
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'rdf-xml', 'json-ld', 'n3', 'le'];
|
|
38
|
+
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'rdf-xml', 'json-ld', 'jelly', 'n3', 'le'];
|
|
38
39
|
export { RDF_PROFILES };
|
|
39
40
|
|
|
40
41
|
// What a file holds: 'js', 'rdf', 'n3', 'srl' or 'le'.
|
|
@@ -100,6 +101,15 @@ function outputContract(text, name, io) {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
// Whether an input is an RDF Message Log: NDJSON-LD always, Jelly when its
|
|
105
|
+
// stream type is MESSAGES, the other formats when their text says so.
|
|
106
|
+
export function isLog(text, name) {
|
|
107
|
+
const format = rdfMessageFormat(name);
|
|
108
|
+
if (format === 'ndjson-ld') return true;
|
|
109
|
+
if (format === 'jelly') return isJellyMessages(text);
|
|
110
|
+
return isRdfMessageLog(text);
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
// The remote contexts of a JSON-LD input: a file: IRI is read as a file, an
|
|
104
114
|
// HTTP(S) one as the documents of N3 are.
|
|
105
115
|
function documentLoader(io) {
|
|
@@ -128,7 +138,7 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
128
138
|
(inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
|
|
129
139
|
const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
|
|
130
140
|
const rdf = (text, name, k) => messageInputs?.get(name) ??
|
|
131
|
-
(
|
|
141
|
+
(isLog(text, name) ? parseRdfMessages : parseRdf)(text, {
|
|
132
142
|
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k), loadDocument: documentLoader(io),
|
|
133
143
|
});
|
|
134
144
|
// These rule sets are added only when requested, never from vocabulary.
|