eyemind 0.9.18 → 0.9.20
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 +30 -14
- package/bin/eyemind.js +2 -1
- package/package.json +1 -1
- package/src/cli.js +10 -9
- package/src/formats.js +28 -6
- package/src/index.js +1 -1
- package/src/jelly.js +974 -0
- package/src/jsonld.js +906 -0
- package/src/messages.js +135 -5
- package/src/node-messages.js +6 -3
- package/src/node.js +3 -1
- package/src/rdf-lexer.js +11 -4
- package/src/rdf-parser.js +3 -0
- package/src/rdf-xml.js +363 -0
- package/src/rdf.js +105 -8
- package/src/version.js +1 -1
- package/src/xml.js +174 -0
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ 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
|
-
|
|
16
|
+
176 runnable programs, each with a card deck and saved conclusions; all but
|
|
17
17
|
the two 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.
|
|
@@ -289,9 +289,23 @@ the [Pythagorean theorem](https://eyereasoner.github.io/eyemind/examples/deck/py
|
|
|
289
289
|
|
|
290
290
|
### RDF 1.2
|
|
291
291
|
|
|
292
|
-
`.ttl`, `.trig`, `.nt
|
|
293
|
-
|
|
294
|
-
|
|
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
|
|
301
|
+
the Processing Algorithms and API, in the processing mode `json-ld-1.2`, or
|
|
302
|
+
`json-ld-1.1` or `json-ld-1.0` through `parseRdf` of `eyemind/rdf`, which also
|
|
303
|
+
takes `expandContext`, `rdfDirection` and `produceGeneralizedRdf`; a JSON-LD
|
|
304
|
+
context that is not in the document is read from its file, or fetched as
|
|
305
|
+
Notation3 documents are. JSON-LD keeps a base direction only with its
|
|
306
|
+
`rdfDirection` option, as the specification has it. `writeRdf` writes
|
|
307
|
+
expanded JSON-LD, with the `useNativeTypes`, `useRdfType` and
|
|
308
|
+
`rdfDirection` options.
|
|
295
309
|
|
|
296
310
|
| RDF 1.2 | eyemind term |
|
|
297
311
|
| --- | --- |
|
|
@@ -302,7 +316,9 @@ as data: their quads become `rdf(Subject, Predicate, Object, Graph)` facts.
|
|
|
302
316
|
| Triple term | `triple(S, P, O)` |
|
|
303
317
|
| Default graph, named graph | `'default_graph'`, `iri(Name)` |
|
|
304
318
|
|
|
305
|
-
All
|
|
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/).
|
|
306
322
|
|
|
307
323
|
### Notation3
|
|
308
324
|
|
|
@@ -325,17 +341,17 @@ eyemind -c examples/family-n3.n3 # with a checked proof
|
|
|
325
341
|
### RDF Messages
|
|
326
342
|
|
|
327
343
|
eyemind reads [RDF Message](https://w3c-cg.github.io/rsp/spec/messages) logs
|
|
328
|
-
in
|
|
344
|
+
in Turtle, TriG, N-Triples, N-Quads, RDF/XML, where an `rdfm:MessageLog`
|
|
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
|
|
329
348
|
ordered envelopes in the `eymsg:` vocabulary, with proofs;
|
|
330
349
|
`--stream-messages` instead runs the rules once per message, reading files,
|
|
331
350
|
standard input or HTTP(S) incrementally. See the
|
|
332
351
|
[message-boundaries](https://eyereasoner.github.io/eyemind/examples/deck/message-boundaries-n3)
|
|
333
352
|
and [message-alerts](https://eyereasoner.github.io/eyemind/examples/deck/message-alerts-n3) decks.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
coverage: all of the Turtle, TriG, N-Triples and N-Quads cases pass, a wrong
|
|
337
|
-
result fails the run, and the NDJSON-LD, RDF/XML and serialization cases are
|
|
338
|
-
counted as unsupported.
|
|
353
|
+
All 35 [RDF Messages tests](https://w3c-cg.github.io/rsp/spec/messages-tests)
|
|
354
|
+
pass, and every `npm test` runs them.
|
|
339
355
|
|
|
340
356
|
With an [RDF logic profile](#rdf-logic-profiles), `--stream-messages` treats
|
|
341
357
|
the other inputs as a background graph and writes, for each message, the
|
|
@@ -650,7 +666,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
650
666
|
|
|
651
667
|
| Option | Meaning |
|
|
652
668
|
| --- | --- |
|
|
653
|
-
| (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` and `.
|
|
669
|
+
| (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. |
|
|
654
670
|
| `-p`, `--proof` | Print the proof instead. |
|
|
655
671
|
| `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
|
|
656
672
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
@@ -663,7 +679,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
663
679
|
| `--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. |
|
|
664
680
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
665
681
|
| `--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. |
|
|
666
|
-
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `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. |
|
|
682
|
+
| `--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. |
|
|
667
683
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
668
684
|
| `--program` | Print the program the inputs compile to. |
|
|
669
685
|
| `--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`. |
|
|
@@ -788,7 +804,7 @@ Further entry points serve applications built on the formats and profiles:
|
|
|
788
804
|
| Import | Gives |
|
|
789
805
|
| --- | --- |
|
|
790
806
|
| `eyemind/rdf` | `parseRdf(text, { format, base })` and `writeRdf(quads, { format, prefixes })`, RDF 1.2 to and from eyemind terms |
|
|
791
|
-
| `eyemind/messages` | `parseRdfMessages(text)` and `
|
|
807
|
+
| `eyemind/messages` | `parseRdfMessages(text)`, `RdfMessageReader` and `writeRdfMessages(messages)`, for RDF Message logs |
|
|
792
808
|
| `eyemind/formats` | `loadInputs(inputs, io, options)` and `loadMessageReasoner(inputs, io, options)`, the command line's loading of `[text, name]` inputs with the options of the RDF profiles, such as `{ qudt: true, shaclIn, shaclOut }` |
|
|
793
809
|
| `eyemind/cli` | `main(argv, io)`, the command line itself, with `io` as in `eyemind/node` |
|
|
794
810
|
| `eyemind/qudt` | `unitConversion(from, to)` and `quantityKinds(unit)`, from the QUDT catalog of `--qudt` |
|
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.20",
|
|
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 } 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';
|
|
@@ -12,9 +12,10 @@ import { srlContextFromProof } from './srl.js';
|
|
|
12
12
|
|
|
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
|
-
Files are read by extension: .js as LS, .ttl, .trig, .nt
|
|
16
|
-
.
|
|
17
|
-
|
|
15
|
+
Files are read by extension: .js as LS, .ttl, .trig, .nt, .nq, .rdf (RDF/XML),
|
|
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)
|
|
@@ -28,8 +29,8 @@ all compiled to LS.
|
|
|
28
29
|
--max-depth N Bound backward recursion (default 1000000)
|
|
29
30
|
--max-iterations N Bound forward rounds per stratum (default 1000)
|
|
30
31
|
--max-inferences N Bound reasoning work (default 1000000)
|
|
31
|
-
--to FORMAT Write the conclusions as turtle, trig, n-triples,
|
|
32
|
-
|
|
32
|
+
--to FORMAT Write the conclusions as turtle, trig, n-triples, n-quads,
|
|
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
|
|
@@ -217,8 +218,8 @@ export function main(argv, io) {
|
|
|
217
218
|
// Hosts such as the playground already hold their inputs as text.
|
|
218
219
|
// Node supplies the incremental file/HTTP implementation instead.
|
|
219
220
|
const sources = files.map((name, index) => ({ name, index, text: readSource(name, io) }));
|
|
220
|
-
const logs = sources.filter(({ text }) =>
|
|
221
|
-
if (!logs.length) throw new UsageError('--stream-messages needs an RDF Message Log
|
|
221
|
+
const logs = sources.filter(({ name, text }) => isLog(text, name));
|
|
222
|
+
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
223
|
const inputs = sources.filter((source) => !logs.includes(source)).map(({ name, text }) => [name, text]);
|
|
223
224
|
for (const { name, text, index } of logs) {
|
|
224
225
|
let code = 0;
|
package/src/formats.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
// A file's extension says what it holds:
|
|
5
5
|
//
|
|
6
6
|
// .js and standard input a Logic Script (LS) program
|
|
7
|
-
// .ttl .trig .nt .nq RDF 1.2 data
|
|
8
|
-
//
|
|
7
|
+
// .ttl .trig .nt .nq RDF 1.2 data, and RDF/XML (.rdf), JSON-LD
|
|
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
|
|
9
11
|
// graph:content formulas for named graphs; with a
|
|
10
12
|
// rule set, its base graph
|
|
11
13
|
// .n3 Notation3, compiled to an LS program
|
|
@@ -31,8 +33,9 @@ import { compileRdfLogic, messageReasoner, RDF_PROFILES, shaclIn as shaclInPatte
|
|
|
31
33
|
import { compileLe, writeLe } from './le.js';
|
|
32
34
|
import { write } from './writer.js';
|
|
33
35
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
36
|
+
import { isJellyMessages } from './jelly.js';
|
|
34
37
|
|
|
35
|
-
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3', 'le'];
|
|
38
|
+
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'rdf-xml', 'json-ld', 'jelly', 'n3', 'le'];
|
|
36
39
|
export { RDF_PROFILES };
|
|
37
40
|
|
|
38
41
|
// What a file holds: 'js', 'rdf', 'n3', 'srl' or 'le'.
|
|
@@ -98,6 +101,25 @@ function outputContract(text, name, io) {
|
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
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
|
+
|
|
113
|
+
// The remote contexts of a JSON-LD input: a file: IRI is read as a file, an
|
|
114
|
+
// HTTP(S) one as the documents of N3 are.
|
|
115
|
+
function documentLoader(io) {
|
|
116
|
+
return (url) => {
|
|
117
|
+
if (url.startsWith('file:') && io?.readFile) return { document: io.readFile(decodeURIComponent(new URL(url).pathname)), documentUrl: url };
|
|
118
|
+
if (/^https?:/.test(url) && io?.readDocument) return { document: io.readDocument(url), documentUrl: url };
|
|
119
|
+
throw new EyemindError(`cannot read the context ${url}`);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
101
123
|
// The reasoner the logic profiles run each RDF Message with, given the
|
|
102
124
|
// background inputs as [text, name] pairs (rdf-logic.js).
|
|
103
125
|
export function loadMessageReasoner(inputs, io = null, options = {}) {
|
|
@@ -116,8 +138,8 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
116
138
|
(inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
|
|
117
139
|
const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
|
|
118
140
|
const rdf = (text, name, k) => messageInputs?.get(name) ??
|
|
119
|
-
(
|
|
120
|
-
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k),
|
|
141
|
+
(isLog(text, name) ? parseRdfMessages : parseRdf)(text, {
|
|
142
|
+
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k), loadDocument: documentLoader(io),
|
|
121
143
|
});
|
|
122
144
|
// These rule sets are added only when requested, never from vocabulary.
|
|
123
145
|
if (kinds.includes('le')) {
|
|
@@ -135,7 +157,7 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
135
157
|
if (odrl) checkOdrlInput(graph.quads);
|
|
136
158
|
const source = inputs.map(([, n]) => n).join(', ');
|
|
137
159
|
// SHACL shapes as contracts: what messages hold, and what is wanted.
|
|
138
|
-
const shapes = ([text, name]) => parseRdf(text, { format: rdfFormat(name) ?? 'turtle', base: baseOf(name) }).quads;
|
|
160
|
+
const shapes = ([text, name]) => parseRdf(text, { format: rdfFormat(name) ?? 'turtle', base: baseOf(name), loadDocument: documentLoader(io) }).quads;
|
|
139
161
|
if (shaclOut) graph.wanted = [...graph.wanted ?? [], ...shaclOut.flatMap((input) => shaclOutPatterns(shapes(input), input[1]))];
|
|
140
162
|
graph.planned = Boolean(shaclIn || shaclOut);
|
|
141
163
|
if (shaclIn) {
|
package/src/index.js
CHANGED
|
@@ -13,6 +13,6 @@ export { checkProof, checkReport, publicReport, verdictText } from './proof.js';
|
|
|
13
13
|
export { readTerm, readTerms } from './reader.js';
|
|
14
14
|
export { EyemindError, Struct, Var } from './terms.js';
|
|
15
15
|
export { write } from './writer.js';
|
|
16
|
-
export { RdfMessageReader, parseRdfMessages } from './messages.js';
|
|
16
|
+
export { RdfMessageReader, parseRdfMessages, writeRdfMessages } from './messages.js';
|
|
17
17
|
export { compileLe, writeLe } from './le.js';
|
|
18
18
|
export { explainLe } from './le-explain.js';
|