eyemind 0.8.45 → 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 +43 -10
- package/LS-SPEC.md +1 -1
- package/README.md +6 -3
- package/package.json +1 -1
- package/src/le-odrl.js +36 -5
- package/src/le.js +33 -8
- package/src/odrl.js +7 -4
- package/src/version.js +1 -1
package/LE-SPEC.md
CHANGED
|
@@ -317,6 +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) | 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. |
|
|
320
322
|
|
|
321
323
|
Their decks state the modeled assumptions and what the checked proofs establish.
|
|
322
324
|
Bounds and finite expression domains are explicit in the programs.
|
|
@@ -365,9 +367,30 @@ evaluation has conflictStrategy prohibit.
|
|
|
365
367
|
```
|
|
366
368
|
|
|
367
369
|
This directive must be the first sentence of one file. The remainder contains
|
|
368
|
-
|
|
369
|
-
compiler maps
|
|
370
|
-
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
|
|
371
394
|
[snapshot profile](https://eyereasoner.github.io/eyemind/#odrl-snapshots) applies
|
|
372
395
|
to Turtle and LE, including missing observations, unsupported policy features
|
|
373
396
|
and conflict strategies. Vocabulary by itself does not enable evaluation.
|
|
@@ -419,14 +442,24 @@ use `has`; for example `issueAlice has decision allowed.`. Status values
|
|
|
419
442
|
`conflict` as a property means `eval:conflict`; `applicablePermission`,
|
|
420
443
|
`applicableProhibition`, `reportConstraint` and `reportDuty` distinguish the
|
|
421
444
|
report's `eval:permission`, `eval:prohibition`, `eval:constraint` and
|
|
422
|
-
`eval:duty` links from ODRL input properties. Other report fields retain their `eval:` names.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
445
|
+
`eval:duty` links from ODRL input properties. Other report fields retain their `eval:` names. Other IRIs
|
|
446
|
+
are written with the run's prefixes, declared after the directive: those the
|
|
447
|
+
file declares, `odrl:` and `eval:`. Inside a witness key, where a bare name
|
|
448
|
+
would read back as a name rather than an IRI, the snapshot namespace also
|
|
449
|
+
needs a prefix: the file's own, or `ns` when it declares none. An IRI that no
|
|
450
|
+
prefix abbreviates stays explicit.
|
|
451
|
+
|
|
452
|
+
Prefix declarations can follow either ODRL directive, and the whole snapshot
|
|
453
|
+
can be written with qualified names, as `ex:mayErase has odrl:action
|
|
454
|
+
odrl:delete.` or `ex:evaluation is a eval:Evaluation.`. After an ODRL
|
|
455
|
+
directive a qualified statement takes the subjects and values the short forms
|
|
456
|
+
take: an ordinary name in the declared namespace, `true` and `false`, and an
|
|
457
|
+
operand list, as `ex:scope has odrl:and [ex:purpose, ex:consent].`. A state
|
|
426
458
|
property or value can use a DPV IRI, for example
|
|
427
|
-
`
|
|
459
|
+
`state has dpv:hasPurpose dpv:AcademicResearch.`. An equality constraint
|
|
428
460
|
can read `dpv:hasPurpose` as its left operand and use
|
|
429
461
|
`dpv:AcademicResearch` as its right operand.
|
|
462
|
+
[Right to erasure example](https://eyereasoner.github.io/eyemind/examples/deck/right-to-erasure-le)
|
|
430
463
|
|
|
431
464
|
```text
|
|
432
465
|
scope is a logicalConstraint and scope has andOperands [purpose, dataCategory].
|
|
@@ -463,8 +496,8 @@ The research snapshot demonstrates compound scope, two DPV hierarchies and
|
|
|
463
496
|
request-local duty evidence; its Turtle twin, run with `--odrl`, reaches the
|
|
464
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)
|
|
465
498
|
|
|
466
|
-
Both ODRL directives take a single LE file and reject
|
|
467
|
-
|
|
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
|
|
468
501
|
`--odrl` switch selects the Turtle snapshot compiler, which can also combine
|
|
469
502
|
with `--owl2rl`, `--skos`, `--qudt` and `--shacl`; an LE run takes none of these
|
|
470
503
|
switches, so an LE snapshot reads only the facts it states.
|
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
|
+
168 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.
|
|
@@ -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
|
|
@@ -461,7 +464,7 @@ SKOS links between categories, such as a `skos:broadMatch` to DPV. Other
|
|
|
461
464
|
entailments, such as an `rdfs:Resource` type for every node, stay out of the
|
|
462
465
|
snapshot, whose validation would reject them. The output is the ODRL report
|
|
463
466
|
with the profiles' own reports, such as a SHACL validation report.
|
|
464
|
-
[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)
|
|
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)
|
|
465
468
|
|
|
466
469
|
## How eyemind reasons
|
|
467
470
|
|
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,15 +98,46 @@ 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;
|
|
109
|
-
if (head.name === 'rdf' && head.args.length === 3)
|
|
136
|
+
if (head.name === 'rdf' && head.args.length === 3) {
|
|
137
|
+
[s, p, o] = head.args;
|
|
138
|
+
s = rdfValue(s, namespace);
|
|
139
|
+
o = LIST_OPERANDS.has(p.args?.[0]) && properListItems(o) !== null ? o : rdfValue(o, namespace);
|
|
140
|
+
}
|
|
110
141
|
else if (head.args.length === 1) {
|
|
111
142
|
s = rdfValue(head.args[0], namespace); p = iri(RDF + 'type');
|
|
112
143
|
o = iri(TYPES.get(head.name) ?? namespace + head.name);
|
|
@@ -138,7 +169,7 @@ export function compileOdrlLe(statements, profile, source) {
|
|
|
138
169
|
writeRdf(quads, { format: 'n-triples' });
|
|
139
170
|
const prefixes = { '': namespace, odrl: ODRL, eval: ODRL_EVAL };
|
|
140
171
|
let loaded;
|
|
141
|
-
if (evaluate) loaded = compileOdrl({ quads, prefixes }, { source });
|
|
172
|
+
if (evaluate) loaded = compileOdrl({ quads, prefixes }, { source, rules });
|
|
142
173
|
else {
|
|
143
174
|
const facts = quads.map(([s, p, o]) => write(new Struct('rdf', [s, p, o]))).join('\n');
|
|
144
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
|
|
|
@@ -136,10 +136,16 @@ class Parser {
|
|
|
136
136
|
|
|
137
137
|
statement(name, subject, ...objects) {
|
|
138
138
|
if (typeof name === 'string') return st(name, subject, ...objects);
|
|
139
|
-
|
|
139
|
+
// After an ODRL directive, qualified statements take the names, true,
|
|
140
|
+
// false and operand lists the short forms take; le-odrl.js maps them.
|
|
141
|
+
const name_ = (term) => this.odrl && typeof term === 'string';
|
|
142
|
+
if (!rdfResource(subject) && !name_(subject)) this.error('a qualified RDF statement needs a resource subject such as ex:item, iri(...) or a variable');
|
|
140
143
|
if (!objects.length) return st('rdf', subject, st('iri', RDF_TYPE), name);
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
const [object] = objects, items = this.odrl ? listItems(object) : null;
|
|
145
|
+
if (!rdfValue(object) && !name_(object) && !(items?.length && items.every((item) => rdfValue(item) || name_(item)))) {
|
|
146
|
+
this.error('a qualified RDF property needs an RDF value such as a qualified name, number or literal(...)');
|
|
147
|
+
}
|
|
148
|
+
return st('rdf', subject, name, object);
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
declarations() {
|
|
@@ -386,6 +392,7 @@ class Parser {
|
|
|
386
392
|
if (this.take('snapshot')) { this.need('logic'); evaluate = true; }
|
|
387
393
|
else this.need('vocabulary');
|
|
388
394
|
const namespace = this.namespace('an ODRL');
|
|
395
|
+
this.odrl = true;
|
|
389
396
|
return { kind: 'odrl', namespace, evaluate, line };
|
|
390
397
|
}
|
|
391
398
|
if (this.take('every')) {
|
|
@@ -504,7 +511,23 @@ export function compileLe(inputs) {
|
|
|
504
511
|
for (const [prefix, namespace] of parser.prefixes) prefixes.set(prefix, namespace);
|
|
505
512
|
}
|
|
506
513
|
if (profile) {
|
|
507
|
-
|
|
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' : '');
|
|
508
531
|
return { ...loaded, prefixes: { ...loaded.prefixes, ...Object.fromEntries(prefixes) } };
|
|
509
532
|
}
|
|
510
533
|
// The helpers follow every stated clause, so a witness's rule number is
|
|
@@ -580,6 +603,8 @@ export function writeLe(result, { odrl = null, prefixes = {} } = {}) {
|
|
|
580
603
|
if (odrl) result = odrlLeReport(result, odrl.namespace);
|
|
581
604
|
// A prefix LE cannot spell, such as Turtle's empty one, gets the first free
|
|
582
605
|
// name of ns, ns2, ...; the output declares each prefix it uses.
|
|
606
|
+
// An ODRL report names its own namespace's resources bare where a name
|
|
607
|
+
// reads back as that IRI; inside a witness key a prefix keeps it an IRI.
|
|
583
608
|
const valid = Object.entries(prefixes).filter(([prefix, namespace]) => PREFIX.test(prefix) && typeof namespace === 'string');
|
|
584
609
|
const taken = new Set(valid.map(([prefix]) => prefix)), stated = new Set(valid.map(([, namespace]) => namespace));
|
|
585
610
|
for (const [prefix, namespace] of Object.entries(prefixes)) {
|
|
@@ -589,7 +614,7 @@ export function writeLe(result, { odrl = null, prefixes = {} } = {}) {
|
|
|
589
614
|
taken.add(name); stated.add(namespace);
|
|
590
615
|
valid.push([name, namespace]);
|
|
591
616
|
}
|
|
592
|
-
const namespaces =
|
|
617
|
+
const namespaces = valid.sort((a, b) => b[1].length - a[1].length);
|
|
593
618
|
const used = new Map();
|
|
594
619
|
const compact = (term) => {
|
|
595
620
|
if (!(term instanceof Struct) || term.name !== 'iri' || term.args.length !== 1 || typeof term.args[0] !== 'string') return null;
|
|
@@ -611,7 +636,7 @@ export function writeLe(result, { odrl = null, prefixes = {} } = {}) {
|
|
|
611
636
|
lines.push(quantifier + flattenConjunction(term).map((goal) => leGoal(goal, render, odrl !== null, compact)).join(' and ') + '.');
|
|
612
637
|
}
|
|
613
638
|
const declarations = [...used].sort().map(([prefix, namespace]) => `Use prefix ${prefix} with namespace ${JSON.stringify(namespace)}.`);
|
|
614
|
-
const header = odrl ? `Use ODRL vocabulary with namespace ${JSON.stringify(odrl.namespace)}.\n
|
|
615
|
-
|
|
639
|
+
const header = (odrl ? `Use ODRL vocabulary with namespace ${JSON.stringify(odrl.namespace)}.\n` : '') +
|
|
640
|
+
(declarations.length ? `${declarations.join('\n')}\n` : '') + (odrl || declarations.length ? '\n' : '');
|
|
616
641
|
return header + (lines.length ? lines.join('\n') + '\n' : '# No conclusions.\n');
|
|
617
642
|
}
|
package/src/odrl.js
CHANGED
|
@@ -18,17 +18,19 @@ export function isOdrlEvaluation(quads) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function checkOdrlInput(quads) {
|
|
21
|
-
if (!isOdrlEvaluation(quads)) throw new EyemindError('
|
|
21
|
+
if (!isOdrlEvaluation(quads)) throw new EyemindError('an ODRL snapshot needs an eval:Evaluation resource selecting the policies and requests');
|
|
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';
|