eyemind 0.8.46 → 0.8.47
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 +28 -7
- package/LS-SPEC.md +1 -1
- package/README.md +4 -1
- package/package.json +1 -1
- package/src/le-odrl.js +31 -4
- package/src/le.js +18 -2
- package/src/odrl.js +6 -3
- package/src/version.js +1 -1
package/LE-SPEC.md
CHANGED
|
@@ -317,8 +317,8 @@ These programs use the grammar above without additional syntax:
|
|
|
317
317
|
| [British citizenship](https://eyereasoner.github.io/eyemind/examples/deck/british-citizenship-le) | Section 1 of the British Nationality Act 1981: alternative premises, a presumption that holds unless the contrary is shown, date comparisons and citizenship through a derived parent. |
|
|
318
318
|
| [Library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le) | Charges from alternative rules, then the sum, number and maximum per member over distinct combinations. |
|
|
319
319
|
| [Election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le) | Eligibility by alternatives, distinct choices, an absence test inside a count, winners by maximum with ties, and a quorum. |
|
|
320
|
-
| [International data transfers](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le) | GDPR Chapter V over
|
|
321
|
-
| [Breach notification](https://eyereasoner.github.io/eyemind/examples/deck/breach-notification-le) | GDPR Articles 33 and 34
|
|
320
|
+
| [International data transfers](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le) | An ODRL snapshot with rules: GDPR Chapter V observations derived with alternative premises and absence tests over DPV, location and GDPR-extension names, decided by one permission per basis and a prohibition that wins. |
|
|
321
|
+
| [Breach notification](https://eyereasoner.github.io/eyemind/examples/deck/breach-notification-le) | An ODRL snapshot with rules: GDPR Articles 33 and 34 as permissions and prohibitions, with requests, observations and a processor's duty evidence derived from breach records by comparisons over hours. |
|
|
322
322
|
|
|
323
323
|
Their decks state the modeled assumptions and what the checked proofs establish.
|
|
324
324
|
Bounds and finite expression domains are explicit in the programs.
|
|
@@ -367,9 +367,30 @@ evaluation has conflictStrategy prohibit.
|
|
|
367
367
|
```
|
|
368
368
|
|
|
369
369
|
This directive must be the first sentence of one file. The remainder contains
|
|
370
|
-
|
|
371
|
-
compiler maps
|
|
372
|
-
reporting LS of `src/odrl.js`.
|
|
370
|
+
facts using the snapshot vocabulary, and rules, but no questions: the report
|
|
371
|
+
is the answer. The compiler maps the facts to RDF and includes the
|
|
372
|
+
validation, evaluation and reporting LS of `src/odrl.js`.
|
|
373
|
+
|
|
374
|
+
A snapshot's rules derive more of its input: their class and property
|
|
375
|
+
statements, in premises and conclusions, are statements of the snapshot's
|
|
376
|
+
RDF graph, with names mapped as for facts. A rule typically derives a state's
|
|
377
|
+
observations or a request's duty evidence from other facts, so the
|
|
378
|
+
evaluator decides on what the rules establish:
|
|
379
|
+
|
|
380
|
+
```text
|
|
381
|
+
For every S and P,
|
|
382
|
+
if S is a state and S has subject P and P has registeredIn civicDistrict
|
|
383
|
+
then S has residenceVerified true.
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Calculations, comparisons, absence tests and aggregates work as in ordinary
|
|
387
|
+
LE; an absence test asks whether the graph, with the rules' conclusions,
|
|
388
|
+
holds a statement. The rules precede the evaluator's own clauses, so they
|
|
389
|
+
cannot read its report, and a snapshot without rules compiles to the same
|
|
390
|
+
program as before. The evaluator validates what the rules derive as it
|
|
391
|
+
validates stated facts: a request or state still has one type, for
|
|
392
|
+
example. Derive an observation as both `true` and `false` where it matters,
|
|
393
|
+
since a missing observation leaves a constraint unknown. The same
|
|
373
394
|
[snapshot profile](https://eyereasoner.github.io/eyemind/#odrl-snapshots) applies
|
|
374
395
|
to Turtle and LE, including missing observations, unsupported policy features
|
|
375
396
|
and conflict strategies. Vocabulary by itself does not enable evaluation.
|
|
@@ -475,8 +496,8 @@ The research snapshot demonstrates compound scope, two DPV hierarchies and
|
|
|
475
496
|
request-local duty evidence; its Turtle twin, run with `--odrl`, reaches the
|
|
476
497
|
same decisions. [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le) · [Turtle twin](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-odrl)
|
|
477
498
|
|
|
478
|
-
Both ODRL directives take a single LE file and reject
|
|
479
|
-
|
|
499
|
+
Both ODRL directives take a single LE file and reject questions; the
|
|
500
|
+
vocabulary directive also rejects rules. `--goal` can query their compiled LS program. The
|
|
480
501
|
`--odrl` switch selects the Turtle snapshot compiler, which can also combine
|
|
481
502
|
with `--owl2rl`, `--skos`, `--qudt` and `--shacl`; an LE run takes none of these
|
|
482
503
|
switches, so an LE snapshot reads only the facts it states.
|
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -243,9 +243,12 @@ as LE, and proofs check the compiled LS, not the English-to-LS translation.
|
|
|
243
243
|
There are no pronouns, disjunctive conclusions or implicit assumptions.
|
|
244
244
|
|
|
245
245
|
A first sentence `Use ODRL snapshot logic with namespace "..."` turns a file of
|
|
246
|
-
|
|
246
|
+
facts and rules into an [ODRL snapshot](#odrl-snapshots) evaluation, with LE names
|
|
247
247
|
mapped to the `eval:` and `odrl:` vocabularies; see the
|
|
248
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).
|
|
249
252
|
Ordinary LE can declare RDF prefixes with `Use prefix dpv with namespace "https://w3id.org/dpv#".`
|
|
250
253
|
Qualified classes, properties and values work in facts, rules and questions.
|
|
251
254
|
The research access example combines ODRL rules with DPV purpose and consent
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.47",
|
|
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/le-odrl.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { compileOdrl, ODRL_EVAL } from './odrl.js';
|
|
4
4
|
import { loadText } from './lang.js';
|
|
5
5
|
import { DEFAULT_GRAPH, writeRdf } from './rdf.js';
|
|
6
|
-
import { EyemindError, Struct, isGround, properListItems } from './terms.js';
|
|
6
|
+
import { EyemindError, Struct, Var, conjunction, flattenConjunction, isGround, properListItems } from './terms.js';
|
|
7
7
|
import { readTerm } from './reader.js';
|
|
8
8
|
import { write } from './writer.js';
|
|
9
9
|
|
|
@@ -98,11 +98,38 @@ function expandOperandLists(quads, namespace) {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
// LS goals a snapshot rule keeps as they are: calculations, comparisons and
|
|
102
|
+
// the aggregation helpers of le.js.
|
|
103
|
+
const KEPT = new Set(['is', 'gt', 'lt', 'ge', 'le', 'eq', 'ne', 'le:distinct', 'le:count', 'le:sum', 'le:max', 'le:min']);
|
|
104
|
+
|
|
105
|
+
// A goal of a snapshot rule over the snapshot's input: class and property
|
|
106
|
+
// statements become odrl_input(S, P, O) with names mapped as for facts.
|
|
107
|
+
export function snapshotGoal(goal, namespace) {
|
|
108
|
+
const value = (term) => term instanceof Var ? term : rdfValue(term, namespace);
|
|
109
|
+
if (goal === 'true') return goal;
|
|
110
|
+
if (!(goal instanceof Struct)) throw new EyemindError('an LE ODRL rule needs class and property statements, calculations and absence tests');
|
|
111
|
+
if (goal.name === 'not' && goal.args.length === 1) return new Struct('not', [snapshotGoal(goal.args[0], namespace)]);
|
|
112
|
+
if (goal.name === 'findall_sorted') {
|
|
113
|
+
const [template, condition, result] = goal.args;
|
|
114
|
+
return new Struct('findall_sorted', [template, conjunction(flattenConjunction(condition).map((g) => snapshotGoal(g, namespace))), result]);
|
|
115
|
+
}
|
|
116
|
+
if (KEPT.has(goal.name)) return goal;
|
|
117
|
+
let s, p, o;
|
|
118
|
+
if (goal.name === 'rdf' && goal.args.length === 3) [s, p, o] = goal.args;
|
|
119
|
+
else if (goal.args.length === 1) [s, p, o] = [goal.args[0], iri(RDF + 'type'), iri(TYPES.get(goal.name) ?? namespace + goal.name)];
|
|
120
|
+
else if (goal.args.length === 2) [s, p, o] = [goal.args[0], iri(PROPERTIES.get(goal.name) ?? namespace + goal.name), goal.args[1]];
|
|
121
|
+
else throw new EyemindError('use class statements, binary properties or rdf(S, P, O) in LE ODRL rules');
|
|
122
|
+
return new Struct('odrl_input', [value(s), p, LIST_OPERANDS.has(p.args?.[0]) && properListItems(o) !== null ? o : value(o)]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// statements: the snapshot's facts; rules: the LS text of its rules, which
|
|
126
|
+
// only a snapshot, not a vocabulary document, may have.
|
|
127
|
+
export function compileOdrlLe(statements, profile, source, rules = '') {
|
|
102
128
|
const { namespace, evaluate } = profile;
|
|
103
129
|
const quads = [];
|
|
130
|
+
if (rules && !evaluate) throw new EyemindError(`${source}: an LE ODRL vocabulary document contains ground facts, not rules`);
|
|
104
131
|
for (const statement of statements) {
|
|
105
|
-
if (statement.kind !== 'fact') throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL snapshot
|
|
132
|
+
if (statement.kind !== 'fact') throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL snapshot has facts and rules, not questions; its report is the answer`);
|
|
106
133
|
for (const head of statement.heads) {
|
|
107
134
|
if (!(head instanceof Struct) || !isGround(head)) throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL fact needs a ground class or property statement`);
|
|
108
135
|
let s, p, o;
|
|
@@ -142,7 +169,7 @@ export function compileOdrlLe(statements, profile, source) {
|
|
|
142
169
|
writeRdf(quads, { format: 'n-triples' });
|
|
143
170
|
const prefixes = { '': namespace, odrl: ODRL, eval: ODRL_EVAL };
|
|
144
171
|
let loaded;
|
|
145
|
-
if (evaluate) loaded = compileOdrl({ quads, prefixes }, { source });
|
|
172
|
+
if (evaluate) loaded = compileOdrl({ quads, prefixes }, { source, rules });
|
|
146
173
|
else {
|
|
147
174
|
const facts = quads.map(([s, p, o]) => write(new Struct('rdf', [s, p, o]))).join('\n');
|
|
148
175
|
const text = `// RDF facts from an LE ODRL vocabulary document.\nfacts_from({ text: ${JSON.stringify(facts)} })\n`;
|
package/src/le.js
CHANGED
|
@@ -5,7 +5,7 @@ import { CONTROL_KEYS, Program, RESERVED_KEYS, Source } from './program.js';
|
|
|
5
5
|
import { readTerm } from './reader.js';
|
|
6
6
|
import { EMPTY, EyemindError, Struct, Var, conjunction, flattenConjunction } from './terms.js';
|
|
7
7
|
import { write } from './writer.js';
|
|
8
|
-
import { compileOdrlLe, odrlLeReport } from './le-odrl.js';
|
|
8
|
+
import { compileOdrlLe, odrlLeReport, snapshotGoal } from './le-odrl.js';
|
|
9
9
|
import { dpvRules } from './dpv.js';
|
|
10
10
|
import { loadText } from './lang.js';
|
|
11
11
|
|
|
@@ -511,7 +511,23 @@ export function compileLe(inputs) {
|
|
|
511
511
|
for (const [prefix, namespace] of parser.prefixes) prefixes.set(prefix, namespace);
|
|
512
512
|
}
|
|
513
513
|
if (profile) {
|
|
514
|
-
|
|
514
|
+
// A snapshot's rules derive input triples for its evaluation, with the
|
|
515
|
+
// aggregation helpers they use; its facts remain RDF data.
|
|
516
|
+
const map = (goal) => snapshotGoal(goal, profile.namespace);
|
|
517
|
+
const rules = [];
|
|
518
|
+
for (const { kind, heads, body, line, file } of statements.filter((s) => s.kind === 'forward' || s.kind === 'contradiction')) {
|
|
519
|
+
rules.push(`// ${String(file).replace(/[\r\n\u2028\u2029]/g, ' ')}: line ${line}`);
|
|
520
|
+
rules.push(kind === 'forward' ? `implies(${javascript(conjunction(body.map(map)))}, ${javascript(conjunction(heads.map(map)))})`
|
|
521
|
+
: `contradiction(${body.map(map).map(javascript).join(', ')})`);
|
|
522
|
+
}
|
|
523
|
+
for (const name of Object.keys(HELPERS).filter((key) => helpers.has(key))) {
|
|
524
|
+
for (const make of HELPERS[name]) {
|
|
525
|
+
const [head, body] = make();
|
|
526
|
+
rules.push(`implied_by(${javascript(head)}, ${body.length ? javascript(conjunction(body)) : "'true'"})`);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
const loaded = compileOdrlLe(statements.filter((s) => s.kind !== 'forward' && s.kind !== 'contradiction'), profile, inputs[0][1],
|
|
530
|
+
rules.length ? rules.join('\n') + '\n' : '');
|
|
515
531
|
return { ...loaded, prefixes: { ...loaded.prefixes, ...Object.fromEntries(prefixes) } };
|
|
516
532
|
}
|
|
517
533
|
// The helpers follow every stated clause, so a witness's rule number is
|
package/src/odrl.js
CHANGED
|
@@ -22,13 +22,15 @@ export function checkOdrlInput(quads) {
|
|
|
22
22
|
if (quads.some(([, , , graph]) => graph !== DEFAULT_GRAPH)) throw new EyemindError('an ODRL snapshot needs one default graph');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
// rules: LS clauses that derive further odrl_input triples, as an LE
|
|
26
|
+
// snapshot's own rules; they precede the snapshot's clauses.
|
|
27
|
+
export function compileOdrl({ quads, prefixes }, { source = '<input>', rules = '' } = {}) {
|
|
26
28
|
checkOdrlInput(quads);
|
|
27
29
|
// RDF graphs are sets; repeated statements must not violate cardinalities.
|
|
28
30
|
const facts = [...new Set(quads.map(([s, p, o]) => write(new Struct('odrl_input', [s, p, o]))))].join('\n');
|
|
29
31
|
const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, an ODRL snapshot.\n` +
|
|
30
32
|
'// Input triples are odrl_input(S, P, O); report triples are rdf(S, P, O).\n' +
|
|
31
|
-
`facts_from({ text: ${JSON.stringify(facts)} })\n${RULES}`;
|
|
33
|
+
`facts_from({ text: ${JSON.stringify(facts)} })\n${rules}${RULES}`;
|
|
32
34
|
return { kind: 'odrl', text, program: loadText(text, source), prefixes: { ...prefixes, eval: ODRL_EVAL }, compiled: null };
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -342,7 +344,8 @@ implies(odrl_rule_condition(E, Q, R, C, 'unknown', Why, Left), [
|
|
|
342
344
|
rdf(Issue, e('property'), Left), rdf(Issue, e('reason'), Why),
|
|
343
345
|
]);
|
|
344
346
|
implies(odrl_unmet_duty(E, Q, R, D), rdf(Q, e('unmetDuty'), D));
|
|
345
|
-
|
|
347
|
+
// Missing duty evidence matters only to a rule its constraints do not fail.
|
|
348
|
+
implies([odrl_unknown_duty(E, Q, R, D, Why), not(odrl_failed(E, Q, R))], [
|
|
346
349
|
rdf(Q, e('uncertainty'), Issue), rdf(Issue, rdfType, e('Uncertainty')),
|
|
347
350
|
rdf(Issue, e('duty'), D), rdf(Issue, e('rule'), R), rdf(Issue, e('reason'), Why),
|
|
348
351
|
]);
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.8.
|
|
2
|
+
export const VERSION = '0.8.47';
|