eyemind 0.6.5 → 0.6.6

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 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 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).
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 138 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
+ - [RDFS and OWL-RL](#rdfs-and-owl-rl)
25
26
  - [ODRL snapshots](#odrl-snapshots)
26
27
  - [How eyemind reasons](#how-eyemind-reasons)
27
28
  - [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
@@ -386,6 +387,60 @@ SRL programs for deployment dependencies, route distances, ancestry, inventory,
386
387
  invoices, provenance and Unicode strings. Each has saved Turtle output, a
387
388
  proof, a check report and a deck, and runs in the playground.
388
389
 
390
+ ### RDFS and OWL-RL
391
+
392
+ `--rdfs` and `--owl-rl` add inference rules to RDF inputs. The files still
393
+ use their usual RDF extensions; standard input is Turtle. A graph's use of
394
+ RDFS or OWL vocabulary alone does not enable either extension. The playground
395
+ has both switches and preserves them in saved sessions and shared links.
396
+
397
+ ```sh
398
+ eyemind --rdfs examples/people-rdfs.ttl
399
+ eyemind --owl-rl examples/family-owl-rl.ttl > /tmp/family-report.ttl
400
+ eyemind --owl-rl --program examples/family-owl-rl.ttl > /tmp/family.js
401
+ eyemind --to turtle /tmp/family.js
402
+ eyemind --owl-rl --proof examples/family-owl-rl.ttl > /tmp/family-proof.js
403
+ eyemind --owl-rl --check-proof /tmp/family-proof.js examples/family-owl-rl.ttl
404
+ ```
405
+
406
+ The generated `.js` contains the data, inference rules and reporting rules;
407
+ it runs as standalone LS. Proofs and check reports remain `.js`. Conclusions
408
+ default to Turtle, with `--all` adding the input triples. Multiple RDF files
409
+ join their default graphs; named graphs are reasoned over independently and
410
+ need `--to trig` or `--to n-quads` to retain their graph names.
411
+
412
+ The implemented rules are:
413
+
414
+ | Switch | Coverage |
415
+ | --- | --- |
416
+ | `--rdfs` | Class and property hierarchy transitivity, type and property propagation, domain and range inference and inheritance, resource/class/property typing, reflexive hierarchies, container membership and datatype-to-literal subclassing. |
417
+ | `--owl-rl` | The RDFS rules above plus OWL equality and substitution; equivalent classes and properties; inverse, symmetric, transitive, functional and inverse-functional properties; property chains and keys; intersections, unions, enumerations, value restrictions and maximum cardinalities 0 and 1; class/property disjointness, AllDifferent, negative property assertions and schema propagation. |
418
+
419
+ The OWL rules implement the non-datatype rule families of
420
+ [OWL 2 RL/RDF tables 4–7 and 9](https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs),
421
+ inspired by [EYE's RDF plus OWL rules](https://github.com/eyereasoner/eye/tree/master/reasoning/rpo).
422
+ They operate on the terms present in each graph. RDFS axiomatic triples,
423
+ datatype value-space reasoning (OWL table 8), ontology imports and OWL
424
+ constructs outside these rule families are not implemented. Literal equality
425
+ uses the RDF-to-LS representation, without general datatype normalization.
426
+ These switches do not validate profile membership or certify completeness
427
+ for arbitrary RDFS or OWL ontologies. `--owl-rl` already includes `--rdfs`;
428
+ enabling both adds the rules once. They take RDF inputs and cannot be combined
429
+ with `--odrl` or `--stream-messages`.
430
+
431
+ OWL contradictions appear as RDF records of type `ent:Conflict`, where
432
+ `ent:` is `https://eyereasoner.github.io/eyemind/entailment#`. Each records its
433
+ rule name with `ent:rule` and arguments with `ent:focus`, `ent:left` and
434
+ `ent:right`; the proof supplies the supporting assertions. Reporting continues
435
+ after a conflict and does not infer arbitrary triples from inconsistency.
436
+ Exit code 0 means the report completed, including any conflicts. An empty
437
+ conflict set only means these rules detected none; it is not a full consistency
438
+ guarantee. RDFS domain and range infer types rather than checking required
439
+ fields, and missing facts alone do not establish a conflict.
440
+
441
+ Try the [people directory](https://eyereasoner.github.io/eyemind/examples/deck/people-rdfs)
442
+ and [family ontology](https://eyereasoner.github.io/eyemind/examples/deck/family-owl-rl).
443
+
389
444
  ### ODRL snapshots
390
445
 
391
446
  Use `--odrl` to add ODRL validation and evaluation to one Turtle file
@@ -624,11 +679,13 @@ eyemind [OPTION ...] [FILE ...]
624
679
  | `--unused` | List the clauses that make no difference to the conclusions. |
625
680
  | `--stream-messages` | Read an RDF Message Log and run the rules independently per message; Node reads files, stdin and HTTP(S) incrementally. |
626
681
  | `--stats` | Print reasoning statistics as JSON to standard error. |
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. |
682
+ | `--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, ODRL, RDFS or OWL-RL program has 1000000, 100000 and 1000000000. |
683
+ | `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3` or `eyemind`; by default N3 for N3, Turtle for SRL, ODRL, RDFS and OWL-RL, eyemind otherwise. |
629
684
  | `--all` | With RDF or N3 output, write the given data too. |
630
685
  | `--program` | Print the program the inputs compile to. |
631
686
  | `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
687
+ | `--rdfs` | Add the documented RDFS inference rules to RDF inputs. |
688
+ | `--owl-rl` | Add the documented OWL-RL inference rules and RDF conflict reports to RDF inputs; includes `--rdfs`. |
632
689
  | `--base IRI` | Resolve relative IRIs of the inputs against `IRI` instead of each file's location. |
633
690
  | `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
634
691
 
@@ -638,7 +695,7 @@ each goal as a data document, with an array denoting conjunction. With
638
695
  `--check-proof`, supply the original goals the proof answers.
639
696
  An option that takes a value requires it immediately afterward; another
640
697
  option, including a short alias such as `-v`, is reported as a missing value.
641
- With `--goal`, answers default to eyemind terms even for N3, SRL and ODRL inputs;
698
+ With `--goal`, answers default to eyemind terms even for N3, SRL, ODRL, RDFS and OWL-RL inputs;
642
699
  use `--to` to request another output format.
643
700
 
644
701
  With `--prove-and-check`, reasoning bounds and `--stats` apply to proof
@@ -667,7 +724,7 @@ They are outside the language and proof specification.
667
724
 
668
725
  The JavaScript implementation defaults to a depth limit of 1000000, an
669
726
  inference limit of 1000000 and a limit of 1000 forward rounds per stratum.
670
- Compiled N3, SRL and ODRL programs use 1000000, 1000000000 and 100000 respectively.
727
+ Compiled N3, SRL, ODRL, RDFS and OWL-RL programs use 1000000, 1000000000 and 100000 respectively.
671
728
  Each supplied bound must be a positive integer no greater than
672
729
  9007199254740991.
673
730
 
package/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.6.5
5
+ Version: eyemind 0.6.6
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
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,10 +24,12 @@ 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 SRL or ODRL, eyemind otherwise or with --goal)
27
+ for SRL, ODRL, RDFS or OWL-RL, 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
30
  --odrl Add ODRL validation and evaluation to one Turtle snapshot
31
+ --rdfs Add RDFS inference rules to RDF inputs
32
+ --owl-rl Add OWL-RL inference and conflict rules to RDF inputs
31
33
  --base IRI Resolve relative IRIs of the inputs against IRI
32
34
  --stream-messages Run the rules independently for each RDF Message
33
35
  -v, --version Print the version
@@ -67,6 +69,8 @@ export function main(argv, io) {
67
69
  let base = null;
68
70
  let streamMessages = false;
69
71
  let odrl = false;
72
+ let rdfs = false;
73
+ let owlRl = false;
70
74
  const filePositions = new Set();
71
75
  for (let i = 0; i < argv.length; i++) {
72
76
  const arg = ALIASES.get(argv[i]) ?? argv[i];
@@ -94,6 +98,10 @@ export function main(argv, io) {
94
98
  printProgram = true;
95
99
  } else if (arg === '--odrl') {
96
100
  odrl = true;
101
+ } else if (arg === '--rdfs') {
102
+ rdfs = true;
103
+ } else if (arg === '--owl-rl') {
104
+ owlRl = true;
97
105
  } else if (arg === '--stream-messages') {
98
106
  streamMessages = true;
99
107
  } else if (arg === '--check-proof' || arg === '--goal' || arg === '--to' || arg === '--base' || Object.hasOwn(LIMITS, arg)) {
@@ -142,6 +150,7 @@ export function main(argv, io) {
142
150
  if (files.filter((file) => file === '-').length > 1) throw new UsageError('stdin can only be read once');
143
151
  if (streamMessages) {
144
152
  if (odrl) throw new UsageError('--odrl cannot be combined with --stream-messages');
153
+ if (rdfs || owlRl) throw new UsageError('--rdfs and --owl-rl cannot be combined with --stream-messages');
145
154
  if (proofFile !== null || options.proof || proveAndCheck || printProgram || unused) {
146
155
  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');
147
156
  }
@@ -182,7 +191,7 @@ export function main(argv, io) {
182
191
  }
183
192
  const document = proofFile === null ? null : readSource(proofFile, io);
184
193
  const loaded = loadInputs(files.map((file) => [readSource(file, io), file === '-' ? '<stdin>' : file]), io,
185
- { base, messageInputs: io.messageInputs, odrl,
194
+ { base, messageInputs: io.messageInputs, odrl, rdfs, owlRl,
186
195
  srlContext: document !== null && files.some((file) => inputKind(file) === 'srl') ? srlContextFromProof(document) : null });
187
196
  const program = loaded.program;
188
197
  if (printProgram) {
@@ -0,0 +1,180 @@
1
+ // Explicit RDF entailment extensions, compiled to standalone Logic Script.
2
+ // Rule names follow W3C OWL 2 RL/RDF tables 4–7 and 9:
3
+ // https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs
4
+ import { loadText } from './lang.js';
5
+ import { rdfDocument } from './rdf.js';
6
+
7
+ export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
8
+
9
+ export function compileEntailment({ quads, prefixes }, { owl = false, source = '<input>' } = {}) {
10
+ const kind = owl ? 'owl-rl' : 'rdfs';
11
+ const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with --${kind}.\n` +
12
+ '// rdf(S, P, O, G) is the working graph; result_rdf contains new RDF conclusions.\n' +
13
+ `facts_from({ text: ${JSON.stringify(rdfDocument(quads))} })\n` +
14
+ `facts_from({ text: ${JSON.stringify(rdfDocument(quads, 'ent_base'))} })\n` +
15
+ COMMON + RDFS + (owl ? OWL : '') + OUTPUT;
16
+ return { kind, text, program: loadText(text, source), prefixes: { ...prefixes, ent: ENTAILMENT }, compiled: null };
17
+ }
18
+
19
+ const COMMON = String.raw`
20
+ const r = (name) => iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#' + name);
21
+ const s = (name) => iri('http://www.w3.org/2000/01/rdf-schema#' + name);
22
+ const o = (name) => iri('http://www.w3.org/2002/07/owl#' + name);
23
+ const e = (name) => iri('https://eyereasoner.github.io/eyemind/entailment#' + name);
24
+ const t = (a, p, b) => rdf(a, p, b, G);
25
+ implied_by(ent_resource(iri(A)), is_atom(A));
26
+ implied_by(ent_resource(bnode(A, B)), [is_atom(A), is_atom(B)]);
27
+ implied_by(ent_resource(triple(A, B, C)), 'true');
28
+ implies(rdf(S, P, O, G), ent_graph(G));
29
+ implies(rdf(S, P, O, G), [ent_node(S, G), ent_node(P, G), ent_node(O, G)]);
30
+
31
+ // RDFS class/property propagation, shared with OWL-RL.
32
+ implies([t(P, s('domain'), C), t(X, P, Y)], t(X, r('type'), C));
33
+ implies([t(P, s('range'), C), t(X, P, Y)], t(Y, r('type'), C));
34
+ implies([t(C, s('subClassOf'), D), t(X, r('type'), C)], t(X, r('type'), D));
35
+ implies([t(C, s('subClassOf'), D), t(D, s('subClassOf'), E)], t(C, s('subClassOf'), E));
36
+ implies([t(P, s('subPropertyOf'), Q), t(X, P, Y)], t(X, Q, Y));
37
+ implies([t(P, s('subPropertyOf'), Q), t(Q, s('subPropertyOf'), R)], t(P, s('subPropertyOf'), R));
38
+ for (const property of ['domain', 'range']) {
39
+ implies([t(P, s(property), C), t(C, s('subClassOf'), D)], t(P, s(property), D));
40
+ implies([t(Q, s(property), C), t(P, s('subPropertyOf'), Q)], t(P, s(property), C));
41
+ }
42
+ `;
43
+
44
+ const RDFS = String.raw`
45
+ // RDFS rules over the terms present in the input; no infinite vocabulary
46
+ // axioms or datatype value-space reasoning are added.
47
+ implies(rdf(S, P, O, G), t(P, r('type'), r('Property')));
48
+ implies(rdf(S, P, O, G), [t(S, r('type'), s('Resource')), t(O, r('type'), s('Resource'))]);
49
+ implies(t(X, r('type'), C), t(C, r('type'), s('Class')));
50
+ for (const property of ['subClassOf', 'domain', 'range']) {
51
+ implies(t(X, s(property), C), t(C, r('type'), s('Class')));
52
+ }
53
+ for (const property of ['domain', 'range']) implies(t(P, s(property), C), t(P, r('type'), r('Property')));
54
+ implies(t(C, s('subClassOf'), D), t(C, r('type'), s('Class')));
55
+ implies(t(P, s('subPropertyOf'), Q), [t(P, r('type'), r('Property')), t(Q, r('type'), r('Property'))]);
56
+ implies(t(P, r('type'), r('Property')), t(P, s('subPropertyOf'), P));
57
+ implies(t(C, r('type'), s('Class')), [t(C, s('subClassOf'), C), t(C, s('subClassOf'), s('Resource'))]);
58
+ implies(t(P, r('type'), s('ContainerMembershipProperty')), t(P, s('subPropertyOf'), s('member')));
59
+ implies(t(D, r('type'), s('Datatype')), t(D, s('subClassOf'), s('Literal')));
60
+ `;
61
+
62
+ const OWL = String.raw`
63
+ // Equality (table 4). Generalized triples stay internal when their subject
64
+ // or predicate is a literal; RDF output only contains legal RDF triples.
65
+ implies(ent_node(X, G), t(X, o('sameAs'), X));
66
+ implies(t(X, o('sameAs'), Y), t(Y, o('sameAs'), X));
67
+ implies([t(X, o('sameAs'), Y), t(Y, o('sameAs'), Z)], t(X, o('sameAs'), Z));
68
+ implies([t(X, o('sameAs'), Y), t(X, P, Z)], t(Y, P, Z));
69
+ implies([t(P, o('sameAs'), Q), t(X, P, Y)], t(X, Q, Y));
70
+ implies([t(X, o('sameAs'), Y), t(Z, P, X)], t(Z, P, Y));
71
+ implies([t(X, o('sameAs'), Y), t(X, o('differentFrom'), Y)], ent_conflict('eq-diff1', X, o('differentFrom'), Y, G));
72
+
73
+ // Finite, positive list relations also terminate on cyclic rdf:rest data.
74
+ implies(ent_graph(G), ent_list(r('nil'), G));
75
+ implies([t(L, r('first'), X), t(L, r('rest'), R), ent_list(R, G)], ent_list(L, G));
76
+ implies([ent_list(L, G), t(L, r('first'), X)], ent_member(L, X, G));
77
+ implies([ent_list(L, G), t(L, r('rest'), R), ent_member(R, X, G)], ent_member(L, X, G));
78
+ implies([ent_list(L, G), t(L, r('first'), X), t(L, r('rest'), R), ent_member(R, Y, G)], ent_pair(L, X, Y, G));
79
+ implies([ent_list(L, G), t(L, r('rest'), R), ent_pair(R, X, Y, G)], ent_pair(L, X, Y, G));
80
+ for (const property of ['members', 'distinctMembers']) {
81
+ implies([t(A, r('type'), o('AllDifferent')), t(A, o(property), L), ent_pair(L, X, Y, G), t(X, o('sameAs'), Y)],
82
+ ent_conflict(property === 'members' ? 'eq-diff2' : 'eq-diff3', A, X, Y, G));
83
+ }
84
+
85
+ // Property axioms (table 5).
86
+ for (const property of [s('label'), s('comment'), s('seeAlso'), s('isDefinedBy'),
87
+ o('deprecated'), o('versionInfo'), o('priorVersion'), o('backwardCompatibleWith'), o('incompatibleWith')]) {
88
+ implies(ent_graph(G), t(property, r('type'), o('AnnotationProperty')));
89
+ }
90
+ implies([t(P, r('type'), o('FunctionalProperty')), t(X, P, Y), t(X, P, Z)], t(Y, o('sameAs'), Z));
91
+ implies([t(P, r('type'), o('InverseFunctionalProperty')), t(X, P, Z), t(Y, P, Z)], t(X, o('sameAs'), Y));
92
+ implies([t(P, r('type'), o('SymmetricProperty')), t(X, P, Y)], t(Y, P, X));
93
+ implies([t(P, r('type'), o('TransitiveProperty')), t(X, P, Y), t(Y, P, Z)], t(X, P, Z));
94
+ implies([t(P, r('type'), o('IrreflexiveProperty')), t(X, P, X)], ent_conflict('prp-irp', X, P, X, G));
95
+ implies([t(P, r('type'), o('AsymmetricProperty')), t(X, P, Y), t(Y, P, X)], ent_conflict('prp-asyp', X, P, Y, G));
96
+ implies([t(P, o('propertyDisjointWith'), Q), t(X, P, Y), t(X, Q, Y)], ent_conflict('prp-pdw', X, P, Q, G));
97
+ implies([t(A, r('type'), o('AllDisjointProperties')), t(A, o('members'), L), ent_pair(L, P, Q, G), t(X, P, Y), t(X, Q, Y)],
98
+ ent_conflict('prp-adp', A, P, Q, G));
99
+ implies([t(P, o('inverseOf'), Q), t(X, P, Y)], t(Y, Q, X));
100
+ implies([t(P, o('inverseOf'), Q), t(X, Q, Y)], t(Y, P, X));
101
+ implies([t(L, r('first'), P), t(L, r('rest'), r('nil')), t(X, P, Y)], ent_chain(L, X, Y, G));
102
+ implies([t(L, r('first'), P), t(L, r('rest'), R), t(X, P, Y), ent_chain(R, Y, Z, G)], ent_chain(L, X, Z, G));
103
+ implies([t(P, o('propertyChainAxiom'), L), ent_chain(L, X, Y, G)], t(X, P, Y));
104
+ implies([t(C, o('hasKey'), L), t(X, r('type'), C), t(Y, r('type'), C)], ent_key_candidate(L, X, Y, G));
105
+ implies([ent_key_candidate(L, X, Y, G), t(L, r('rest'), R)], ent_key_candidate(R, X, Y, G));
106
+ implies(ent_key_candidate(r('nil'), X, Y, G), ent_key(r('nil'), X, Y, G));
107
+ implies([ent_key_candidate(L, X, Y, G), t(L, r('first'), P), t(L, r('rest'), R), t(X, P, V), t(Y, P, V), ent_key(R, X, Y, G)],
108
+ ent_key(L, X, Y, G));
109
+ implies([t(C, o('hasKey'), L), t(X, r('type'), C), t(Y, r('type'), C), ent_key(L, X, Y, G)], t(X, o('sameAs'), Y));
110
+ for (const property of ['targetIndividual', 'targetValue']) {
111
+ implies([t(A, o('sourceIndividual'), X), t(A, o('assertionProperty'), P), t(A, o(property), Y), t(X, P, Y)],
112
+ ent_conflict(property === 'targetIndividual' ? 'prp-npa1' : 'prp-npa2', A, P, Y, G));
113
+ }
114
+
115
+ // Class expressions and class axioms (tables 6–7).
116
+ implies(ent_graph(G), [t(o('Thing'), r('type'), o('Class')), t(o('Nothing'), r('type'), o('Class'))]);
117
+ implies(t(X, r('type'), o('Nothing')), ent_conflict('cls-nothing2', X, r('type'), o('Nothing'), G));
118
+ implies(ent_node(X, G), ent_all(r('nil'), X, G));
119
+ implies([t(L, r('first'), C), t(L, r('rest'), R), t(X, r('type'), C), ent_all(R, X, G)], ent_all(L, X, G));
120
+ implies([t(C, o('intersectionOf'), L), ent_list(L, G), ent_all(L, X, G)], t(X, r('type'), C));
121
+ implies([t(C, o('intersectionOf'), L), ent_member(L, D, G)], t(C, s('subClassOf'), D));
122
+ implies([t(C, o('unionOf'), L), ent_member(L, D, G)], t(D, s('subClassOf'), C));
123
+ implies([t(C, o('oneOf'), L), ent_member(L, X, G)], t(X, r('type'), C));
124
+ for (const property of ['complementOf', 'disjointWith']) {
125
+ implies([t(C, o(property), D), t(X, r('type'), C), t(X, r('type'), D)],
126
+ ent_conflict(property === 'complementOf' ? 'cls-com' : 'cax-dw', X, C, D, G));
127
+ }
128
+ implies([t(A, r('type'), o('AllDisjointClasses')), t(A, o('members'), L), ent_pair(L, C, D, G), t(X, r('type'), C), t(X, r('type'), D)],
129
+ ent_conflict('cax-adc', X, C, D, G));
130
+ implies([t(C, o('someValuesFrom'), D), t(C, o('onProperty'), P), t(X, P, Y), t(Y, r('type'), D)], t(X, r('type'), C));
131
+ implies([t(C, o('someValuesFrom'), o('Thing')), t(C, o('onProperty'), P), t(X, P, Y)], t(X, r('type'), C));
132
+ implies([t(C, o('allValuesFrom'), D), t(C, o('onProperty'), P), t(X, r('type'), C), t(X, P, Y)], t(Y, r('type'), D));
133
+ implies([t(C, o('hasValue'), Y), t(C, o('onProperty'), P), t(X, r('type'), C)], t(X, P, Y));
134
+ implies([t(C, o('hasValue'), Y), t(C, o('onProperty'), P), t(X, P, Y)], t(X, r('type'), C));
135
+ for (const n of [0, 1]) {
136
+ fact(ent_cardinality(n, n));
137
+ implied_by(ent_cardinality(literal(V, datatype('http://www.w3.org/2001/XMLSchema#nonNegativeInteger')), n),
138
+ regex_match('^[ \\t\\r\\n]*' + (n === 0 ? '[+-]?0+' : '[+]?0*1') + '[ \\t\\r\\n]*$', V));
139
+ }
140
+ implies([t(C, o('maxCardinality'), N), ent_cardinality(N, 0), t(C, o('onProperty'), P), t(X, r('type'), C), t(X, P, Y)],
141
+ ent_conflict('cls-maxc1', X, C, P, G));
142
+ implies([t(C, o('maxCardinality'), N), ent_cardinality(N, 1), t(C, o('onProperty'), P), t(X, r('type'), C), t(X, P, Y), t(X, P, Z)],
143
+ t(Y, o('sameAs'), Z));
144
+ implies([t(C, o('maxQualifiedCardinality'), N), ent_cardinality(N, K), t(C, o('onProperty'), P), t(C, o('onClass'), D),
145
+ t(X, r('type'), C), t(X, P, Y), t(Y, r('type'), D)], ent_qualified(C, K, X, P, Y, G));
146
+ implies([t(C, o('maxQualifiedCardinality'), N), ent_cardinality(N, K), t(C, o('onProperty'), P), t(C, o('onClass'), o('Thing')),
147
+ t(X, r('type'), C), t(X, P, Y)], ent_qualified(C, K, X, P, Y, G));
148
+ implies(ent_qualified(C, 0, X, P, Y, G), ent_conflict('cls-maxqc1', X, C, P, G));
149
+ implies([ent_qualified(C, 1, X, P, Y, G), ent_qualified(C, 1, X, P, Z, G)], t(Y, o('sameAs'), Z));
150
+
151
+ // Schema vocabulary (table 9).
152
+ implies(t(C, r('type'), o('Class')), [t(C, s('subClassOf'), C), t(C, o('equivalentClass'), C),
153
+ t(C, s('subClassOf'), o('Thing')), t(o('Nothing'), s('subClassOf'), C)]);
154
+ for (const [equivalent, sub] of [['equivalentClass', 'subClassOf'], ['equivalentProperty', 'subPropertyOf']]) {
155
+ implies(t(C, o(equivalent), D), [t(C, s(sub), D), t(D, s(sub), C)]);
156
+ implies([t(C, s(sub), D), t(D, s(sub), C)], t(C, o(equivalent), D));
157
+ }
158
+ for (const kind of ['ObjectProperty', 'DatatypeProperty']) {
159
+ implies(t(P, r('type'), o(kind)), [t(P, s('subPropertyOf'), P), t(P, o('equivalentProperty'), P)]);
160
+ }
161
+ for (const kind of ['hasValue', 'someValuesFrom', 'allValuesFrom']) {
162
+ if (kind !== 'hasValue') implies([t(C, o(kind), Y), t(C, o('onProperty'), P), t(D, o(kind), Z),
163
+ t(D, o('onProperty'), P), t(Y, s('subClassOf'), Z)], t(C, s('subClassOf'), D));
164
+ implies([t(C, o(kind), Y), t(C, o('onProperty'), P), t(D, o(kind), Y), t(D, o('onProperty'), Q), t(P, s('subPropertyOf'), Q)],
165
+ kind === 'allValuesFrom' ? t(D, s('subClassOf'), C) : t(C, s('subClassOf'), D));
166
+ }
167
+ `;
168
+
169
+ const OUTPUT = String.raw`
170
+ // Separate report triples from the ontology so a conflict report does not
171
+ // create more ontology consequences. All conflicts are retained, without
172
+ // stopping at the first contradiction or concluding arbitrary triples.
173
+ implies([ent_conflict(R, X, P, Y, G)], [
174
+ ent_report(B, r('type'), e('Conflict'), G), ent_report(B, e('rule'), literal(R, datatype('http://www.w3.org/2001/XMLSchema#string')), G),
175
+ ent_report(B, e('focus'), X, G), ent_report(B, e('left'), P, G), ent_report(B, e('right'), Y, G),
176
+ ]);
177
+ 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));
178
+ implies(ent_report(S, P, O, G), result_rdf(S, P, O, G));
179
+ query(result_rdf(S, P, O, G));
180
+ `;
package/src/formats.js CHANGED
@@ -13,6 +13,7 @@
13
13
  //
14
14
  // The odrl option adds the snapshot profile's validation and evaluation LS
15
15
  // to one Turtle input. Its vocabulary alone never enables the evaluator.
16
+ // rdfs and owlRl add the documented entailment rules to RDF inputs.
16
17
  //
17
18
  // The compiled program is ordinary LS: proofs, checking and --unused
18
19
  // apply to it. SRL execution functions capture a context that a saved proof
@@ -24,6 +25,7 @@ import { DEFAULT_GRAPH, parseRdf, rdfDocument, rdfFormat, writeRdf } from './rdf
24
25
  import { resultToN3, compileSources } from './n3.js';
25
26
  import { compileSrl, srlAnswers, srlQuads } from './srl.js';
26
27
  import { compileOdrl } from './odrl.js';
28
+ import { compileEntailment } from './entailment.js';
27
29
  import { write } from './writer.js';
28
30
  import { isRdfMessageLog, parseRdfMessages } from './messages.js';
29
31
 
@@ -45,7 +47,7 @@ export function rdfMessageFormat(name) {
45
47
  // Load inputs, given as [text, name] pairs, as one program. io may supply
46
48
  // readFile, for the documents N3 and IMPORTS name, and fileIri(name), the
47
49
  // base IRI of a file. Returns { kind, program, text, prefixes, compiled }:
48
- // kind is 'js', 'n3', 'srl' or 'odrl', text the compiled program,
50
+ // kind is 'js', 'n3', 'srl', 'odrl', 'rdfs' or 'owl-rl', text the compiled program,
49
51
  // and compiled what writing the conclusions needs.
50
52
  export function loadInputs(inputs, io = null, options = {}) {
51
53
  try {
@@ -57,7 +59,7 @@ export function loadInputs(inputs, io = null, options = {}) {
57
59
  }
58
60
  }
59
61
 
60
- function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false }) {
62
+ function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false, rdfs = false, owlRl = false }) {
61
63
  const kinds = inputs.map(([text, name]) => messageInputs?.has(name) ||
62
64
  (inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
63
65
  const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
@@ -65,7 +67,21 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
65
67
  (isRdfMessageLog(text) ? parseRdfMessages : parseRdf)(text, {
66
68
  format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k),
67
69
  });
68
- // ODRL logic is added only when requested, never from a document's terms.
70
+ // These rule sets are added only when requested, never from vocabulary.
71
+ if ((rdfs || owlRl) && odrl) throw new EyemindError('--odrl cannot be combined with --rdfs or --owl-rl');
72
+ if (rdfs || owlRl) {
73
+ if (inputs.some(([, name], k) => kinds[k] !== 'rdf' && name !== '<stdin>')) {
74
+ throw new EyemindError('--rdfs and --owl-rl take RDF inputs; standard input is Turtle');
75
+ }
76
+ const prefixes = {}, quads = [];
77
+ inputs.forEach(([text, name], k) => {
78
+ const parsed = name === '<stdin>' ? parseRdf(text, { format: 'turtle', base: baseOf(name), scope: scopeOf(inputs, name, k) }) : rdf(text, name, k);
79
+ if (parsed.triples) throw new EyemindError('--rdfs and --owl-rl take RDF graphs, not RDF Message Logs');
80
+ Object.assign(prefixes, parsed.prefixes);
81
+ quads.push(...parsed.quads);
82
+ });
83
+ return compileEntailment({ quads, prefixes }, { owl: owlRl, source: inputs.map(([, n]) => n).join(', ') });
84
+ }
69
85
  if (odrl) {
70
86
  if (inputs.length !== 1) throw new EyemindError('--odrl takes one Turtle snapshot containing policies, requests and SOTW');
71
87
  const [text, name] = inputs[0];
@@ -128,9 +144,9 @@ function importResolver(io) {
128
144
  };
129
145
  }
130
146
 
131
- // The default output format of a run: N3 for N3, Turtle for SRL and ODRL, and
132
- // eyemind's own text for a program.
133
- export const defaultFormat = (kind) => ({ n3: 'n3', srl: 'turtle', odrl: 'turtle' })[kind] ?? 'eyemind';
147
+ // The default output format: N3 for N3, Turtle for SRL and the RDF logic
148
+ // extensions, and eyemind's own text for a program.
149
+ export const defaultFormat = (kind) => ({ n3: 'n3', srl: 'turtle', odrl: 'turtle', rdfs: 'turtle', 'owl-rl': 'turtle' })[kind] ?? 'eyemind';
134
150
 
135
151
  // The conclusions of a run in an output format; null for eyemind's own text.
136
152
  // all also writes the given data. Throws when a conclusion is no triple.
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.5';
2
+ export const VERSION = '0.6.6';