eyemind 0.9.18 → 0.9.19
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 +25 -14
- package/package.json +1 -1
- package/src/cli.js +7 -7
- package/src/formats.js +18 -6
- package/src/index.js +1 -1
- package/src/jsonld.js +906 -0
- package/src/messages.js +103 -3
- package/src/node-messages.js +2 -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 +92 -7
- 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,20 @@ 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
|
-
as data: their quads become
|
|
294
|
-
`--to turtle`, `trig`,
|
|
292
|
+
`.ttl`, `.trig`, `.nt`, `.nq`, `.rdf` (RDF/XML) and `.jsonld` (JSON-LD) files
|
|
293
|
+
are read with the formats' own grammars, as data: their quads become
|
|
294
|
+
`rdf(Subject, Predicate, Object, Graph)` facts. `--to turtle`, `trig`,
|
|
295
|
+
`n-triples`, `n-quads`, `rdf-xml` or `json-ld` writes the conclusions back;
|
|
296
|
+
Turtle, N-Triples and RDF/XML refuse named graphs, which they cannot hold,
|
|
297
|
+
and JSON-LD refuses triple terms. JSON-LD follows the JSON-LD 1.2 draft of
|
|
298
|
+
the Processing Algorithms and API, in the processing mode `json-ld-1.2`, or
|
|
299
|
+
`json-ld-1.1` or `json-ld-1.0` through `parseRdf` of `eyemind/rdf`, which also
|
|
300
|
+
takes `expandContext`, `rdfDirection` and `produceGeneralizedRdf`; a JSON-LD
|
|
301
|
+
context that is not in the document is read from its file, or fetched as
|
|
302
|
+
Notation3 documents are. JSON-LD keeps a base direction only with its
|
|
303
|
+
`rdfDirection` option, as the specification has it. `writeRdf` writes
|
|
304
|
+
expanded JSON-LD, with the `useNativeTypes`, `useRdfType` and
|
|
305
|
+
`rdfDirection` options.
|
|
295
306
|
|
|
296
307
|
| RDF 1.2 | eyemind term |
|
|
297
308
|
| --- | --- |
|
|
@@ -302,7 +313,8 @@ as data: their quads become `rdf(Subject, Predicate, Object, Graph)` facts.
|
|
|
302
313
|
| Triple term | `triple(S, P, O)` |
|
|
303
314
|
| Default graph, named graph | `'default_graph'`, `iri(Name)` |
|
|
304
315
|
|
|
305
|
-
All
|
|
316
|
+
All 1262 W3C RDF 1.1 and 1.2 tests pass, RDF/XML included, and all 522
|
|
317
|
+
`toRdf` and `fromRdf` tests of the W3C JSON-LD API.
|
|
306
318
|
|
|
307
319
|
### Notation3
|
|
308
320
|
|
|
@@ -325,17 +337,16 @@ eyemind -c examples/family-n3.n3 # with a checked proof
|
|
|
325
337
|
### RDF Messages
|
|
326
338
|
|
|
327
339
|
eyemind reads [RDF Message](https://w3c-cg.github.io/rsp/spec/messages) logs
|
|
328
|
-
in
|
|
340
|
+
in Turtle, TriG, N-Triples, N-Quads, RDF/XML, where an `rdfm:MessageLog`
|
|
341
|
+
holds one `rdf:RDF` per message, and NDJSON-LD (`.ndjson`), a JSON object per
|
|
342
|
+
line; `writeRdfMessages` of `eyemind/messages` writes them. By default rules see the whole log replayed as
|
|
329
343
|
ordered envelopes in the `eymsg:` vocabulary, with proofs;
|
|
330
344
|
`--stream-messages` instead runs the rules once per message, reading files,
|
|
331
345
|
standard input or HTTP(S) incrementally. See the
|
|
332
346
|
[message-boundaries](https://eyereasoner.github.io/eyemind/examples/deck/message-boundaries-n3)
|
|
333
347
|
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.
|
|
348
|
+
All 35 [RDF Messages tests](https://w3c-cg.github.io/rsp/spec/messages-tests)
|
|
349
|
+
pass, and every `npm test` runs them.
|
|
339
350
|
|
|
340
351
|
With an [RDF logic profile](#rdf-logic-profiles), `--stream-messages` treats
|
|
341
352
|
the other inputs as a background graph and writes, for each message, the
|
|
@@ -650,7 +661,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
650
661
|
|
|
651
662
|
| Option | Meaning |
|
|
652
663
|
| --- | --- |
|
|
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 `.
|
|
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) and `.ndjson` (NDJSON-LD message log) files RDF data, `.n3` Notation3, `.srl` a SPARQL 1.2 RL rule set and `.le` Logical English. |
|
|
654
665
|
| `-p`, `--proof` | Print the proof instead. |
|
|
655
666
|
| `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
|
|
656
667
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
@@ -663,7 +674,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
663
674
|
| `--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
675
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
665
676
|
| `--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. |
|
|
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. |
|
|
667
678
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
668
679
|
| `--program` | Print the program the inputs compile to. |
|
|
669
680
|
| `--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 +799,7 @@ Further entry points serve applications built on the formats and profiles:
|
|
|
788
799
|
| Import | Gives |
|
|
789
800
|
| --- | --- |
|
|
790
801
|
| `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 `
|
|
802
|
+
| `eyemind/messages` | `parseRdfMessages(text)`, `RdfMessageReader` and `writeRdfMessages(messages)`, for RDF Message logs |
|
|
792
803
|
| `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
804
|
| `eyemind/cli` | `main(argv, io)`, the command line itself, with `io` as in `eyemind/node` |
|
|
794
805
|
| `eyemind/qudt` | `unitConversion(from, to)` and `quantityKinds(unit)`, from the QUDT catalog of `--qudt` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.19",
|
|
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
|
@@ -12,9 +12,9 @@ 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
|
-
all compiled to LS.
|
|
15
|
+
Files are read by extension: .js as LS, .ttl, .trig, .nt, .nq, .rdf (RDF/XML),
|
|
16
|
+
.jsonld (JSON-LD) and .ndjson (NDJSON-LD log) as RDF 1.2 data, .n3 as Notation3,
|
|
17
|
+
.srl as SPARQL 1.2 RL and .le as Logical English, all compiled to LS.
|
|
18
18
|
-p, --proof Print a proof of the conclusions
|
|
19
19
|
-c, --prove-and-check Generate a proof and check it against the input program
|
|
20
20
|
--check-proof FILE Check a proof and print its answers and verdict (- for stdin)
|
|
@@ -28,8 +28,8 @@ all compiled to LS.
|
|
|
28
28
|
--max-depth N Bound backward recursion (default 1000000)
|
|
29
29
|
--max-iterations N Bound forward rounds per stratum (default 1000)
|
|
30
30
|
--max-inferences N Bound reasoning work (default 1000000)
|
|
31
|
-
--to FORMAT Write the conclusions as turtle, trig, n-triples,
|
|
32
|
-
|
|
31
|
+
--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
33
|
for SRL, ODRL or RDF logic profiles, eyemind otherwise or with --goal)
|
|
34
34
|
--all With RDF or N3 output, write the given data too
|
|
35
35
|
--program Print the program the inputs compile to
|
|
@@ -217,8 +217,8 @@ export function main(argv, io) {
|
|
|
217
217
|
// Hosts such as the playground already hold their inputs as text.
|
|
218
218
|
// Node supplies the incremental file/HTTP implementation instead.
|
|
219
219
|
const sources = files.map((name, index) => ({ name, index, text: readSource(name, io) }));
|
|
220
|
-
const logs = sources.filter(({ text }) => isRdfMessageLog(text));
|
|
221
|
-
if (!logs.length) throw new UsageError('--stream-messages needs an RDF Message Log
|
|
220
|
+
const logs = sources.filter(({ name, text }) => rdfMessageFormat(name) === 'ndjson-ld' || isRdfMessageLog(text));
|
|
221
|
+
if (!logs.length) throw new UsageError('--stream-messages needs an RDF Message Log: VERSION "*-messages", an rdfm:MessageLog in RDF/XML, or NDJSON-LD (.ndjson)');
|
|
222
222
|
const inputs = sources.filter((source) => !logs.includes(source)).map(({ name, text }) => [name, text]);
|
|
223
223
|
for (const { name, text, index } of logs) {
|
|
224
224
|
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) and NDJSON-LD logs (.ndjson): with a
|
|
9
|
+
// program, rdf(S, P, O, G) facts; with an N3
|
|
10
|
+
// 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
|
|
@@ -32,7 +34,7 @@ import { compileLe, writeLe } from './le.js';
|
|
|
32
34
|
import { write } from './writer.js';
|
|
33
35
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
34
36
|
|
|
35
|
-
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3', 'le'];
|
|
37
|
+
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'rdf-xml', 'json-ld', 'n3', 'le'];
|
|
36
38
|
export { RDF_PROFILES };
|
|
37
39
|
|
|
38
40
|
// What a file holds: 'js', 'rdf', 'n3', 'srl' or 'le'.
|
|
@@ -98,6 +100,16 @@ function outputContract(text, name, io) {
|
|
|
98
100
|
});
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
// The remote contexts of a JSON-LD input: a file: IRI is read as a file, an
|
|
104
|
+
// HTTP(S) one as the documents of N3 are.
|
|
105
|
+
function documentLoader(io) {
|
|
106
|
+
return (url) => {
|
|
107
|
+
if (url.startsWith('file:') && io?.readFile) return { document: io.readFile(decodeURIComponent(new URL(url).pathname)), documentUrl: url };
|
|
108
|
+
if (/^https?:/.test(url) && io?.readDocument) return { document: io.readDocument(url), documentUrl: url };
|
|
109
|
+
throw new EyemindError(`cannot read the context ${url}`);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
101
113
|
// The reasoner the logic profiles run each RDF Message with, given the
|
|
102
114
|
// background inputs as [text, name] pairs (rdf-logic.js).
|
|
103
115
|
export function loadMessageReasoner(inputs, io = null, options = {}) {
|
|
@@ -116,8 +128,8 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
116
128
|
(inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
|
|
117
129
|
const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
|
|
118
130
|
const rdf = (text, name, k) => messageInputs?.get(name) ??
|
|
119
|
-
(isRdfMessageLog(text) ? parseRdfMessages : parseRdf)(text, {
|
|
120
|
-
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k),
|
|
131
|
+
(rdfFormat(name) === 'ndjson-ld' || isRdfMessageLog(text) ? parseRdfMessages : parseRdf)(text, {
|
|
132
|
+
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k), loadDocument: documentLoader(io),
|
|
121
133
|
});
|
|
122
134
|
// These rule sets are added only when requested, never from vocabulary.
|
|
123
135
|
if (kinds.includes('le')) {
|
|
@@ -135,7 +147,7 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
135
147
|
if (odrl) checkOdrlInput(graph.quads);
|
|
136
148
|
const source = inputs.map(([, n]) => n).join(', ');
|
|
137
149
|
// 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;
|
|
150
|
+
const shapes = ([text, name]) => parseRdf(text, { format: rdfFormat(name) ?? 'turtle', base: baseOf(name), loadDocument: documentLoader(io) }).quads;
|
|
139
151
|
if (shaclOut) graph.wanted = [...graph.wanted ?? [], ...shaclOut.flatMap((input) => shaclOutPatterns(shapes(input), input[1]))];
|
|
140
152
|
graph.planned = Boolean(shaclIn || shaclOut);
|
|
141
153
|
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';
|