eyemind 0.8.41 → 0.8.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LS-SPEC.md +1 -1
- package/README.md +11 -3
- package/package.json +1 -1
- package/src/formats.js +9 -4
- package/src/odrl.js +21 -1
- package/src/rdf-logic.js +11 -4
- package/src/version.js +1 -1
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
|
+
164 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.
|
|
@@ -446,7 +446,15 @@ Each rule has one assignee, action and target. The snapshot compares state
|
|
|
446
446
|
properties with scalar or DPV category constraints and combines constraints
|
|
447
447
|
with `odrl:and`, `odrl:or` or `odrl:xone`. Permissions can require duties,
|
|
448
448
|
with fulfillment evidence attached to each request.
|
|
449
|
-
|
|
449
|
+
|
|
450
|
+
`--odrl` combines with `--owl2rl`, `--skos`, `--qudt` and `--shacl`. The
|
|
451
|
+
snapshot then reads the given triples, what the profiles entail about each
|
|
452
|
+
request's state, such as an observation a property chain derives, and entailed
|
|
453
|
+
SKOS links between categories, such as a `skos:broadMatch` to DPV. Other
|
|
454
|
+
entailments, such as an `rdfs:Resource` type for every node, stay out of the
|
|
455
|
+
snapshot, whose validation would reject them. The output is the ODRL report
|
|
456
|
+
with the profiles' own reports, such as a SHACL validation report.
|
|
457
|
+
[Handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card) · [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le) · [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)
|
|
450
458
|
|
|
451
459
|
## How eyemind reasons
|
|
452
460
|
|
|
@@ -620,7 +628,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
620
628
|
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3`, `le` or `eyemind`; by default LE for LE, N3 for N3, Turtle for SRL, ODRL and RDF profiles, eyemind otherwise. |
|
|
621
629
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
622
630
|
| `--program` | Print the program the inputs compile to. |
|
|
623
|
-
| `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
|
|
631
|
+
| `--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. |
|
|
624
632
|
| `--owl2rl` | Add the documented OWL 2 RL inference rules, including RDFS, and RDF conflict reports to RDF inputs. |
|
|
625
633
|
| `--qudt` | Normalize supported QUDT/CDT quantities, with source provenance. |
|
|
626
634
|
| `--skos` | Add positive SKOS Core entailments. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.42",
|
|
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
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
//
|
|
15
15
|
// The odrl option adds the snapshot profile's validation and evaluation LS
|
|
16
16
|
// to one Turtle input. Its vocabulary alone never enables the evaluator.
|
|
17
|
-
// Explicit owl2rl, qudt, skos and shacl profiles share one RDF working graph
|
|
17
|
+
// Explicit owl2rl, qudt, skos and shacl profiles share one RDF working graph;
|
|
18
|
+
// with odrl as well, that graph's entailments about states feed the snapshot.
|
|
18
19
|
//
|
|
19
20
|
// The compiled program is ordinary LS: proofs, checking and --unused
|
|
20
21
|
// apply to it. SRL execution functions capture a context that a saved proof
|
|
@@ -25,7 +26,7 @@ import { readTerms } from './reader.js';
|
|
|
25
26
|
import { DEFAULT_GRAPH, parseRdf, rdfDocument, rdfFormat, writeRdf } from './rdf.js';
|
|
26
27
|
import { resultToN3, compileSources } from './n3.js';
|
|
27
28
|
import { compileSrl, srlAnswers, srlQuads } from './srl.js';
|
|
28
|
-
import { compileOdrl } from './odrl.js';
|
|
29
|
+
import { checkOdrlInput, compileOdrl } from './odrl.js';
|
|
29
30
|
import { compileRdfLogic, messageReasoner, RDF_PROFILES, shaclIn as shaclInPatterns, shaclOut as shaclOutPatterns } from './rdf-logic.js';
|
|
30
31
|
import { compileLe, writeLe } from './le.js';
|
|
31
32
|
import { write } from './writer.js';
|
|
@@ -125,9 +126,13 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
125
126
|
}
|
|
126
127
|
return compileLe(inputs);
|
|
127
128
|
}
|
|
128
|
-
if (profiles.length && odrl)
|
|
129
|
+
if (profiles.length && odrl) {
|
|
130
|
+
if (inputs.length !== 1) throw new EyemindError(`--odrl with ${switches} takes one Turtle snapshot containing policies, requests and SOTW`);
|
|
131
|
+
if (shaclIn || shaclOut) throw new EyemindError('--odrl cannot be combined with --shacl-in or --shacl-out');
|
|
132
|
+
}
|
|
129
133
|
if (profiles.length) {
|
|
130
134
|
const graph = profileGraph(inputs, kinds, rdf, baseOf, switches, io);
|
|
135
|
+
if (odrl) checkOdrlInput(graph.quads);
|
|
131
136
|
const source = inputs.map(([, n]) => n).join(', ');
|
|
132
137
|
// SHACL shapes as contracts: what messages hold, and what is wanted.
|
|
133
138
|
const shapes = ([text, name]) => parseRdf(text, { format: rdfFormat(name) ?? 'turtle', base: baseOf(name) }).quads;
|
|
@@ -139,7 +144,7 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
139
144
|
graph.expected = { patterns: read.flatMap((r) => r.patterns), allowed: closed ? new Set(read.flatMap((r) => [...r.allowed])) : null };
|
|
140
145
|
}
|
|
141
146
|
if (messages) return messageReasoner(graph, { profiles, source, limits });
|
|
142
|
-
return compileRdfLogic(graph, { profiles, source, context: srlContext });
|
|
147
|
+
return compileRdfLogic(graph, { profiles, source, context: srlContext, odrl });
|
|
143
148
|
}
|
|
144
149
|
if (odrl) {
|
|
145
150
|
if (inputs.length !== 1) throw new EyemindError('--odrl takes one Turtle snapshot containing policies, requests and SOTW');
|
package/src/odrl.js
CHANGED
|
@@ -17,9 +17,13 @@ export function isOdrlEvaluation(quads) {
|
|
|
17
17
|
object.args[0] === `${ODRL_EVAL}Evaluation`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function checkOdrlInput(quads) {
|
|
21
21
|
if (!isOdrlEvaluation(quads)) throw new EyemindError('--odrl 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
|
+
}
|
|
24
|
+
|
|
25
|
+
export function compileOdrl({ quads, prefixes }, { source = '<input>' } = {}) {
|
|
26
|
+
checkOdrlInput(quads);
|
|
23
27
|
// RDF graphs are sets; repeated statements must not violate cardinalities.
|
|
24
28
|
const facts = [...new Set(quads.map(([s, p, o]) => write(new Struct('odrl_input', [s, p, o]))))].join('\n');
|
|
25
29
|
const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, an ODRL snapshot.\n` +
|
|
@@ -28,6 +32,22 @@ export function compileOdrl({ quads, prefixes }, { source = '<input>' } = {}) {
|
|
|
28
32
|
return { kind: 'odrl', text, program: loadText(text, source), prefixes: { ...prefixes, eval: ODRL_EVAL }, compiled: null };
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
// With RDF logic profiles, the snapshot reads the given default graph, what
|
|
36
|
+
// the profiles entail about each request's state, and entailed SKOS links
|
|
37
|
+
// between categories. Other entailments, such as rdfs:Resource types of every
|
|
38
|
+
// node, would fail its strict validation. A block keeps its constants apart
|
|
39
|
+
// from the profiles' own.
|
|
40
|
+
export const odrlProfileRules = () => `{${RULES}
|
|
41
|
+
implies(ent_base(S, P, O, 'default_graph'), odrl_input(S, P, O));
|
|
42
|
+
implies([ent_base(Q, e('state'), S, 'default_graph'), rdf(S, P, O, 'default_graph'), not_identical(P, rdfType)],
|
|
43
|
+
odrl_input(S, P, O));
|
|
44
|
+
for (const name of ['broader', 'narrower', 'broaderTransitive', 'narrowerTransitive']) {
|
|
45
|
+
const link = iri('http://www.w3.org/2004/02/skos/core#' + name);
|
|
46
|
+
implies(rdf(C, link, D, 'default_graph'), odrl_input(C, link, D));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
31
51
|
const RULES = String.raw`
|
|
32
52
|
// Validation: the supported snapshot profile. Unknown policy features fail
|
|
33
53
|
// validation, so they cannot disappear while a permission is being decided.
|
package/src/rdf-logic.js
CHANGED
|
@@ -10,6 +10,7 @@ import { compileShacl } from './shacl.js';
|
|
|
10
10
|
import { NODE_FUNCTIONS } from './shacl-expr.js';
|
|
11
11
|
import { executionContext } from './srl.js';
|
|
12
12
|
import { rdfValueRules } from './rdf-values.js';
|
|
13
|
+
import { ODRL_EVAL, odrlProfileRules } from './odrl.js';
|
|
13
14
|
import { run } from './engine.js';
|
|
14
15
|
import { Specializer, shape } from './specialize.js';
|
|
15
16
|
import { Env, EyemindError, Struct, Var, freshTerm, identity, key, unify } from './terms.js';
|
|
@@ -19,8 +20,10 @@ export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
|
|
|
19
20
|
export const RDF_PROFILES = ['owl2rl', 'qudt', 'skos', 'shacl'];
|
|
20
21
|
|
|
21
22
|
// wanted: rdf/4 patterns of the output contract, or null for every new triple.
|
|
23
|
+
// odrl: the entailed graph feeds an ODRL snapshot, whose report replaces the
|
|
24
|
+
// new triples; the profiles' own reports stay.
|
|
22
25
|
export function compileRdfLogic({ quads, prefixes, shapes = quads, wanted = null }, {
|
|
23
|
-
profiles, source = '<input>', disallows, evaluate, context, stream = false, stableRuleIds = false,
|
|
26
|
+
profiles, source = '<input>', disallows, evaluate, context, stream = false, stableRuleIds = false, odrl = false,
|
|
24
27
|
}) {
|
|
25
28
|
quads = [...new Map(quads.map((q) => [q.map((t) => write(t)).join(' '), q])).values()];
|
|
26
29
|
const selected = new Set(profiles), needs = new Set();
|
|
@@ -42,10 +45,10 @@ export function compileRdfLogic({ quads, prefixes, shapes = quads, wanted = null
|
|
|
42
45
|
(selected.has('owl2rl') ? owl2rlRules : '') +
|
|
43
46
|
(selected.has('skos') ? skosRules : '') +
|
|
44
47
|
(selected.has('qudt') ? qudtRules(stableRuleIds ? [] : quads) : '') +
|
|
45
|
-
shacl + (evaluate ? "query(sh_evaluation(R));\n" : REPORTS + (stream ? '' : wanted === null ? RESULT : contracted(wanted))) +
|
|
48
|
+
shacl + (evaluate ? "query(sh_evaluation(R));\n" : REPORTS + (odrl ? REPORTED + odrlProfileRules() : stream ? '' : wanted === null ? RESULT : contracted(wanted))) +
|
|
46
49
|
(stableRuleIds ? data + defaultGraph + (selected.has('qudt') ? qudtUnits(quads) : '') : '');
|
|
47
|
-
return { kind: profiles[0], text, program: loadText(text, source),
|
|
48
|
-
prefixes: { ...prefixes, ent: ENTAILMENT, ...(selected.has('skos') ? { skos: 'http://www.w3.org/2004/02/skos/core#' } : {}),
|
|
50
|
+
return { kind: odrl ? 'odrl' : profiles[0], text, program: loadText(text, source),
|
|
51
|
+
prefixes: { ...prefixes, ent: ENTAILMENT, ...(odrl ? { eval: ODRL_EVAL } : {}), ...(selected.has('skos') ? { skos: 'http://www.w3.org/2004/02/skos/core#' } : {}),
|
|
49
52
|
...(selected.has('qudt') ? { qconv: 'https://eyereasoner.github.io/eyemind/qudt#', qudt: 'http://qudt.org/schema/qudt/', unit: 'http://qudt.org/vocab/unit/' } : {}),
|
|
50
53
|
...(selected.has('shacl') ? { sh: 'http://www.w3.org/ns/shacl#' } : {}) }, compiled: null };
|
|
51
54
|
}
|
|
@@ -411,6 +414,10 @@ implies(ent_conflict(R, X, P, Y, G), [
|
|
|
411
414
|
const contracted = (wanted) => RESULT.replace(/^query\(.*\n/m, '') +
|
|
412
415
|
wanted.map((pattern) => `${write(new Struct('query', [new Struct('result_rdf', pattern.args)]), null, new Lettering())};\n`).join('');
|
|
413
416
|
|
|
417
|
+
const REPORTED = String.raw`implies(ent_report(S, P, O, G), result_rdf(S, P, O, G));
|
|
418
|
+
query(result_rdf(S, P, O, G));
|
|
419
|
+
`;
|
|
420
|
+
|
|
414
421
|
const RESULT = String.raw`implies([rdf(S, iri(P), O, G), ent_resource(S), not(ent_base(S, iri(P), O, G))], result_rdf(S, iri(P), O, G));
|
|
415
422
|
implies(ent_report(S, P, O, G), result_rdf(S, P, O, G));
|
|
416
423
|
query(result_rdf(S, P, O, G));
|
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.42';
|