eyemind 0.8.51 → 0.9.0
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/LE-SPEC.md +236 -537
- package/LS-SPEC.md +1 -1
- package/README.md +72 -68
- package/package.json +1 -1
- package/src/formats.js +5 -7
- package/src/le.js +1139 -583
- package/src/version.js +1 -1
- package/src/le-odrl.js +0 -213
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
|
+
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,79 +192,83 @@ 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)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
|
219
|
+
`eyemind examples/socrates-le.le` prints the answers as sentences:
|
|
208
220
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
Template additions, constants, functions, ontologies with type checking,
|
|
257
|
+
unknowns, constraints, sections, included resources, LPS and s(CASP) belong to
|
|
258
|
+
Logical English 2 and are reported as unsupported. Every `npm test` scores the
|
|
259
|
+
[Logical English 2 examples](test/UPSTREAM.md) that state their expected
|
|
260
|
+
answers, as coverage: a wrong answer fails the run, a file that uses an
|
|
261
|
+
unsupported feature is counted as not passed.
|
|
260
262
|
|
|
261
263
|
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
|
-
[Pell equations](https://eyereasoner.github.io/eyemind/examples/deck/pell-equation-le),
|
|
265
264
|
[British citizenship](https://eyereasoner.github.io/eyemind/examples/deck/british-citizenship-le),
|
|
266
|
-
[
|
|
267
|
-
[
|
|
265
|
+
[GDPR breach notification](https://eyereasoner.github.io/eyemind/examples/deck/breach-notification-le),
|
|
266
|
+
[international data transfers](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le),
|
|
267
|
+
the [right to erasure](https://eyereasoner.github.io/eyemind/examples/deck/right-to-erasure-le),
|
|
268
|
+
[library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le),
|
|
269
|
+
an [election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le),
|
|
270
|
+
[shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le) or
|
|
271
|
+
[river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le).
|
|
268
272
|
|
|
269
273
|
### RDF 1.2
|
|
270
274
|
|
|
@@ -465,7 +469,7 @@ SKOS links between categories, such as a `skos:broadMatch` to DPV. Other
|
|
|
465
469
|
entailments, such as an `rdfs:Resource` type for every node, stay out of the
|
|
466
470
|
snapshot, whose validation would reject them. The output is the ODRL report
|
|
467
471
|
with the profiles' own reports, such as a SHACL validation report.
|
|
468
|
-
[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)
|
|
472
|
+
[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)
|
|
469
473
|
|
|
470
474
|
## How eyemind reasons
|
|
471
475
|
|
|
@@ -636,7 +640,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
636
640
|
| `--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. |
|
|
637
641
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
638
642
|
| `--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. |
|
|
639
|
-
| `--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. |
|
|
643
|
+
| `--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. |
|
|
640
644
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
641
645
|
| `--program` | Print the program the inputs compile to. |
|
|
642
646
|
| `--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`. |
|
|
@@ -754,7 +758,7 @@ console.log(result.bindings);
|
|
|
754
758
|
console.log(checkProof(socrates, result.proof, { goals }).valid);
|
|
755
759
|
```
|
|
756
760
|
|
|
757
|
-
`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
|
|
761
|
+
`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(loaded.program), loaded)` writes the answers as LE sentences, given the value `loaded` that `compileLe` returned.
|
|
758
762
|
|
|
759
763
|
Further entry points serve applications built on the formats and profiles:
|
|
760
764
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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
|
@@ -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')
|
|
220
|
-
|
|
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
|
|
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
|
|