eyemind 0.6.4 → 0.6.5
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/README.md +80 -6
- package/SPEC.md +1 -1
- package/package.json +1 -1
- package/src/cli.js +7 -2
- package/src/formats.js +14 -4
- package/src/odrl.js +252 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ eyemind is a dependency-free reasoner for **Logic Script (LS)**, a rule language
|
|
|
7
7
|
|
|
8
8
|
[Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
|
|
9
9
|
|
|
10
|
-
The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and how a proof is checked. The examples are
|
|
10
|
+
The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and how a proof is checked. The examples are 136 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1246 cases that test language and proof behavior through a command adapter, together with implementation interface checks; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
11
11
|
|
|
12
12
|
## Contents
|
|
13
13
|
|
|
@@ -22,6 +22,7 @@ The playground runs programs in your browser; the specification defines the lang
|
|
|
22
22
|
- [Notation3](#notation3)
|
|
23
23
|
- [RDF Messages](#rdf-messages)
|
|
24
24
|
- [SPARQL 1.2 RL](#sparql-12-rl)
|
|
25
|
+
- [ODRL snapshots](#odrl-snapshots)
|
|
25
26
|
- [How eyemind reasons](#how-eyemind-reasons)
|
|
26
27
|
- [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
|
|
27
28
|
- [JSON check reports](#json-check-reports)
|
|
@@ -349,7 +350,7 @@ eyemind --all rules.srl facts.ttl # the base graph too
|
|
|
349
350
|
eyemind -c rules.srl facts.ttl # a proof of it, checked
|
|
350
351
|
```
|
|
351
352
|
|
|
352
|
-
Triples are `rdf(Subject, Predicate, Object)`, with `base/3` marking the base graph and `inf/3` the inference graph. A rule becomes `implies`, `NOT` becomes `not` of a helper, `GROUP` becomes `findall_sorted`, which leaves aggregates independent of derivation order, a blank node in a rule head becomes the Skolem term of its firing, and a SPARQL error is a goal that fails, so `FILTER` rejects the solution and `SET` drops it. The W3C SPARQL 1.2 RL test suite runs in `npm test` from `.cache/w3c/sparql-rl`: all
|
|
353
|
+
Triples are `rdf(Subject, Predicate, Object)`, with `base/3` marking the base graph and `inf/3` the inference graph. A rule becomes `implies`, `NOT` becomes `not` of a helper, `GROUP` becomes `findall_sorted`, which leaves aggregates independent of derivation order, a blank node in a rule head becomes the Skolem term of its firing, and a SPARQL error is a goal that fails, so `FILTER` rejects the solution and `SET` drops it. The W3C SPARQL 1.2 RL test suite runs in `npm test` from `.cache/w3c/sparql-rl`: all 342 tests pass.
|
|
353
354
|
|
|
354
355
|
SRL integers and decimals use exact integer arithmetic. Decimal addition,
|
|
355
356
|
subtraction, multiplication, comparison, rounding and terminating division
|
|
@@ -385,6 +386,78 @@ SRL programs for deployment dependencies, route distances, ancestry, inventory,
|
|
|
385
386
|
invoices, provenance and Unicode strings. Each has saved Turtle output, a
|
|
386
387
|
proof, a check report and a deck, and runs in the playground.
|
|
387
388
|
|
|
389
|
+
### ODRL snapshots
|
|
390
|
+
|
|
391
|
+
Use `--odrl` to add ODRL validation and evaluation to one Turtle file
|
|
392
|
+
containing policies, candidate requests and their state of the world (SOTW).
|
|
393
|
+
A resource of type `eval:Evaluation`, using
|
|
394
|
+
`eval: <https://eyereasoner.github.io/eyemind/odrl#>`, selects the policies
|
|
395
|
+
with `eval:policy`, the requests with `eval:request`, and a cross-policy
|
|
396
|
+
`eval:conflictStrategy`: `odrl:perm`, `odrl:prohibit` or `odrl:invalid`.
|
|
397
|
+
The switch enables the snapshot compiler; without it Turtle remains RDF
|
|
398
|
+
data, even when it contains an `eval:Evaluation` resource. The playground
|
|
399
|
+
has the same `--odrl` checkbox, enabled for the handicap-card example and
|
|
400
|
+
preserved in saved state and shared links.
|
|
401
|
+
|
|
402
|
+
```sh
|
|
403
|
+
eyemind --odrl examples/handicap-card.ttl > /tmp/handicap-card-report.ttl
|
|
404
|
+
eyemind --odrl --program examples/handicap-card.ttl > /tmp/handicap-card.js
|
|
405
|
+
eyemind --to turtle /tmp/handicap-card.js > /tmp/handicap-card-report.ttl
|
|
406
|
+
eyemind --odrl --proof examples/handicap-card.ttl > /tmp/handicap-card-proof.js
|
|
407
|
+
eyemind --odrl --check-proof /tmp/handicap-card-proof.js examples/handicap-card.ttl
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
The compiled `.js` includes the input facts and all validation and evaluation
|
|
411
|
+
LS; running it needs no policy file or external evaluator. The Turtle report
|
|
412
|
+
lists each request's `eval:decision` (`Allowed`, `Prohibited`,
|
|
413
|
+
`NotApplicable` or `Undetermined`), the `eval:canHappen` requests, validation
|
|
414
|
+
errors, uncertainties and conflicts. Each conflict identifies its request,
|
|
415
|
+
permission policy/rule and prohibition policy/rule. `eval:conflictCount`
|
|
416
|
+
explicitly records zero when none is detected. This evaluates the listed
|
|
417
|
+
requests at the supplied snapshot; it neither issues a card nor predicts
|
|
418
|
+
future changes to the world.
|
|
419
|
+
`eval:validationStatus` records whether the input fits the profile's shape
|
|
420
|
+
and vocabulary. Conflicts are reported and resolved separately.
|
|
421
|
+
|
|
422
|
+
The supported profile is declared on each policy with
|
|
423
|
+
`odrl:profile eval:SnapshotProfile`. Policies are `odrl:Set` or
|
|
424
|
+
`odrl:Agreement`; each rule states exactly one assignee, action and target.
|
|
425
|
+
A request is an `eval:Request` with those same three ODRL properties, an
|
|
426
|
+
`eval:subject` and an `eval:state`. Its `eval:State` names the same subject.
|
|
427
|
+
Assignees, actions and targets match by RDF term identity. Each constraint's
|
|
428
|
+
`odrl:leftOperand` is an IRI naming a property of that state, with exactly one
|
|
429
|
+
`odrl:operator` and `odrl:rightOperand`. All constraints of a rule must hold.
|
|
430
|
+
Equality and inequality (`eq`, `neq`) support IRIs, strings, booleans and
|
|
431
|
+
exact integers; ordering (`gt`, `gteq`, `lt`, `lteq`) supports exact integers.
|
|
432
|
+
Boolean lexical forms `true`/`1` and `false`/`0` denote the same values.
|
|
433
|
+
|
|
434
|
+
An absent, multiply valued, unsupported or differently typed observation
|
|
435
|
+
leaves a constraint unknown. A definitely false constraint makes its rule
|
|
436
|
+
inapplicable; otherwise an unknown constraint makes the request
|
|
437
|
+
`Undetermined`. Missing facts never establish a negative observation.
|
|
438
|
+
The caller supplies the applicable policy set, trusted state and candidate
|
|
439
|
+
actions. The compiler does not establish agreement acceptance or evidence
|
|
440
|
+
authenticity. Unsupported policy properties, profiles, duties, inheritance,
|
|
441
|
+
action hierarchies, collections and refinements are validation errors and
|
|
442
|
+
block authorization for the evaluation. This is a bounded profile, not a
|
|
443
|
+
general ODRL evaluator.
|
|
444
|
+
|
|
445
|
+
ODRL's per-policy `odrl:conflict` strategies are applied first; an omitted
|
|
446
|
+
strategy defaults to `odrl:invalid`. A detected internal conflict then voids
|
|
447
|
+
that policy and leaves the evaluation undetermined. The explicit
|
|
448
|
+
`eval:conflictStrategy` combines the remaining policy decisions; `invalid`
|
|
449
|
+
voids the evaluation if both a permission and a prohibition remain for any
|
|
450
|
+
request. Conflicts stay in the report after resolution. These are
|
|
451
|
+
permission/prohibition overlaps for the listed requests, not an exhaustive
|
|
452
|
+
search for conflicts in every possible state. The rules follow the
|
|
453
|
+
[ODRL Information Model](https://www.w3.org/TR/odrl-model/) for the supported
|
|
454
|
+
features; the snapshot vocabulary and cross-policy composition are this
|
|
455
|
+
profile's conventions.
|
|
456
|
+
|
|
457
|
+
The [handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card)
|
|
458
|
+
allows Alice's request and reports the conflict that blocks Bob's, under
|
|
459
|
+
explicitly fictional criteria.
|
|
460
|
+
|
|
388
461
|
## How eyemind reasons
|
|
389
462
|
|
|
390
463
|
The statement chooses the direction:
|
|
@@ -551,10 +624,11 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
551
624
|
| `--unused` | List the clauses that make no difference to the conclusions. |
|
|
552
625
|
| `--stream-messages` | Read an RDF Message Log and run the rules independently per message; Node reads files, stdin and HTTP(S) incrementally. |
|
|
553
626
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
554
|
-
| `--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 or
|
|
555
|
-
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3` or `eyemind`; by default N3 for N3, Turtle for SRL, eyemind otherwise. |
|
|
627
|
+
| `--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 or ODRL program has 1000000, 100000 and 1000000000. |
|
|
628
|
+
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3` or `eyemind`; by default N3 for N3, Turtle for SRL and ODRL, eyemind otherwise. |
|
|
556
629
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
557
630
|
| `--program` | Print the program the inputs compile to. |
|
|
631
|
+
| `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
|
|
558
632
|
| `--base IRI` | Resolve relative IRIs of the inputs against `IRI` instead of each file's location. |
|
|
559
633
|
| `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
|
|
560
634
|
|
|
@@ -564,7 +638,7 @@ each goal as a data document, with an array denoting conjunction. With
|
|
|
564
638
|
`--check-proof`, supply the original goals the proof answers.
|
|
565
639
|
An option that takes a value requires it immediately afterward; another
|
|
566
640
|
option, including a short alias such as `-v`, is reported as a missing value.
|
|
567
|
-
With `--goal`, answers default to eyemind terms even for N3 and
|
|
641
|
+
With `--goal`, answers default to eyemind terms even for N3, SRL and ODRL inputs;
|
|
568
642
|
use `--to` to request another output format.
|
|
569
643
|
|
|
570
644
|
With `--prove-and-check`, reasoning bounds and `--stats` apply to proof
|
|
@@ -593,7 +667,7 @@ They are outside the language and proof specification.
|
|
|
593
667
|
|
|
594
668
|
The JavaScript implementation defaults to a depth limit of 1000000, an
|
|
595
669
|
inference limit of 1000000 and a limit of 1000 forward rounds per stratum.
|
|
596
|
-
Compiled N3 and
|
|
670
|
+
Compiled N3, SRL and ODRL programs use 1000000, 1000000000 and 100000 respectively.
|
|
597
671
|
Each supplied bound must be a positive integer no greater than
|
|
598
672
|
9007199254740991.
|
|
599
673
|
|
package/SPEC.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3) and SPARQL 1.2 RL (SRL) interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/cli.js
CHANGED
|
@@ -24,9 +24,10 @@ Files are read by extension: .js as LS, .ttl, .trig, .nt and .nq as RDF 1.2 data
|
|
|
24
24
|
--max-inferences N Bound reasoning work (default 1000000)
|
|
25
25
|
--to FORMAT Write the conclusions as turtle, trig, n-triples,
|
|
26
26
|
n-quads, n3 or eyemind (default: n3 for N3, turtle
|
|
27
|
-
for
|
|
27
|
+
for SRL or ODRL, eyemind otherwise or with --goal)
|
|
28
28
|
--all With RDF or N3 output, write the given data too
|
|
29
29
|
--program Print the program the inputs compile to
|
|
30
|
+
--odrl Add ODRL validation and evaluation to one Turtle snapshot
|
|
30
31
|
--base IRI Resolve relative IRIs of the inputs against IRI
|
|
31
32
|
--stream-messages Run the rules independently for each RDF Message
|
|
32
33
|
-v, --version Print the version
|
|
@@ -65,6 +66,7 @@ export function main(argv, io) {
|
|
|
65
66
|
let printProgram = false;
|
|
66
67
|
let base = null;
|
|
67
68
|
let streamMessages = false;
|
|
69
|
+
let odrl = false;
|
|
68
70
|
const filePositions = new Set();
|
|
69
71
|
for (let i = 0; i < argv.length; i++) {
|
|
70
72
|
const arg = ALIASES.get(argv[i]) ?? argv[i];
|
|
@@ -90,6 +92,8 @@ export function main(argv, io) {
|
|
|
90
92
|
all = true;
|
|
91
93
|
} else if (arg === '--program') {
|
|
92
94
|
printProgram = true;
|
|
95
|
+
} else if (arg === '--odrl') {
|
|
96
|
+
odrl = true;
|
|
93
97
|
} else if (arg === '--stream-messages') {
|
|
94
98
|
streamMessages = true;
|
|
95
99
|
} else if (arg === '--check-proof' || arg === '--goal' || arg === '--to' || arg === '--base' || Object.hasOwn(LIMITS, arg)) {
|
|
@@ -137,6 +141,7 @@ export function main(argv, io) {
|
|
|
137
141
|
if (!files.length) files.push('-');
|
|
138
142
|
if (files.filter((file) => file === '-').length > 1) throw new UsageError('stdin can only be read once');
|
|
139
143
|
if (streamMessages) {
|
|
144
|
+
if (odrl) throw new UsageError('--odrl cannot be combined with --stream-messages');
|
|
140
145
|
if (proofFile !== null || options.proof || proveAndCheck || printProgram || unused) {
|
|
141
146
|
throw new UsageError('--stream-messages cannot be combined with --proof, --check-proof, --prove-and-check, --program or --unused; replay the whole log to prove its conclusions');
|
|
142
147
|
}
|
|
@@ -177,7 +182,7 @@ export function main(argv, io) {
|
|
|
177
182
|
}
|
|
178
183
|
const document = proofFile === null ? null : readSource(proofFile, io);
|
|
179
184
|
const loaded = loadInputs(files.map((file) => [readSource(file, io), file === '-' ? '<stdin>' : file]), io,
|
|
180
|
-
{ base, messageInputs: io.messageInputs,
|
|
185
|
+
{ base, messageInputs: io.messageInputs, odrl,
|
|
181
186
|
srlContext: document !== null && files.some((file) => inputKind(file) === 'srl') ? srlContextFromProof(document) : null });
|
|
182
187
|
const program = loaded.program;
|
|
183
188
|
if (printProgram) {
|
package/src/formats.js
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
// .n3 Notation3, compiled to an LS program
|
|
12
12
|
// .srl a SPARQL 1.2 RL rule set, compiled to one
|
|
13
13
|
//
|
|
14
|
+
// The odrl option adds the snapshot profile's validation and evaluation LS
|
|
15
|
+
// to one Turtle input. Its vocabulary alone never enables the evaluator.
|
|
16
|
+
//
|
|
14
17
|
// The compiled program is ordinary LS: proofs, checking and --unused
|
|
15
18
|
// apply to it. SRL execution functions capture a context that a saved proof
|
|
16
19
|
// retains; compiling with that context reproduces the same program later.
|
|
@@ -20,6 +23,7 @@ import { readTerms } from './reader.js';
|
|
|
20
23
|
import { DEFAULT_GRAPH, parseRdf, rdfDocument, rdfFormat, writeRdf } from './rdf.js';
|
|
21
24
|
import { resultToN3, compileSources } from './n3.js';
|
|
22
25
|
import { compileSrl, srlAnswers, srlQuads } from './srl.js';
|
|
26
|
+
import { compileOdrl } from './odrl.js';
|
|
23
27
|
import { write } from './writer.js';
|
|
24
28
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
25
29
|
|
|
@@ -41,7 +45,7 @@ export function rdfMessageFormat(name) {
|
|
|
41
45
|
// Load inputs, given as [text, name] pairs, as one program. io may supply
|
|
42
46
|
// readFile, for the documents N3 and IMPORTS name, and fileIri(name), the
|
|
43
47
|
// base IRI of a file. Returns { kind, program, text, prefixes, compiled }:
|
|
44
|
-
// kind is 'js', 'n3' or '
|
|
48
|
+
// kind is 'js', 'n3', 'srl' or 'odrl', text the compiled program,
|
|
45
49
|
// and compiled what writing the conclusions needs.
|
|
46
50
|
export function loadInputs(inputs, io = null, options = {}) {
|
|
47
51
|
try {
|
|
@@ -53,7 +57,7 @@ export function loadInputs(inputs, io = null, options = {}) {
|
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
function load(inputs, io, { base = null, messageInputs = null, srlContext = null }) {
|
|
60
|
+
function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false }) {
|
|
57
61
|
const kinds = inputs.map(([text, name]) => messageInputs?.has(name) ||
|
|
58
62
|
(inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
|
|
59
63
|
const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
|
|
@@ -61,6 +65,12 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
61
65
|
(isRdfMessageLog(text) ? parseRdfMessages : parseRdf)(text, {
|
|
62
66
|
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k),
|
|
63
67
|
});
|
|
68
|
+
// ODRL logic is added only when requested, never from a document's terms.
|
|
69
|
+
if (odrl) {
|
|
70
|
+
if (inputs.length !== 1) throw new EyemindError('--odrl takes one Turtle snapshot containing policies, requests and SOTW');
|
|
71
|
+
const [text, name] = inputs[0];
|
|
72
|
+
return compileOdrl(parseRdf(text, { format: 'turtle', base: baseOf(name), scope: scopeOf(inputs, name, 0) }), { source: name });
|
|
73
|
+
}
|
|
64
74
|
if (kinds.includes('srl')) {
|
|
65
75
|
const others = kinds.filter((k) => k !== 'srl' && k !== 'rdf');
|
|
66
76
|
if (kinds.filter((k) => k === 'srl').length > 1 || others.length) {
|
|
@@ -118,9 +128,9 @@ function importResolver(io) {
|
|
|
118
128
|
};
|
|
119
129
|
}
|
|
120
130
|
|
|
121
|
-
// The default output format of a run: N3 for N3, Turtle for SRL, and
|
|
131
|
+
// The default output format of a run: N3 for N3, Turtle for SRL and ODRL, and
|
|
122
132
|
// eyemind's own text for a program.
|
|
123
|
-
export const defaultFormat = (kind) => ({ n3: 'n3', srl: 'turtle' })[kind] ?? 'eyemind';
|
|
133
|
+
export const defaultFormat = (kind) => ({ n3: 'n3', srl: 'turtle', odrl: 'turtle' })[kind] ?? 'eyemind';
|
|
124
134
|
|
|
125
135
|
// The conclusions of a run in an output format; null for eyemind's own text.
|
|
126
136
|
// all also writes the given data. Throws when a conclusion is no triple.
|
package/src/odrl.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// A bounded ODRL snapshot profile: one Turtle document supplies the policies,
|
|
2
|
+
// candidate requests and their state of the world. Both validation and
|
|
3
|
+
// evaluation are ordinary LS, included in the standalone compiled program.
|
|
4
|
+
// ODRL semantics: https://www.w3.org/TR/odrl-model/
|
|
5
|
+
import { EyemindError, Struct } from './terms.js';
|
|
6
|
+
import { DEFAULT_GRAPH } from './rdf.js';
|
|
7
|
+
import { loadText } from './lang.js';
|
|
8
|
+
import { write } from './writer.js';
|
|
9
|
+
|
|
10
|
+
export const ODRL_EVAL = 'https://eyereasoner.github.io/eyemind/odrl#';
|
|
11
|
+
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
12
|
+
|
|
13
|
+
export function isOdrlEvaluation(quads) {
|
|
14
|
+
return quads.some(([, predicate, object]) => predicate instanceof Struct && predicate.name === 'iri' &&
|
|
15
|
+
predicate.args[0] === `${RDF}type` && object instanceof Struct && object.name === 'iri' &&
|
|
16
|
+
object.args[0] === `${ODRL_EVAL}Evaluation`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function compileOdrl({ quads, prefixes }, { source = '<input>' } = {}) {
|
|
20
|
+
if (!isOdrlEvaluation(quads)) throw new EyemindError('--odrl needs an eval:Evaluation resource selecting the policies and requests');
|
|
21
|
+
if (quads.some(([, , , graph]) => graph !== DEFAULT_GRAPH)) throw new EyemindError('an ODRL snapshot needs one default graph');
|
|
22
|
+
// RDF graphs are sets; repeated statements must not violate cardinalities.
|
|
23
|
+
const facts = [...new Set(quads.map(([s, p, o]) => write(new Struct('odrl_input', [s, p, o]))))].join('\n');
|
|
24
|
+
const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, an ODRL snapshot.\n` +
|
|
25
|
+
'// Input triples are odrl_input(S, P, O); report triples are rdf(S, P, O).\n' +
|
|
26
|
+
`facts_from({ text: ${JSON.stringify(facts)} })\n${RULES}`;
|
|
27
|
+
return { kind: 'odrl', text, program: loadText(text, source), prefixes: { ...prefixes, eval: ODRL_EVAL }, compiled: null };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const RULES = String.raw`
|
|
31
|
+
// Validation: the supported snapshot profile. Unknown policy features fail
|
|
32
|
+
// validation, so they cannot disappear while a permission is being decided.
|
|
33
|
+
const odrlNS = 'http://www.w3.org/ns/odrl/2/';
|
|
34
|
+
const evalNS = 'https://eyereasoner.github.io/eyemind/odrl#';
|
|
35
|
+
const xsdNS = 'http://www.w3.org/2001/XMLSchema#';
|
|
36
|
+
const o = (name) => iri(odrlNS + name);
|
|
37
|
+
const e = (name) => iri(evalNS + name);
|
|
38
|
+
const rdfType = iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
|
|
39
|
+
|
|
40
|
+
implies(odrl_input(E, rdfType, e('Evaluation')), odrl_evaluation(E));
|
|
41
|
+
implies(odrl_evaluation(E), odrl_node(E, E, 'evaluation'));
|
|
42
|
+
implies([odrl_evaluation(E), odrl_input(E, e('policy'), P)], odrl_node(E, P, 'policy'));
|
|
43
|
+
implies([odrl_evaluation(E), odrl_input(E, e('request'), Q)], odrl_node(E, Q, 'request'));
|
|
44
|
+
implies([odrl_node(E, P, 'policy'), odrl_input(P, o('permission'), R)], odrl_rule(E, P, R, 'permission'));
|
|
45
|
+
implies([odrl_node(E, P, 'policy'), odrl_input(P, o('prohibition'), R)], odrl_rule(E, P, R, 'prohibition'));
|
|
46
|
+
implies(odrl_rule(E, P, R, K), odrl_node(E, R, K));
|
|
47
|
+
implies([odrl_rule(E, P, R, K), odrl_input(R, o('constraint'), C)], odrl_node(E, C, 'constraint'));
|
|
48
|
+
implies([odrl_node(E, Q, 'request'), odrl_input(Q, e('state'), S)], odrl_node(E, S, 'state'));
|
|
49
|
+
implies([odrl_rule(E, P, R, K), odrl_input(R, o('action'), A)], odrl_node(E, A, 'action'));
|
|
50
|
+
implies([odrl_node(E, Q, 'request'), odrl_input(Q, o('action'), A)], odrl_node(E, A, 'action'));
|
|
51
|
+
for (const name of ['assignee', 'target']) {
|
|
52
|
+
implies([odrl_rule(E, P, R, K), odrl_input(R, o(name), S)], odrl_entity(E, S));
|
|
53
|
+
implies([odrl_node(E, Q, 'request'), odrl_input(Q, o(name), S)], odrl_entity(E, S));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const [kind, predicate, min, max, valueKind] of [
|
|
57
|
+
['evaluation', rdfType, 1, 1, 'type'],
|
|
58
|
+
['evaluation', e('policy'), 1, -1, 'resource'],
|
|
59
|
+
['evaluation', e('request'), 1, -1, 'resource'],
|
|
60
|
+
['evaluation', e('conflictStrategy'), 1, 1, 'strategy'],
|
|
61
|
+
['policy', rdfType, 1, 1, 'type'],
|
|
62
|
+
['policy', o('profile'), 1, 1, 'profile'],
|
|
63
|
+
['policy', o('permission'), 0, -1, 'resource'],
|
|
64
|
+
['policy', o('prohibition'), 0, -1, 'resource'],
|
|
65
|
+
['policy', o('assigner'), 0, 1, 'resource'],
|
|
66
|
+
['policy', o('conflict'), 0, 1, 'strategy'],
|
|
67
|
+
['request', rdfType, 1, 1, 'type'],
|
|
68
|
+
['request', o('assignee'), 1, 1, 'resource'],
|
|
69
|
+
['request', o('action'), 1, 1, 'iri'],
|
|
70
|
+
['request', o('target'), 1, 1, 'resource'],
|
|
71
|
+
['request', e('subject'), 1, 1, 'resource'],
|
|
72
|
+
['request', e('state'), 1, 1, 'resource'],
|
|
73
|
+
['state', rdfType, 1, 1, 'type'],
|
|
74
|
+
['state', e('subject'), 1, 1, 'resource'],
|
|
75
|
+
['constraint', rdfType, 0, 1, 'type'],
|
|
76
|
+
['constraint', o('leftOperand'), 1, 1, 'iri'],
|
|
77
|
+
['constraint', o('operator'), 1, 1, 'operator'],
|
|
78
|
+
['constraint', o('rightOperand'), 1, 1, 'scalar'],
|
|
79
|
+
['action', rdfType, 0, 1, 'type'],
|
|
80
|
+
]) fact(odrl_field(kind, predicate, min, max, valueKind));
|
|
81
|
+
for (const kind of ['permission', 'prohibition']) {
|
|
82
|
+
fact(odrl_field(kind, rdfType, 0, 1, 'type'));
|
|
83
|
+
for (const name of ['assignee', 'action', 'target']) fact(odrl_field(kind, o(name), 1, 1, name === 'action' ? 'iri' : 'resource'));
|
|
84
|
+
fact(odrl_field(kind, o('assigner'), 0, 1, 'resource'), odrl_field(kind, o('constraint'), 0, -1, 'resource'));
|
|
85
|
+
}
|
|
86
|
+
for (const [kind, type] of [
|
|
87
|
+
['evaluation', e('Evaluation')], ['request', e('Request')], ['state', e('State')],
|
|
88
|
+
['policy', o('Set')], ['policy', o('Agreement')],
|
|
89
|
+
['permission', o('Permission')], ['prohibition', o('Prohibition')], ['constraint', o('Constraint')],
|
|
90
|
+
['action', o('Action')],
|
|
91
|
+
]) fact(odrl_type(kind, type));
|
|
92
|
+
for (const predicate of [
|
|
93
|
+
'http://www.w3.org/2000/01/rdf-schema#label', 'http://www.w3.org/2000/01/rdf-schema#comment',
|
|
94
|
+
'http://purl.org/dc/terms/title', 'http://purl.org/dc/terms/description',
|
|
95
|
+
]) fact(odrl_metadata(iri(predicate)));
|
|
96
|
+
for (const name of ['perm', 'prohibit', 'invalid']) fact(odrl_strategy_value(o(name)));
|
|
97
|
+
for (const name of ['eq', 'neq', 'gt', 'gteq', 'lt', 'lteq']) fact(odrl_operator(o(name)));
|
|
98
|
+
|
|
99
|
+
fact(odrl_count([], 0));
|
|
100
|
+
implied_by(odrl_count([_, ...T], N), [odrl_count(T, M), is(N, add(M, 1))]);
|
|
101
|
+
implied_by(odrl_resource(iri(V)), is_atom(V));
|
|
102
|
+
implied_by(odrl_resource(bnode(S, V)), [is_atom(S), is_atom(V)]);
|
|
103
|
+
implied_by(odrl_scalar(V, 'integer', V), is_int(V));
|
|
104
|
+
implied_by(odrl_scalar(iri(V), 'iri', V), is_atom(V));
|
|
105
|
+
implied_by(odrl_scalar(literal(V, datatype(xsdNS + 'string')), 'string', V), is_atom(V));
|
|
106
|
+
for (const [lexical, value] of [['true', 'true'], ['1', 'true'], ['false', 'false'], ['0', 'false']]) {
|
|
107
|
+
fact(odrl_scalar(literal(lexical, datatype(xsdNS + 'boolean')), 'boolean', value));
|
|
108
|
+
}
|
|
109
|
+
implied_by(odrl_value('resource', V), odrl_resource(V));
|
|
110
|
+
implied_by(odrl_value('iri', iri(V)), is_atom(V));
|
|
111
|
+
implied_by(odrl_value('type', iri(V)), is_atom(V));
|
|
112
|
+
implied_by(odrl_value('scalar', V), odrl_scalar(V, _, _));
|
|
113
|
+
implied_by(odrl_value('strategy', V), odrl_strategy_value(V));
|
|
114
|
+
implied_by(odrl_value('operator', V), odrl_operator(V));
|
|
115
|
+
fact(odrl_value('profile', e('SnapshotProfile')));
|
|
116
|
+
implied_by(odrl_known_field(K, P), odrl_field(K, P, _, _, _));
|
|
117
|
+
implied_by(odrl_known_field(K, P), odrl_metadata(P));
|
|
118
|
+
fact(odrl_known_field('state', P));
|
|
119
|
+
implied_by(odrl_has_rule(P), odrl_input(P, o('permission'), _));
|
|
120
|
+
implied_by(odrl_has_rule(P), odrl_input(P, o('prohibition'), _));
|
|
121
|
+
|
|
122
|
+
implies([odrl_node(E, S, K), odrl_field(K, P, Min, Max, T),
|
|
123
|
+
findall_sorted(V, odrl_input(S, P, V), Values), odrl_count(Values, N), lt(N, Min)],
|
|
124
|
+
odrl_problem(E, S, P, e('MissingValue')));
|
|
125
|
+
implies([odrl_node(E, S, K), odrl_field(K, P, Min, Max, T), ge(Max, 0),
|
|
126
|
+
findall_sorted(V, odrl_input(S, P, V), Values), odrl_count(Values, N), gt(N, Max)],
|
|
127
|
+
odrl_problem(E, S, P, e('TooManyValues')));
|
|
128
|
+
implies([odrl_node(E, S, K), odrl_field(K, P, Min, Max, T), odrl_input(S, P, V), not(odrl_value(T, V))],
|
|
129
|
+
odrl_problem(E, S, P, e('UnsupportedValue')));
|
|
130
|
+
implies([odrl_node(E, S, K), odrl_input(S, P, V), not(odrl_known_field(K, P))],
|
|
131
|
+
odrl_problem(E, S, P, e('UnsupportedProperty')));
|
|
132
|
+
implies([odrl_node(E, S, K), odrl_input(S, rdfType, T), not(odrl_type(K, T))],
|
|
133
|
+
odrl_problem(E, S, rdfType, e('UnsupportedType')));
|
|
134
|
+
implies([odrl_node(E, P, 'policy'), not(odrl_has_rule(P))], odrl_problem(E, P, rdfType, e('MissingRule')));
|
|
135
|
+
implies([odrl_evaluation(E), findall_sorted(X, odrl_evaluation(X), Es), odrl_count(Es, N), ne(N, 1)],
|
|
136
|
+
odrl_problem(E, E, rdfType, e('MultipleEvaluations')));
|
|
137
|
+
implies([odrl_node(E, Q, 'request'), odrl_input(Q, e('state'), S),
|
|
138
|
+
odrl_input(Q, e('subject'), Person), odrl_input(S, e('subject'), Other), not_identical(Person, Other)],
|
|
139
|
+
odrl_problem(E, Q, e('state'), e('SubjectMismatch')));
|
|
140
|
+
implies([odrl_rule(E, P, R, 'permission'), odrl_rule(E, P2, R, 'prohibition')],
|
|
141
|
+
odrl_problem(E, R, rdfType, e('AmbiguousRule')));
|
|
142
|
+
implies([odrl_entity(E, S), odrl_input(S, iri(P), V), atom_concat(odrlNS, _, P)],
|
|
143
|
+
odrl_problem(E, S, iri(P), e('UnsupportedProperty')));
|
|
144
|
+
for (const name of ['AssetCollection', 'PartyCollection']) {
|
|
145
|
+
implies([odrl_entity(E, S), odrl_input(S, rdfType, o(name))], odrl_problem(E, S, rdfType, e('UnsupportedType')));
|
|
146
|
+
}
|
|
147
|
+
implied_by(odrl_syntax_error(E), odrl_problem(E, _, _, _));
|
|
148
|
+
|
|
149
|
+
// Constraints read exactly one observation from the request's state.
|
|
150
|
+
// Missing, ambiguous or unsupported observations stay unknown.
|
|
151
|
+
implied_by(odrl_order_kind(o('eq'), K), 'true');
|
|
152
|
+
implied_by(odrl_order_kind(o('neq'), K), 'true');
|
|
153
|
+
for (const name of ['gt', 'gteq', 'lt', 'lteq']) fact(odrl_order_kind(o(name), 'integer'));
|
|
154
|
+
implies([odrl_node(E, C, 'constraint'), odrl_input(C, o('operator'), Op),
|
|
155
|
+
odrl_input(C, o('rightOperand'), V), odrl_scalar(V, K, N), not(odrl_order_kind(Op, K))],
|
|
156
|
+
odrl_problem(E, C, o('rightOperand'), e('OperatorTypeMismatch')));
|
|
157
|
+
fact(odrl_compare(o('eq'), K, V, V));
|
|
158
|
+
implied_by(odrl_compare(o('neq'), K, V, W), not_identical(V, W));
|
|
159
|
+
implied_by(odrl_compare(o('gt'), 'integer', V, W), gt(V, W));
|
|
160
|
+
implied_by(odrl_compare(o('gteq'), 'integer', V, W), ge(V, W));
|
|
161
|
+
implied_by(odrl_compare(o('lt'), 'integer', V, W), lt(V, W));
|
|
162
|
+
implied_by(odrl_compare(o('lteq'), 'integer', V, W), le(V, W));
|
|
163
|
+
implies([odrl_rule(E, P, R, K), odrl_node(E, Q, 'request'), not(odrl_syntax_error(E)),
|
|
164
|
+
odrl_input(R, o('assignee'), Who), odrl_input(Q, o('assignee'), Who),
|
|
165
|
+
odrl_input(R, o('action'), Act), odrl_input(Q, o('action'), Act),
|
|
166
|
+
odrl_input(R, o('target'), Target), odrl_input(Q, o('target'), Target)], odrl_candidate(E, Q, P, R, K));
|
|
167
|
+
implies([odrl_candidate(E, Q, P, R, K), odrl_input(R, o('constraint'), C),
|
|
168
|
+
odrl_input(C, o('leftOperand'), Left), odrl_input(Q, e('state'), S),
|
|
169
|
+
findall_sorted(V, odrl_input(S, Left, V), Values)], odrl_observation(E, Q, R, C, Values));
|
|
170
|
+
implies(odrl_observation(E, Q, R, C, []), odrl_condition(E, Q, R, C, 'unknown', e('MissingObservation')));
|
|
171
|
+
implies(odrl_observation(E, Q, R, C, [A, B, ...Rest]), odrl_condition(E, Q, R, C, 'unknown', e('AmbiguousObservation')));
|
|
172
|
+
implies([odrl_observation(E, Q, R, C, [V]), not(odrl_scalar(V, _, _))],
|
|
173
|
+
odrl_condition(E, Q, R, C, 'unknown', e('UnsupportedObservation')));
|
|
174
|
+
implies([odrl_observation(E, Q, R, C, [V]), odrl_scalar(V, VK, VN),
|
|
175
|
+
odrl_input(C, o('rightOperand'), W), odrl_scalar(W, WK, WN), not_identical(VK, WK)],
|
|
176
|
+
odrl_condition(E, Q, R, C, 'unknown', e('ObservationTypeMismatch')));
|
|
177
|
+
implies([odrl_observation(E, Q, R, C, [V]), odrl_scalar(V, K, VN),
|
|
178
|
+
odrl_input(C, o('rightOperand'), W), odrl_scalar(W, K, WN), odrl_input(C, o('operator'), Op),
|
|
179
|
+
odrl_compare(Op, K, VN, WN)], odrl_condition(E, Q, R, C, 'met', e('Satisfied')));
|
|
180
|
+
implies([odrl_observation(E, Q, R, C, [V]), odrl_scalar(V, K, VN),
|
|
181
|
+
odrl_input(C, o('rightOperand'), W), odrl_scalar(W, K, WN), odrl_input(C, o('operator'), Op),
|
|
182
|
+
not(odrl_compare(Op, K, VN, WN))], odrl_condition(E, Q, R, C, 'unmet', e('Unsatisfied')));
|
|
183
|
+
implied_by(odrl_failed(E, Q, R), odrl_condition(E, Q, R, _, 'unmet', _));
|
|
184
|
+
implied_by(odrl_unknown(E, Q, R), odrl_condition(E, Q, R, _, 'unknown', _));
|
|
185
|
+
implies([odrl_candidate(E, Q, P, R, K), not(odrl_failed(E, Q, R)), not(odrl_unknown(E, Q, R))],
|
|
186
|
+
odrl_applies(E, Q, P, R, K));
|
|
187
|
+
implied_by(odrl_uncertain(E, Q), [odrl_candidate(E, Q, P, R, K), not(odrl_failed(E, Q, R)), odrl_unknown(E, Q, R)]);
|
|
188
|
+
|
|
189
|
+
// Keep every permission/prohibition overlap as evidence, even when a
|
|
190
|
+
// strategy resolves it. An invalid policy voids the whole evaluation.
|
|
191
|
+
implies([odrl_applies(E, Q, PP, PR, 'permission'), odrl_applies(E, Q, NP, NR, 'prohibition')],
|
|
192
|
+
odrl_conflict(E, Q, PP, PR, NP, NR));
|
|
193
|
+
implied_by(odrl_policy_strategy(P, Strategy), odrl_input(P, o('conflict'), Strategy));
|
|
194
|
+
implied_by(odrl_policy_strategy(P, o('invalid')), not(odrl_input(P, o('conflict'), _)));
|
|
195
|
+
implied_by(odrl_void_policy(E, P), [odrl_conflict(E, Q, P, PR, P, NR), odrl_policy_strategy(P, o('invalid'))]);
|
|
196
|
+
implied_by(odrl_has(E, Q, P, K), odrl_applies(E, Q, P, _, K));
|
|
197
|
+
implies([odrl_applies(E, Q, P, R, 'permission'), not(odrl_void_policy(E, P)),
|
|
198
|
+
or(odrl_policy_strategy(P, o('perm')), not(odrl_has(E, Q, P, 'prohibition')))], odrl_retained(E, Q, P, R, 'permission'));
|
|
199
|
+
implies([odrl_applies(E, Q, P, R, 'prohibition'), not(odrl_void_policy(E, P)),
|
|
200
|
+
or(odrl_policy_strategy(P, o('prohibit')), not(odrl_has(E, Q, P, 'permission')))], odrl_retained(E, Q, P, R, 'prohibition'));
|
|
201
|
+
implied_by(odrl_retained_kind(E, Q, K), odrl_retained(E, Q, _, _, K));
|
|
202
|
+
implied_by(odrl_cross_conflict(E), [odrl_retained_kind(E, Q, 'permission'), odrl_retained_kind(E, Q, 'prohibition')]);
|
|
203
|
+
implied_by(odrl_blocked(E), odrl_syntax_error(E));
|
|
204
|
+
implied_by(odrl_blocked(E), odrl_void_policy(E, _));
|
|
205
|
+
implied_by(odrl_blocked(E), [odrl_input(E, e('conflictStrategy'), o('invalid')), odrl_cross_conflict(E)]);
|
|
206
|
+
implies([odrl_node(E, Q, 'request'), odrl_blocked(E)], odrl_decision(E, Q, e('Undetermined')));
|
|
207
|
+
implies([odrl_node(E, Q, 'request'), not(odrl_blocked(E)), odrl_uncertain(E, Q)], odrl_decision(E, Q, e('Undetermined')));
|
|
208
|
+
implies([odrl_node(E, Q, 'request'), not(odrl_blocked(E)), not(odrl_uncertain(E, Q)),
|
|
209
|
+
odrl_retained_kind(E, Q, 'permission'),
|
|
210
|
+
or(odrl_input(E, e('conflictStrategy'), o('perm')), not(odrl_retained_kind(E, Q, 'prohibition')))],
|
|
211
|
+
odrl_decision(E, Q, e('Allowed')));
|
|
212
|
+
implies([odrl_node(E, Q, 'request'), not(odrl_blocked(E)), not(odrl_uncertain(E, Q)),
|
|
213
|
+
odrl_retained_kind(E, Q, 'prohibition'),
|
|
214
|
+
or(odrl_input(E, e('conflictStrategy'), o('prohibit')), not(odrl_retained_kind(E, Q, 'permission')))],
|
|
215
|
+
odrl_decision(E, Q, e('Prohibited')));
|
|
216
|
+
implies([odrl_node(E, Q, 'request'), not(odrl_blocked(E)), not(odrl_uncertain(E, Q)),
|
|
217
|
+
not(odrl_retained_kind(E, Q, 'permission')), not(odrl_retained_kind(E, Q, 'prohibition'))],
|
|
218
|
+
odrl_decision(E, Q, e('NotApplicable')));
|
|
219
|
+
|
|
220
|
+
// One RDF report, including an explicit conflict count and links back to
|
|
221
|
+
// the requests, policies, rules and constraints that explain each result.
|
|
222
|
+
implies(odrl_evaluation(E), rdf(E, rdfType, e('EvaluationReport')));
|
|
223
|
+
implies([odrl_evaluation(E), odrl_input(E, e('policy'), P)], rdf(E, e('policy'), P));
|
|
224
|
+
implies([odrl_evaluation(E), odrl_input(E, e('conflictStrategy'), S)], rdf(E, e('conflictStrategy'), S));
|
|
225
|
+
implies([odrl_evaluation(E), not(odrl_syntax_error(E))], rdf(E, e('validationStatus'), e('Valid')));
|
|
226
|
+
implies(odrl_syntax_error(E), rdf(E, e('validationStatus'), e('Invalid')));
|
|
227
|
+
implies([odrl_decision(E, Q, Status), odrl_resource(Q)], [rdf(E, e('request'), Q), rdf(Q, e('decision'), Status)]);
|
|
228
|
+
implies(odrl_decision(E, Q, e('Allowed')), rdf(E, e('canHappen'), Q));
|
|
229
|
+
implies([odrl_node(E, Q, 'request'), odrl_resource(Q), odrl_input(Q, P, V)], rdf(Q, P, V));
|
|
230
|
+
implies(odrl_applies(E, Q, P, R, 'permission'), rdf(Q, e('permission'), R));
|
|
231
|
+
implies(odrl_applies(E, Q, P, R, 'prohibition'), rdf(Q, e('prohibition'), R));
|
|
232
|
+
implies(odrl_void_policy(E, P), rdf(E, e('invalidPolicy'), P));
|
|
233
|
+
implies([odrl_input(E, e('conflictStrategy'), o('invalid')), odrl_cross_conflict(E)], rdf(E, e('reason'), e('ConflictingPolicies')));
|
|
234
|
+
implies(odrl_condition(E, Q, R, C, 'unmet', Why), rdf(Q, e('unmetConstraint'), C));
|
|
235
|
+
implies([odrl_condition(E, Q, R, C, 'unknown', Why), odrl_input(C, o('leftOperand'), Left)], [
|
|
236
|
+
rdf(Q, e('uncertainty'), Issue), rdf(Issue, rdfType, e('Uncertainty')),
|
|
237
|
+
rdf(Issue, e('constraint'), C), rdf(Issue, e('rule'), R),
|
|
238
|
+
rdf(Issue, e('property'), Left), rdf(Issue, e('reason'), Why),
|
|
239
|
+
]);
|
|
240
|
+
implies(odrl_problem(E, S, P, Code), [
|
|
241
|
+
rdf(E, e('validationError'), Issue), rdf(Issue, rdfType, e('ValidationError')),
|
|
242
|
+
rdf(Issue, e('focus'), S), rdf(Issue, e('property'), P), rdf(Issue, e('code'), Code),
|
|
243
|
+
]);
|
|
244
|
+
implies(odrl_conflict(E, Q, PP, PR, NP, NR), [
|
|
245
|
+
rdf(E, e('conflict'), Conflict), rdf(Conflict, rdfType, e('Conflict')),
|
|
246
|
+
rdf(Conflict, e('request'), Q), rdf(Conflict, e('permissionPolicy'), PP), rdf(Conflict, e('permissionRule'), PR),
|
|
247
|
+
rdf(Conflict, e('prohibitionPolicy'), NP), rdf(Conflict, e('prohibitionRule'), NR),
|
|
248
|
+
]);
|
|
249
|
+
implies([odrl_evaluation(E), findall_sorted(conflict(Q, PP, PR, NP, NR), odrl_conflict(E, Q, PP, PR, NP, NR), Cs),
|
|
250
|
+
odrl_count(Cs, N)], rdf(E, e('conflictCount'), N));
|
|
251
|
+
query(rdf(S, P, O));
|
|
252
|
+
`;
|
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.6.
|
|
2
|
+
export const VERSION = '0.6.5';
|