eyemind 0.9.19 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The Logic Script (LS) Language and Proof Format
5
- Version: eyemind 0.9.19
5
+ Version: eyemind 0.9.20
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/README.md CHANGED
@@ -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) 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
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, and all 522
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, 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
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
@@ -661,7 +666,7 @@ eyemind [OPTION ...] [FILE ...]
661
666
 
662
667
  | Option | Meaning |
663
668
  | --- | --- |
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. |
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. |
665
670
  | `-p`, `--proof` | Print the proof instead. |
666
671
  | `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
667
672
  | `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
@@ -674,7 +679,7 @@ eyemind [OPTION ...] [FILE ...]
674
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. |
675
680
  | `--stats` | Print reasoning statistics as JSON to standard error. |
676
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. |
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. |
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. |
678
683
  | `--all` | With RDF or N3 output, write the given data too. |
679
684
  | `--program` | Print the program the inputs compile to. |
680
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`. |
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
- const buffer = Buffer.from(text, 'utf8');
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.19",
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 { isRdfMessageLog, replayMessages, RdfMessageReader } from './messages.js';
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';
@@ -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) 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.
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
@@ -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(({ 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)');
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
@@ -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) and NDJSON-LD logs (.ndjson): with a
9
- // program, rdf(S, P, O, G) facts; with an N3
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
- (rdfFormat(name) === 'ndjson-ld' || isRdfMessageLog(text) ? parseRdfMessages : parseRdf)(text, {
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.