eyemind 0.8.41 → 0.8.43

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The Logic Script (LS) Language and Proof Format
5
- Version: eyemind 0.8.41
5
+ Version: eyemind 0.8.43
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
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
- 160 runnable programs, each with a card deck and saved conclusions; all but
16
+ 165 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.
@@ -407,7 +407,10 @@ query(rdf(O, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), sosa('Obser
407
407
  units: with `qudt:conversionMultiplier` and `qudt:hasDimensionVector`,
408
408
  composed from QUDT units with `qudt:hasFactorUnit` and an optional
409
409
  `qudt:factorUnitScalar`, derived from `qudt:prefix` and `qudt:scalingOf`,
410
- or aligned with `owl:sameAs` or `skos:exactMatch`. The
410
+ or aligned with `owl:sameAs` or `skos:exactMatch`, which are symmetric and
411
+ read in either direction, or with `qconv:alignedQudtUnit` from the local
412
+ unit to the QUDT one; a local `qudt:symbol` or `qudt:ucumCode` then names
413
+ the unit in a CDT literal. The
411
414
  other units of the QUDT unit vocabulary with a fixed conversion, such as
412
415
  `unit:W-PER-M2`, come from an offline catalog that `tools/qudt-catalog.js`
413
416
  generates from a QUDT release, also by the UCUM code of a CDT literal. A
@@ -446,7 +449,15 @@ Each rule has one assignee, action and target. The snapshot compares state
446
449
  properties with scalar or DPV category constraints and combines constraints
447
450
  with `odrl:and`, `odrl:or` or `odrl:xone`. Permissions can require duties,
448
451
  with fulfillment evidence attached to each request.
449
- [Handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card) · [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le)
452
+
453
+ `--odrl` combines with `--owl2rl`, `--skos`, `--qudt` and `--shacl`. The
454
+ snapshot then reads the given triples, what the profiles entail about each
455
+ request's state, such as an observation a property chain derives, and entailed
456
+ SKOS links between categories, such as a `skos:broadMatch` to DPV. Other
457
+ entailments, such as an `rdfs:Resource` type for every node, stay out of the
458
+ snapshot, whose validation would reject them. The output is the ODRL report
459
+ with the profiles' own reports, such as a SHACL validation report.
460
+ [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
461
 
451
462
  ## How eyemind reasons
452
463
 
@@ -620,7 +631,7 @@ eyemind [OPTION ...] [FILE ...]
620
631
  | `--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
632
  | `--all` | With RDF or N3 output, write the given data too. |
622
633
  | `--program` | Print the program the inputs compile to. |
623
- | `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
634
+ | `--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
635
  | `--owl2rl` | Add the documented OWL 2 RL inference rules, including RDFS, and RDF conflict reports to RDF inputs. |
625
636
  | `--qudt` | Normalize supported QUDT/CDT quantities, with source provenance. |
626
637
  | `--skos` | Add positive SKOS Core entailments. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.8.41",
3
+ "version": "0.8.43",
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) throw new EyemindError(`--odrl cannot be combined with ${switches}`);
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 compileOdrl({ quads, prefixes }, { source = '<input>' } = {}) {
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/qudt.js CHANGED
@@ -97,6 +97,11 @@ implied_by(qu_align(U, U, G), qu_dimension(U, G, _));
97
97
  for (const p of [iri('${SAME_AS}'), iri('${EXACT_MATCH}'), qc('alignedQudtUnit')]) {
98
98
  implied_by(qu_align(Local, U, G), [rdf(Local, p, U, G), qu_dimension(U, G, _)]);
99
99
  }
100
+ // owl:sameAs and skos:exactMatch are symmetric, so a known unit can name its
101
+ // local alias without --owl2rl or --skos; qconv:alignedQudtUnit is directed.
102
+ for (const p of [iri('${SAME_AS}'), iri('${EXACT_MATCH}')]) {
103
+ implied_by(qu_align(Local, U, G), [rdf(U, p, Local, G), qu_dimension(U, G, _)]);
104
+ }
100
105
  implied_by(qu_custom_profile(P, G), ent_base(P, qc('targetUnit'), _, G));
101
106
  implied_by(qu_profile(P, DT, U, Code, G), [qu_builtin_profile(P, DT, U, Code), not(qu_custom_profile(P, G))]);
102
107
  implied_by(qu_profile(P, DT, U, Code, G), [ent_base(P, qc('targetUnit'), U, G), ent_base(P, qc('datatype'), iri(DT), G), ent_base(P, qc('targetUcumCode'), L, G), srl_str(L, literal(Code, datatype(quString)))]);
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.41';
2
+ export const VERSION = '0.8.43';