eyemind 0.8.52 → 0.9.1

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.8.52
5
+ Version: eyemind 0.9.1
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
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
- 168 runnable programs, each with a card deck and saved conclusions; all but
16
+ 163 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.
@@ -192,78 +192,84 @@ The file extension selects the format; proofs and check reports are always `.js`
192
192
 
193
193
  ### Logical English
194
194
 
195
- A `.le` file is Logical English (LE): sentences in a fixed English grammar,
196
- each ending in `.`, compiled deterministically to LS, as the
197
- [LE specification](https://eyereasoner.github.io/eyemind/LE-SPEC) defines. Unsupported prose is an
198
- error, never an approximate translation, and the conclusions are written back
199
- as sentences.
195
+ A `.le` file is [Logical English](https://github.com/LogicalContractsOrg/LogicalEnglish) (LE),
196
+ the controlled natural language of Robert Kowalski and his colleagues for
197
+ legal and business rules. eyemind reads the core that the original
198
+ implementation and Logical English 2 share and compiles it to LS, as the
199
+ [LE specification](https://eyereasoner.github.io/eyemind/LE-SPEC) describes.
200
+ A document declares its sentence patterns, states a knowledge base of facts
201
+ and rules, and asks queries, optionally in scenarios:
200
202
 
201
203
  ```text
202
- Socrates is a human.
203
- Every human is mortal.
204
- Find every X such that X is mortal.
204
+ the templates are:
205
+ *a thing* is human,
206
+ *a thing* is mortal.
207
+
208
+ the knowledge base socrates includes:
209
+
210
+ a person is mortal
211
+ if the person is human.
212
+
213
+ Socrates is human.
214
+
215
+ query mortal is:
216
+ which thing is mortal.
205
217
  ```
206
218
 
207
- `eyemind examples/socrates-le.le` prints `Socrates is a mortal.`
219
+ `eyemind examples/socrates-le.le` prints the answers as sentences:
208
220
 
209
- **Names.** Keywords are case-insensitive, names case-sensitive. A class or
210
- relation name starts with a lowercase letter; an individual is a name such as
211
- `Socrates` or a JSON-quoted `"René Descartes"`. A variable is a capital letter
212
- with optional digits (`X`, `Y1`) and must be declared in its sentence, which is
213
- its scope. Terms also include exact integers, floats (`1.0`, `1e3`), lists
214
- `[a, b]` and compounds `pair(A, B)`. `#` starts a comment.
221
+ ```text
222
+ % query mortal
223
+ Socrates is mortal.
224
+ ```
215
225
 
216
- | LE | LS |
217
- | --- | --- |
218
- | `T is a class`, `T is an class` | `class(T)` |
219
- | `T is a relation of U`, `T has relation U` | `relation(T, U)` |
220
- | `relation(T, U, ...)` | that goal |
221
- | `A and B` | a conjunction; on its own, facts |
222
- | `For every X, ...` | a universally quantified fact |
223
- | `Every A is B.` | `implies(A(X), B(X))` |
224
- | `For every X and Y, if ... then ...` | a forward rule |
225
- | `if A and B or C then ...`, `Every A or B is C.` | one rule per alternative; `and` binds more tightly |
226
- | `Y is the value of E` | `is(Y, E)`, with `+ - * /` and parentheses |
227
- | `X is greater than`, `less than`, `at least`, `at most`, `equal to`, `different from E` | `gt`, `lt`, `ge`, `le`, `eq`, `ne` |
228
- | `it is not known that S` | `not(S)`, with LS's stratified meaning |
229
- | `N is the number of X such that S` | a count of the distinct values of `X` |
230
- | `T is the sum`, `maximum`, `minimum of V for every X and V such that S` | a fold of `V` over the distinct combinations |
231
- | `then there exists Y such that ...` | a Skolem witness of the firing |
232
- | `Find every X such that ...`, `Find whether ...` | `query(...)` |
233
- | `It is impossible that ...`, `Contradiction.` | `contradiction(...)` |
234
-
235
- Arithmetic, absence tests and aggregates need their inputs from earlier
236
- premises; an aggregate's own variables stay inside it, and a conjunction in its
237
- condition is put in parentheses. Arithmetic follows LS: integers stay exact,
238
- division gives a float. An answer becomes a sentence such as `16 is a square of 4.`; a witness is written
239
- `witness(rule 4, Y, Alice)`, and conclusions read back as facts of another LE
240
- program. Several `.le` files form one program, without other input formats
241
- or RDF logic switches; `--to le` writes LS conclusions
242
- as LE, and proofs check the compiled LS, not the English-to-LS translation.
243
- There are no pronouns, disjunctive conclusions or implicit assumptions.
244
-
245
- A first sentence `Use ODRL snapshot logic with namespace "..."` turns a file of
246
- facts and rules into an [ODRL snapshot](#odrl-snapshots) evaluation, with LE names
247
- mapped to the `eval:` and `odrl:` vocabularies; see the
248
- [handicap-card LE deck](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card-le).
249
- The rules derive the snapshot's observations and duty evidence, and the
250
- evaluator decides; see the
251
- [data transfers deck](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le).
252
- Ordinary LE can declare RDF prefixes with `Use prefix dpv with namespace "https://w3id.org/dpv#".`
253
- Qualified classes, properties and values work in facts, rules and questions.
254
- The research access example combines ODRL rules with DPV purpose and consent
255
- data and checks three policy decisions. [Research access LE deck](https://eyereasoner.github.io/eyemind/examples/deck/research-access-le)
256
-
257
- `Use DPV hierarchy logic.` adds rules for matching purposes, data and
258
- personal data against the supplied SKOS taxonomy. ODRL snapshots can use the same
259
- hierarchy in category constraints. [Logical English specification](https://eyereasoner.github.io/eyemind/LE-SPEC#dpv-hierarchies)
226
+ **Templates and variables.** A template such as
227
+ `*a person* is born in *a place* on *a date*` is a relation whose name joins
228
+ its words (`is_born_in_on`); a sentence matches the template with the most
229
+ words. In a sentence, `a person` (or `an`, `some`, `each`, `which`) introduces
230
+ a variable and `the person` refers back to it; a definite phrase that refers to
231
+ nothing, such as `the UK`, is a name. `a person X` names the variable `X`, and a
232
+ capital letter with optional digits is a variable on its own. Numbers, dates
233
+ (`2021-10-09`), quoted text and lists (`[a, b]`) are values. `%` starts a comment.
234
+
235
+ **Conditions.** A rule is `conclusion if conditions.` Conditions join with
236
+ `and` and `or`; a deeper indentation binds tighter, and lines at one
237
+ indentation read from the top. `it is not the case that`,
238
+ `for all cases in which ... it is the case that ...` and the aggregates
239
+ `R is the sum of each X such that ...` (also `count`, `average`, `min`, `max`,
240
+ `list`) take the more deeply indented lines below them. Arithmetic uses
241
+ `=`, `<`, `>=`, `+`, `*`, `/` and the like, and built-in templates compare
242
+ dates (`is after`, `is before or equal to`), count days (`is N days after`) and
243
+ take list members (`is in`).
244
+
245
+ **Meaning.** Rules are backward LS rules, as in LE's Prolog target: aggregates
246
+ count every solution they find, and a negation whose variable no condition has
247
+ bound succeeds when no instance holds. When a document has scenarios, every
248
+ relation takes the scenario as its first argument, so one program and one
249
+ proof answer every query in every scenario. A scenario can state the answers
250
+ it expects, `q expects answers ["..."].`; the output then notes any answer set
251
+ that differs. Proofs and check reports are `.js` and check the compiled LS; that
252
+ the program reads the English as intended is a matter of the compiler. Several
253
+ `.le` files form one document, without other input formats or RDF logic
254
+ switches.
255
+
256
+ Of Logical English 2, eyemind also reads constants, included files, rule labels,
257
+ `only if` rules and the template additions `synonym`, `opposite` and those that
258
+ change nothing it computes. Abduction (assumptions and constraints), functions,
259
+ type checking, embedded Prolog, LPS and s(CASP) are reported as unsupported. Every `npm test` scores the
260
+ [Logical English 2 examples](test/UPSTREAM.md) that state their expected
261
+ answers, as coverage: a wrong answer fails the run, a file that uses an
262
+ unsupported feature is counted as not passed.
260
263
 
261
264
  For larger programs, try
262
- [shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le),
263
- [river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le),
264
265
  [British citizenship](https://eyereasoner.github.io/eyemind/examples/deck/british-citizenship-le),
265
- [library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le) or an
266
- [election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le).
266
+ [GDPR breach notification](https://eyereasoner.github.io/eyemind/examples/deck/breach-notification-le),
267
+ [international data transfers](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le),
268
+ the [right to erasure](https://eyereasoner.github.io/eyemind/examples/deck/right-to-erasure-le),
269
+ [library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le),
270
+ an [election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le),
271
+ [shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le) or
272
+ [river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le).
267
273
 
268
274
  ### RDF 1.2
269
275
 
@@ -464,7 +470,7 @@ SKOS links between categories, such as a `skos:broadMatch` to DPV. Other
464
470
  entailments, such as an `rdfs:Resource` type for every node, stay out of the
465
471
  snapshot, whose validation would reject them. The output is the ODRL report
466
472
  with the profiles' own reports, such as a SHACL validation report.
467
- [Handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card) · [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-odrl) · [Research access with OWL 2 RL and SKOS](https://eyereasoner.github.io/eyemind/examples/deck/research-access-odrl) · [Research portal with OWL 2 RL](https://eyereasoner.github.io/eyemind/examples/deck/research-portal-odrl) · [Package holiday with SHACL](https://eyereasoner.github.io/eyemind/examples/deck/package-holiday-odrl) · [Right to erasure in qualified LE](https://eyereasoner.github.io/eyemind/examples/deck/right-to-erasure-le)
473
+ [Handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card) · [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-odrl) · [Research access with OWL 2 RL and SKOS](https://eyereasoner.github.io/eyemind/examples/deck/research-access-odrl) · [Research portal with OWL 2 RL](https://eyereasoner.github.io/eyemind/examples/deck/research-portal-odrl) · [Package holiday with SHACL](https://eyereasoner.github.io/eyemind/examples/deck/package-holiday-odrl)
468
474
 
469
475
  ## How eyemind reasons
470
476
 
@@ -635,7 +641,7 @@ eyemind [OPTION ...] [FILE ...]
635
641
  | `--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. |
636
642
  | `--stats` | Print reasoning statistics as JSON to standard error. |
637
643
  | `--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. |
638
- | `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3`, `le` or `eyemind`; `n3` only for an N3 run; by default LE for LE, N3 for N3, Turtle for SRL, ODRL and RDF profiles, eyemind otherwise. |
644
+ | `--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. |
639
645
  | `--all` | With RDF or N3 output, write the given data too. |
640
646
  | `--program` | Print the program the inputs compile to. |
641
647
  | `--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`. |
@@ -753,7 +759,7 @@ console.log(result.bindings);
753
759
  console.log(checkProof(socrates, result.proof, { goals }).valid);
754
760
  ```
755
761
 
756
- `run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `compileLe([[text, filename], ...])` returns the compiled LS `program` and standalone JavaScript `text`; `writeLe(run(program))` writes its conclusions as LE.
762
+ `run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `compileLe([[text, filename], ...], io)` returns the compiled LS `program` and standalone JavaScript `text`, reading included files with `io.readFile` when given; `writeLe(run(loaded.program), loaded)` writes the answers as LE sentences, given the value `loaded` that `compileLe` returned.
757
763
 
758
764
  Further entry points serve applications built on the formats and profiles:
759
765
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.8.52",
3
+ "version": "0.9.1",
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/formats.js CHANGED
@@ -124,7 +124,7 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
124
124
  if (kinds.some((kind) => kind !== 'le') || odrl || profiles.length) {
125
125
  throw new EyemindError('a Logical English run takes .le files without RDF logic switches or other input formats');
126
126
  }
127
- return compileLe(inputs);
127
+ return compileLe(inputs, io);
128
128
  }
129
129
  if (profiles.length && odrl) {
130
130
  if (inputs.length !== 1) throw new EyemindError(`--odrl with ${switches} takes one Turtle snapshot containing policies, requests and SOTW`);
@@ -216,19 +216,17 @@ export const defaultFormat = (kind) => RDF_PROFILES.includes(kind) ? 'turtle' :
216
216
  // all also writes given RDF or N3 data. Rejects conclusions the format cannot represent.
217
217
  export function writeConclusions(loaded, result, { format, all = false, blankNodePrefix = '' } = {}) {
218
218
  if (format === 'eyemind') return null;
219
- if (format === 'le') return writeLe(result, { odrl: loaded.compiled?.odrl ?? null,
220
- prefixes: loaded.prefixes instanceof Map ? Object.fromEntries(loaded.prefixes) : loaded.prefixes ?? {} });
219
+ if (format === 'le') {
220
+ if (loaded.kind !== 'le') throw new EyemindError('--to le writes the answers of a Logical English run');
221
+ return writeLe(result, loaded);
222
+ }
221
223
  if (format === 'n3') {
222
224
  if (loaded.kind !== 'n3') throw new EyemindError('--to n3 writes the conclusions of an N3 run');
223
225
  return resultToN3(loaded.compiled.doc, result, { mode: all ? 'all' : 'new', blankNodePrefix }).n3;
224
226
  }
225
227
  let quads;
226
228
  if (loaded.kind === 'srl') quads = srlQuads(loaded.compiled, srlAnswers(result), { all });
227
- else if (all && loaded.kind === 'le' && !loaded.compiled?.odrl) {
228
- const facts = loaded.program.sources.filter(({ kind, head }) => kind === 'fact' &&
229
- head instanceof Struct && head.name === 'rdf' && (head.args.length === 3 || head.args.length === 4));
230
- quads = conclusionQuads(result.answers, null, facts.map(({ head }) => head));
231
- } else quads = conclusionQuads(result.answers, all ? loaded.text : null);
229
+ else quads = conclusionQuads(result.answers, all ? loaded.text : null);
232
230
  return writeRdf(quads, { format, prefixes: loaded.kind === 'n3' ? Object.fromEntries(loaded.prefixes) : loaded.prefixes, blankNodePrefix });
233
231
  }
234
232