eyemind 0.7.0 → 0.7.2
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/{MATHEMATICAL-ENGLISH.md → LOGICAL-ENGLISH.md} +107 -19
- package/README.md +52 -44
- package/SPEC.md +1 -1
- package/package.json +2 -2
- package/src/cli.js +10 -14
- package/src/formats.js +22 -22
- package/src/index.js +1 -1
- package/src/le-odrl.js +145 -0
- package/src/{me.js → le.js} +48 -19
- package/src/{entailment.js → owl2rl.js} +6 -7
- package/src/version.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Logical English
|
|
2
2
|
|
|
3
|
-
eyemind reads `.
|
|
3
|
+
eyemind reads `.le` files as the language defined here and compiles
|
|
4
4
|
them to ordinary Logic Script (LS). This is an input extension; the meaning of
|
|
5
5
|
the compiled program is defined by the [LS specification](https://eyereasoner.github.io/eyemind/SPEC).
|
|
6
6
|
It supports statements and computations in a fixed grammar. It does not parse
|
|
@@ -51,13 +51,14 @@ nesting is limited to 256 levels.
|
|
|
51
51
|
The following forms have the indicated LS meanings. `T`, `U` and the arguments
|
|
52
52
|
stand for terms; `class` and `relation` stand for names as defined above.
|
|
53
53
|
|
|
54
|
-
|
|
|
54
|
+
| LE form | LS term |
|
|
55
55
|
| --- | --- |
|
|
56
56
|
| `T is a class` | `class(T)` |
|
|
57
57
|
| `T is an class` | `class(T)` |
|
|
58
58
|
| `T is class` | `class(T)` |
|
|
59
59
|
| `T is a relation of U` | `relation(T, U)` |
|
|
60
60
|
| `T is an relation of U` | `relation(T, U)` |
|
|
61
|
+
| `T has relation U` | `relation(T, U)` |
|
|
61
62
|
| `relation(T, U, ...)` | The corresponding compound goal. |
|
|
62
63
|
| `relation` | An atom used as a goal, with arity zero. |
|
|
63
64
|
|
|
@@ -95,7 +96,7 @@ actual values must also satisfy LS's runtime requirements.
|
|
|
95
96
|
|
|
96
97
|
These additional forms are available in premises and questions:
|
|
97
98
|
|
|
98
|
-
|
|
|
99
|
+
| LE form | LS goal |
|
|
99
100
|
| --- | --- |
|
|
100
101
|
| `Y is the value of E` | `is(Y, E)` |
|
|
101
102
|
| `X is greater than E` | `gt(X, E)` |
|
|
@@ -172,11 +173,98 @@ derived conclusions, following LS's default; given facts alone are not printed.
|
|
|
172
173
|
`It is impossible that` compiles to an LS contradiction with the stated body.
|
|
173
174
|
`Contradiction.` is an unconditional contradiction, also used to serialize a
|
|
174
175
|
run's `'false'` conclusion. Contradictions halt reasoning with exit code 65;
|
|
175
|
-
they do not produce the continuing RDF conflict reports of `--
|
|
176
|
+
they do not produce the continuing RDF conflict reports of `--owl2rl`.
|
|
177
|
+
|
|
178
|
+
## Examples combining features
|
|
179
|
+
|
|
180
|
+
These programs use the grammar above without additional syntax:
|
|
181
|
+
|
|
182
|
+
| Example | What it demonstrates |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| [Shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le) | Bounded recursive histories, exact costs and minimum selection by absence, retaining ties. |
|
|
185
|
+
| [River crossing](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le) | Compound states, repeated-variable matching, safety constraints and complete plans within a bound. |
|
|
186
|
+
| [Pell equations](https://eyereasoner.github.io/eyemind/examples/deck/pell-equation-le) | Recursive arithmetic beyond binary64 integer precision and exact polynomial checks. |
|
|
187
|
+
| [Course certificates](https://eyereasoner.github.io/eyemind/examples/deck/course-certificates-le) | Recursive requirements, absence of a counterexample, shared existential witnesses and witnesses containing earlier witnesses. |
|
|
188
|
+
| [Symbolic differentiation](https://eyereasoner.github.io/eyemind/examples/deck/symbolic-derivative-le) | Structural recursion over expression trees, constructed derivatives and evaluation at separate points. |
|
|
189
|
+
|
|
190
|
+
Their decks state the modeled assumptions and what the checked proofs establish.
|
|
191
|
+
Bounds and finite expression domains are explicit in the programs.
|
|
192
|
+
|
|
193
|
+
## ODRL snapshots
|
|
194
|
+
|
|
195
|
+
An LE file can explicitly select the existing ODRL snapshot evaluator:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
Use ODRL snapshot logic with namespace "https://example.org/handicap-card#".
|
|
199
|
+
|
|
200
|
+
evaluation is an evaluation.
|
|
201
|
+
evaluation has policy eligibility.
|
|
202
|
+
evaluation has request issueAlice.
|
|
203
|
+
evaluation has conflictStrategy prohibit.
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
This directive must be the first sentence of one file. The remainder contains
|
|
207
|
+
ground facts using the snapshot vocabulary, without rules or questions. The
|
|
208
|
+
compiler maps those facts to RDF and includes the validation, evaluation and
|
|
209
|
+
reporting LS of `src/odrl.js`. The same
|
|
210
|
+
[snapshot profile](https://eyereasoner.github.io/eyemind/#odrl-snapshots) applies
|
|
211
|
+
to Turtle and LE, including missing observations, unsupported policy features
|
|
212
|
+
and conflict strategies. Vocabulary by itself does not enable evaluation.
|
|
213
|
+
|
|
214
|
+
Names expand as follows, with case preserved:
|
|
215
|
+
|
|
216
|
+
| LE form or name | RDF mapping |
|
|
217
|
+
| --- | --- |
|
|
218
|
+
| An ordinary individual name | An IRI formed by appending it to the declared namespace. |
|
|
219
|
+
| Classes `evaluation`, `request`, `state` | `eval:Evaluation`, `eval:Request`, `eval:State`. |
|
|
220
|
+
| Classes `policy`, `agreement`, `permission`, `prohibition`, `constraint`, `action` | `odrl:Set`, `odrl:Agreement`, `odrl:Permission`, `odrl:Prohibition`, `odrl:Constraint`, `odrl:Action`. |
|
|
221
|
+
| Classes `assetCollection`, `partyCollection` | ODRL collection classes, rejected by the snapshot profile. |
|
|
222
|
+
| Properties `policy`, `request`, `state`, `subject`, `conflictStrategy` | The corresponding `eval:` properties. |
|
|
223
|
+
| Properties `profile`, `permission`, `prohibition`, `assignee`, `assigner`, `action`, `target`, `constraint`, `leftOperand`, `operator`, `rightOperand` | The corresponding `odrl:` properties. |
|
|
224
|
+
| Property `policyConflict` | `odrl:conflict`, the policy-local strategy. |
|
|
225
|
+
| Property `type` | `rdf:type`. |
|
|
226
|
+
| An otherwise unknown class or property | An IRI in the declared namespace; validation still applies. |
|
|
227
|
+
| Values `snapshotProfile`, `perm`, `prohibit`, `invalid`, `eq`, `neq`, `gt`, `gteq`, `lt`, `lteq` | `eval:SnapshotProfile` or the corresponding ODRL strategy/operator IRIs. |
|
|
228
|
+
| Values `true`, `false` | Boolean RDF literals. Quoting does not change an LE name into an RDF string literal. |
|
|
229
|
+
| An integer or float | An exact RDF integer or an `xsd:double` literal. |
|
|
230
|
+
|
|
231
|
+
The unsupported ODRL properties `duty`, `obligation`, `inheritFrom`, `includedIn`,
|
|
232
|
+
`partOf` and `refinement` retain their ODRL IRIs so the shared validator can
|
|
233
|
+
report them. Explicit RDF values such as `iri("https://example.org/item")` and
|
|
234
|
+
`literal("text", datatype("http://www.w3.org/2001/XMLSchema#string"))` retain
|
|
235
|
+
their terms. `rdf(S, P, O)` facts allow any explicit RDF predicate without an
|
|
236
|
+
abbreviation. A snapshot still has one default graph.
|
|
237
|
+
|
|
238
|
+
The [handicap-card LE example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card-le)
|
|
239
|
+
contains the complete policies, requests and SOTW. Run it without CLI switches:
|
|
240
|
+
|
|
241
|
+
```sh
|
|
242
|
+
eyemind examples/handicap-card-le.le
|
|
243
|
+
eyemind --program examples/handicap-card-le.le > /tmp/handicap-card-le.js
|
|
244
|
+
eyemind --to turtle /tmp/handicap-card-le.js
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Its default output is an LE report whose first sentence is
|
|
248
|
+
`Use ODRL vocabulary with namespace "https://example.org/handicap-card#".`.
|
|
249
|
+
That directive reads RDF data without evaluating policies. This makes the report
|
|
250
|
+
readable as input again, preserving every RDF fact and witness. Report properties
|
|
251
|
+
use `has`; for example `issueAlice has decision allowed.`. Status values
|
|
252
|
+
`allowed`, `prohibited`, `notApplicable`, `undetermined`, `valid` and
|
|
253
|
+
`invalidReport` name the corresponding `eval:` IRIs. Report classes include
|
|
254
|
+
`evaluationReport`, `conflict`, `validationError` and `uncertainty`.
|
|
255
|
+
`conflict` as a property means `eval:conflict`; `applicablePermission`,
|
|
256
|
+
`applicableProhibition` and `reportConstraint` distinguish the report's
|
|
257
|
+
`eval:permission`, `eval:prohibition` and `eval:constraint` links from ODRL
|
|
258
|
+
input properties. Other report fields retain their `eval:` names. An IRI with
|
|
259
|
+
no unambiguous abbreviation stays explicit, including IRIs inside witness keys.
|
|
260
|
+
|
|
261
|
+
Both ODRL directives take a single LE file and reject mixed-in ordinary LE
|
|
262
|
+
rules or questions. `--goal` can query their compiled LS program. The normal
|
|
263
|
+
`--odrl` switch continues to select the Turtle snapshot compiler.
|
|
176
264
|
|
|
177
265
|
## Output, compilation and checking
|
|
178
266
|
|
|
179
|
-
|
|
267
|
+
LE inputs default to `.le` conclusions. Each answer becomes a sentence:
|
|
180
268
|
|
|
181
269
|
```text
|
|
182
270
|
Socrates is a mortal.
|
|
@@ -186,7 +274,7 @@ Alice is an owner of witness(rule 4, Y, Alice).
|
|
|
186
274
|
|
|
187
275
|
`witness(rule 4, Y, Alice)` names the witness for existential variable `Y` of
|
|
188
276
|
rule 4 with argument Alice. It reads back as `skolem(4, 'Y', ['Alice'])` in LS.
|
|
189
|
-
The label `Y` in this position is a name, independent of any declared
|
|
277
|
+
The label `Y` in this position is a name, independent of any declared LE
|
|
190
278
|
variable. A label outside the variable-name syntax is quoted. Additional
|
|
191
279
|
arguments follow as more comma-separated terms; a witness without arguments
|
|
192
280
|
is `witness(rule 4, Y)`. The rule number, label and arguments all contribute
|
|
@@ -196,28 +284,28 @@ Unary and binary relations use the class and relation-of forms; relations with
|
|
|
196
284
|
more arguments use calls. Names are quoted when required to preserve their
|
|
197
285
|
meaning. Compound names are quoted. Variable answers use `For every X0 and X1,
|
|
198
286
|
...`, consistently renaming their variables while retaining sharing. A conjunctive
|
|
199
|
-
answer uses `and`. These sentences can be loaded as facts in another `.
|
|
287
|
+
answer uses `and`. These sentences can be loaded as facts in another `.le`
|
|
200
288
|
program. An empty answer set is `# No conclusions.`. The writer rejects goals
|
|
201
289
|
outside these relational forms instead of silently changing their meaning.
|
|
202
290
|
|
|
203
291
|
```sh
|
|
204
|
-
eyemind examples/socrates-
|
|
205
|
-
eyemind --program examples/socrates-
|
|
206
|
-
eyemind --to
|
|
207
|
-
eyemind --proof examples/socrates-
|
|
208
|
-
eyemind --check-proof /tmp/socrates-
|
|
292
|
+
eyemind examples/socrates-le.le
|
|
293
|
+
eyemind --program examples/socrates-le.le > /tmp/socrates-le.js
|
|
294
|
+
eyemind --to le /tmp/socrates-le.js
|
|
295
|
+
eyemind --proof examples/socrates-le.le > /tmp/socrates-le-proof.js
|
|
296
|
+
eyemind --check-proof /tmp/socrates-le-proof.js examples/socrates-le.le
|
|
209
297
|
```
|
|
210
298
|
|
|
211
|
-
Multiple `.
|
|
212
|
-
input formats or the RDF logic switches. Standard input remains LS; `--to
|
|
213
|
-
can write supported LS conclusions as
|
|
214
|
-
defaults to LS output; add `--to
|
|
215
|
-
output, without changing
|
|
299
|
+
Multiple `.le` files form one program in file order; they do not mix with other
|
|
300
|
+
input formats or the RDF logic switches. Standard input remains LS; `--to le`
|
|
301
|
+
can write supported LS conclusions as LE. `--goal` uses LS goal syntax and
|
|
302
|
+
defaults to LS output; add `--to le` for LE output. `--all` applies to RDF and N3
|
|
303
|
+
output, without changing LE's selected conclusions.
|
|
216
304
|
|
|
217
305
|
The compiler reads data without executing it and emits standalone `.js` LS
|
|
218
306
|
using explicit constructors to retain names and numeric types. Comments in the
|
|
219
307
|
compiled text identify the source file and sentence line. Parser errors name
|
|
220
|
-
that location.
|
|
308
|
+
that location. LE runs use LS's usual work bounds, which can be overridden by
|
|
221
309
|
the CLI. Existential or recursive rules can still have an infinite closure.
|
|
222
310
|
|
|
223
311
|
Proofs and check reports are `.js` documents and use the existing LS checker.
|
package/README.md
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
[](https://doi.org/10.5281/zenodo.23824021)
|
|
4
4
|
[](https://www.npmjs.com/package/eyemind)
|
|
5
5
|
|
|
6
|
-
eyemind is a dependency-free reasoner for **Logic Script (LS)**, a rule language with JavaScript syntax. LS programs state facts, rules, and queries; eyemind draws conclusions using forward and backward reasoning, and can produce proofs that a separate checker verifies against your program. It interoperates with **RDF 1.2**, **Notation3 (N3)** and **SPARQL 1.2 RL (SRL)**: RDF supplies data, and N3 and SRL compile to LS programs whose proofs use the same checker.
|
|
6
|
+
eyemind is a dependency-free reasoner for **Logic Script (LS)**, a rule language with JavaScript syntax. LS programs state facts, rules, and queries; eyemind draws conclusions using forward and backward reasoning, and can produce proofs that a separate checker verifies against your program. It interoperates with **RDF 1.2**, **Notation3 (N3)** and **SPARQL 1.2 RL (SRL)**: RDF supplies data, and N3 and SRL compile to LS programs whose proofs use the same checker. **Logical English (LE)** also compiles to LS and writes `.le` conclusions. It runs as a command-line program, a JavaScript library, and a browser application.
|
|
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 147 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
|
|
|
@@ -18,12 +18,12 @@ The playground runs programs in your browser; the specification defines the lang
|
|
|
18
18
|
- [Terms and names](#terms-and-names)
|
|
19
19
|
- [Deriving rules](#deriving-rules)
|
|
20
20
|
- [Inspecting rules](#inspecting-rules)
|
|
21
|
-
- [
|
|
21
|
+
- [Logical English](#logical-english)
|
|
22
22
|
- [RDF 1.2](#rdf-12)
|
|
23
23
|
- [Notation3](#notation3)
|
|
24
24
|
- [RDF Messages](#rdf-messages)
|
|
25
25
|
- [SPARQL 1.2 RL](#sparql-12-rl)
|
|
26
|
-
- [
|
|
26
|
+
- [OWL 2 RL](#owl-2-rl)
|
|
27
27
|
- [ODRL snapshots](#odrl-snapshots)
|
|
28
28
|
- [How eyemind reasons](#how-eyemind-reasons)
|
|
29
29
|
- [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
|
|
@@ -180,9 +180,9 @@ query(test(X, Y))
|
|
|
180
180
|
|
|
181
181
|
The answer is `test(a(A), c(A))`, with the shared variable preserved. Inspection sees ordinary source rules only, not facts, queries, generators or itself, and its proof step names the source rule it matched. See the [rule inspection deck](https://eyereasoner.github.io/eyemind/examples/deck/rule-inspection) and [SPEC §6.3](https://eyereasoner.github.io/eyemind/SPEC#63-source-rule-inspection).
|
|
182
182
|
|
|
183
|
-
###
|
|
183
|
+
### Logical English
|
|
184
184
|
|
|
185
|
-
A `.
|
|
185
|
+
A `.le` file is [Logical English](https://eyereasoner.github.io/eyemind/LOGICAL-ENGLISH),
|
|
186
186
|
compiled deterministically into LS. Facts, class rules, quantified if/then rules,
|
|
187
187
|
calculations, explicit absence tests, existential conclusions, questions and
|
|
188
188
|
contradictions have a fixed grammar. Unsupported prose is an error.
|
|
@@ -194,31 +194,41 @@ Find every X such that X is mortal.
|
|
|
194
194
|
```
|
|
195
195
|
|
|
196
196
|
```sh
|
|
197
|
-
eyemind examples/socrates-
|
|
198
|
-
eyemind --program examples/socrates-
|
|
199
|
-
eyemind --to
|
|
200
|
-
eyemind --proof examples/socrates-
|
|
201
|
-
eyemind --check-proof /tmp/socrates-
|
|
197
|
+
eyemind examples/socrates-le.le > /tmp/socrates-le.le
|
|
198
|
+
eyemind --program examples/socrates-le.le > /tmp/socrates-le.js
|
|
199
|
+
eyemind --to le /tmp/socrates-le.js
|
|
200
|
+
eyemind --proof examples/socrates-le.le > /tmp/socrates-le-proof.js
|
|
201
|
+
eyemind --check-proof /tmp/socrates-le-proof.js examples/socrates-le.le
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
-
Conclusions default to `.
|
|
205
|
-
another
|
|
204
|
+
Conclusions default to `.le`: `Socrates is a mortal.`. They can supply facts to
|
|
205
|
+
another LE program. `--to le` also writes supported LS conclusions in this
|
|
206
206
|
format. Proofs and check reports remain `.js`, and the standalone compilation
|
|
207
207
|
contains all its LS clauses with source sentence locations. The existing checker
|
|
208
208
|
checks the compiled LS; the documented grammar and compiler tests define the
|
|
209
209
|
English translation.
|
|
210
210
|
|
|
211
|
-
Multiple `.
|
|
211
|
+
Multiple `.le` files form one program. Names are case-sensitive, variables such
|
|
212
212
|
as `X` and `Y1` are explicitly declared within each sentence, and integers stay
|
|
213
213
|
exact. Arithmetic and absence tests require their inputs from earlier premises;
|
|
214
214
|
absence is written `it is not known that`, with LS's stratified meaning. A rule
|
|
215
|
-
can introduce witnesses with `there exists`.
|
|
215
|
+
can introduce witnesses with `there exists`. LE uses the ordinary LS resource
|
|
216
216
|
bounds; recursive and existential rules can still have an infinite closure.
|
|
217
217
|
|
|
218
|
-
The playground loads
|
|
219
|
-
Try [Socrates](https://eyereasoner.github.io/eyemind/examples/deck/socrates-
|
|
220
|
-
[exact squares](https://eyereasoner.github.io/eyemind/examples/deck/squares-
|
|
221
|
-
and [record creation](https://eyereasoner.github.io/eyemind/examples/deck/records-
|
|
218
|
+
The playground loads LE examples and downloads conclusions as `output.le`.
|
|
219
|
+
Try [Socrates](https://eyereasoner.github.io/eyemind/examples/deck/socrates-le),
|
|
220
|
+
[exact squares](https://eyereasoner.github.io/eyemind/examples/deck/squares-le)
|
|
221
|
+
and [record creation](https://eyereasoner.github.io/eyemind/examples/deck/records-le).
|
|
222
|
+
For examples combining more features, try
|
|
223
|
+
[shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le),
|
|
224
|
+
[river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le),
|
|
225
|
+
[large Pell solutions](https://eyereasoner.github.io/eyemind/examples/deck/pell-equation-le),
|
|
226
|
+
[symbolic differentiation](https://eyereasoner.github.io/eyemind/examples/deck/symbolic-derivative-le),
|
|
227
|
+
or [course certificates](https://eyereasoner.github.io/eyemind/examples/deck/course-certificates-le).
|
|
228
|
+
The [handicap-card LE snapshot](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card-le)
|
|
229
|
+
explicitly selects the shared ODRL evaluator with `Use ODRL snapshot logic with
|
|
230
|
+
namespace ...`. It expresses the Turtle example's policies and SOTW as English
|
|
231
|
+
property facts and writes the same decisions and conflicts as an LE report.
|
|
222
232
|
|
|
223
233
|
### RDF 1.2
|
|
224
234
|
|
|
@@ -428,20 +438,20 @@ SRL programs for deployment dependencies, route distances, ancestry, inventory,
|
|
|
428
438
|
invoices, provenance and Unicode strings. Each has saved Turtle output, a
|
|
429
439
|
proof, a check report and a deck, and runs in the playground.
|
|
430
440
|
|
|
431
|
-
###
|
|
441
|
+
### OWL 2 RL
|
|
432
442
|
|
|
433
|
-
`--
|
|
443
|
+
`--owl2rl` adds inference rules, including RDFS, to RDF inputs. The files still
|
|
434
444
|
use their usual RDF extensions; standard input is Turtle. A graph's use of
|
|
435
|
-
RDFS or OWL vocabulary alone does not enable
|
|
436
|
-
has
|
|
445
|
+
RDFS or OWL vocabulary alone does not enable the extension. The playground
|
|
446
|
+
has the same switch and preserves it in saved sessions and shared links.
|
|
437
447
|
|
|
438
448
|
```sh
|
|
439
|
-
eyemind --
|
|
440
|
-
eyemind --
|
|
441
|
-
eyemind --
|
|
449
|
+
eyemind --owl2rl examples/people-owl2rl.ttl
|
|
450
|
+
eyemind --owl2rl examples/family-owl2rl.ttl > /tmp/family-report.ttl
|
|
451
|
+
eyemind --owl2rl --program examples/family-owl2rl.ttl > /tmp/family.js
|
|
442
452
|
eyemind --to turtle /tmp/family.js
|
|
443
|
-
eyemind --
|
|
444
|
-
eyemind --
|
|
453
|
+
eyemind --owl2rl --proof examples/family-owl2rl.ttl > /tmp/family-proof.js
|
|
454
|
+
eyemind --owl2rl --check-proof /tmp/family-proof.js examples/family-owl2rl.ttl
|
|
445
455
|
```
|
|
446
456
|
|
|
447
457
|
The generated `.js` contains the data, inference rules and reporting rules;
|
|
@@ -452,10 +462,10 @@ need `--to trig` or `--to n-quads` to retain their graph names.
|
|
|
452
462
|
|
|
453
463
|
The implemented rules are:
|
|
454
464
|
|
|
455
|
-
|
|
|
465
|
+
| Rule family | Coverage |
|
|
456
466
|
| --- | --- |
|
|
457
|
-
|
|
|
458
|
-
|
|
|
467
|
+
| 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. |
|
|
468
|
+
| 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. |
|
|
459
469
|
|
|
460
470
|
The OWL rules implement the non-datatype rule families of
|
|
461
471
|
[OWL 2 RL/RDF tables 4–7 and 9](https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs),
|
|
@@ -464,9 +474,8 @@ They operate on the terms present in each graph. RDFS axiomatic triples,
|
|
|
464
474
|
datatype value-space reasoning (OWL table 8), ontology imports and OWL
|
|
465
475
|
constructs outside these rule families are not implemented. Literal equality
|
|
466
476
|
uses the RDF-to-LS representation, without general datatype normalization.
|
|
467
|
-
|
|
468
|
-
for arbitrary RDFS or OWL ontologies.
|
|
469
|
-
enabling both adds the rules once. They take RDF inputs and cannot be combined
|
|
477
|
+
This switch does not validate profile membership or certify completeness
|
|
478
|
+
for arbitrary RDFS or OWL ontologies. It takes RDF inputs and cannot be combined
|
|
470
479
|
with `--odrl` or `--stream-messages`.
|
|
471
480
|
|
|
472
481
|
OWL contradictions appear as RDF records of type `ent:Conflict`, where
|
|
@@ -479,8 +488,8 @@ conflict set only means these rules detected none; it is not a full consistency
|
|
|
479
488
|
guarantee. RDFS domain and range infer types rather than checking required
|
|
480
489
|
fields, and missing facts alone do not establish a conflict.
|
|
481
490
|
|
|
482
|
-
Try the [people directory](https://eyereasoner.github.io/eyemind/examples/deck/people-
|
|
483
|
-
and [family ontology](https://eyereasoner.github.io/eyemind/examples/deck/family-
|
|
491
|
+
Try the [people directory](https://eyereasoner.github.io/eyemind/examples/deck/people-owl2rl)
|
|
492
|
+
and [family ontology](https://eyereasoner.github.io/eyemind/examples/deck/family-owl2rl).
|
|
484
493
|
|
|
485
494
|
### ODRL snapshots
|
|
486
495
|
|
|
@@ -711,7 +720,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
711
720
|
|
|
712
721
|
| Option | Meaning |
|
|
713
722
|
| --- | --- |
|
|
714
|
-
| (none) | Load the files, or standard input, as one program and print its conclusions. `.js` files and standard input are Logic Script, `.ttl`, `.trig`, `.nt` and `.nq` files RDF data, `.n3` Notation3, `.srl` a SPARQL 1.2 RL rule set and `.
|
|
723
|
+
| (none) | Load the files, or standard input, as one program and print its conclusions. `.js` files and standard input are Logic Script, `.ttl`, `.trig`, `.nt` and `.nq` files RDF data, `.n3` Notation3, `.srl` a SPARQL 1.2 RL rule set and `.le` Logical English. |
|
|
715
724
|
| `-p`, `--proof` | Print the proof instead. |
|
|
716
725
|
| `-c`, `--prove-and-check` | Generate a proof, check it, and print the checked answers with the report. |
|
|
717
726
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
@@ -720,13 +729,12 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
720
729
|
| `--unused` | List the clauses that make no difference to the conclusions. |
|
|
721
730
|
| `--stream-messages` | Read an RDF Message Log and run the rules independently per message; Node reads files, stdin and HTTP(S) incrementally. |
|
|
722
731
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
723
|
-
| `--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
|
|
724
|
-
| `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3`, `
|
|
732
|
+
| `--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 2 RL program has 1000000, 100000 and 1000000000. |
|
|
733
|
+
| `--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, RDFS and OWL 2 RL, eyemind otherwise. |
|
|
725
734
|
| `--all` | With RDF or N3 output, write the given data too. |
|
|
726
735
|
| `--program` | Print the program the inputs compile to. |
|
|
727
736
|
| `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
|
|
728
|
-
| `--
|
|
729
|
-
| `--owl-rl` | Add the documented OWL-RL inference rules and RDF conflict reports to RDF inputs; includes `--rdfs`. |
|
|
737
|
+
| `--owl2rl` | Add the documented OWL 2 RL inference rules, including RDFS, and RDF conflict reports to RDF inputs. |
|
|
730
738
|
| `--base IRI` | Resolve relative IRIs of the inputs against `IRI` instead of each file's location. |
|
|
731
739
|
| `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
|
|
732
740
|
|
|
@@ -736,7 +744,7 @@ each goal as a data document, with an array denoting conjunction. With
|
|
|
736
744
|
`--check-proof`, supply the original goals the proof answers.
|
|
737
745
|
An option that takes a value requires it immediately afterward; another
|
|
738
746
|
option, including a short alias such as `-v`, is reported as a missing value.
|
|
739
|
-
With `--goal`, answers default to eyemind terms even for
|
|
747
|
+
With `--goal`, answers default to eyemind terms even for LE, N3, SRL, ODRL, RDFS and OWL 2 RL inputs;
|
|
740
748
|
use `--to` to request another output format.
|
|
741
749
|
|
|
742
750
|
With `--prove-and-check`, reasoning bounds and `--stats` apply to proof
|
|
@@ -765,7 +773,7 @@ They are outside the language and proof specification.
|
|
|
765
773
|
|
|
766
774
|
The JavaScript implementation defaults to a depth limit of 1000000, an
|
|
767
775
|
inference limit of 1000000 and a limit of 1000 forward rounds per stratum.
|
|
768
|
-
Compiled N3, SRL, ODRL
|
|
776
|
+
Compiled N3, SRL, ODRL and OWL 2 RL programs use 1000000, 1000000000 and 100000 respectively.
|
|
769
777
|
Each supplied bound must be a positive integer no greater than
|
|
770
778
|
9007199254740991.
|
|
771
779
|
|
|
@@ -837,7 +845,7 @@ console.log(result.bindings);
|
|
|
837
845
|
console.log(checkProof(socrates, result.proof, { goals }).valid);
|
|
838
846
|
```
|
|
839
847
|
|
|
840
|
-
`run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `
|
|
848
|
+
`run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `compileLe([[text, filename], ...])` returns the compiled LS `program` and standalone JavaScript `text`; `writeLe(run(program))` writes its conclusions as LE.
|
|
841
849
|
|
|
842
850
|
## What is deliberately absent
|
|
843
851
|
|
package/SPEC.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"src/",
|
|
18
18
|
"README.md",
|
|
19
19
|
"SPEC.md",
|
|
20
|
-
"
|
|
20
|
+
"LOGICAL-ENGLISH.md",
|
|
21
21
|
"LICENSE.md"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
package/src/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { srlContextFromProof } from './srl.js';
|
|
|
10
10
|
export const HELP = `Usage: eyemind [OPTION ...] [FILE ...]
|
|
11
11
|
Logic Script (LS) programs use JavaScript syntax. Forward rules run to a fixpoint.
|
|
12
12
|
Files are read by extension: .js as LS, .ttl, .trig, .nt and .nq as RDF 1.2 data,
|
|
13
|
-
.n3 as Notation3, .srl as SPARQL 1.2 RL and .
|
|
13
|
+
.n3 as Notation3, .srl as SPARQL 1.2 RL and .le as Logical English,
|
|
14
14
|
all compiled to LS.
|
|
15
15
|
-p, --proof Print a proof of the conclusions
|
|
16
16
|
-c, --prove-and-check Generate a proof and check it against the input program
|
|
@@ -24,13 +24,12 @@ all compiled to LS.
|
|
|
24
24
|
--max-iterations N Bound forward rounds per stratum (default 1000)
|
|
25
25
|
--max-inferences N Bound reasoning work (default 1000000)
|
|
26
26
|
--to FORMAT Write the conclusions as turtle, trig, n-triples,
|
|
27
|
-
n-quads, n3,
|
|
28
|
-
for SRL, ODRL
|
|
27
|
+
n-quads, n3, le or eyemind (default: le for LE, n3 for N3, turtle
|
|
28
|
+
for SRL, ODRL or OWL 2 RL, eyemind otherwise or with --goal)
|
|
29
29
|
--all With RDF or N3 output, write the given data too
|
|
30
30
|
--program Print the program the inputs compile to
|
|
31
31
|
--odrl Add ODRL validation and evaluation to one Turtle snapshot
|
|
32
|
-
--
|
|
33
|
-
--owl-rl Add OWL-RL inference and conflict rules to RDF inputs
|
|
32
|
+
--owl2rl Add OWL 2 RL inference, including RDFS, and conflict rules
|
|
34
33
|
--base IRI Resolve relative IRIs of the inputs against IRI
|
|
35
34
|
--stream-messages Run the rules independently for each RDF Message
|
|
36
35
|
-v, --version Print the version
|
|
@@ -70,8 +69,7 @@ export function main(argv, io) {
|
|
|
70
69
|
let base = null;
|
|
71
70
|
let streamMessages = false;
|
|
72
71
|
let odrl = false;
|
|
73
|
-
let
|
|
74
|
-
let owlRl = false;
|
|
72
|
+
let owl2rl = false;
|
|
75
73
|
const filePositions = new Set();
|
|
76
74
|
for (let i = 0; i < argv.length; i++) {
|
|
77
75
|
const arg = ALIASES.get(argv[i]) ?? argv[i];
|
|
@@ -99,10 +97,8 @@ export function main(argv, io) {
|
|
|
99
97
|
printProgram = true;
|
|
100
98
|
} else if (arg === '--odrl') {
|
|
101
99
|
odrl = true;
|
|
102
|
-
} else if (arg === '--
|
|
103
|
-
|
|
104
|
-
} else if (arg === '--owl-rl') {
|
|
105
|
-
owlRl = true;
|
|
100
|
+
} else if (arg === '--owl2rl') {
|
|
101
|
+
owl2rl = true;
|
|
106
102
|
} else if (arg === '--stream-messages') {
|
|
107
103
|
streamMessages = true;
|
|
108
104
|
} else if (arg === '--check-proof' || arg === '--goal' || arg === '--to' || arg === '--base' || Object.hasOwn(LIMITS, arg)) {
|
|
@@ -151,7 +147,7 @@ export function main(argv, io) {
|
|
|
151
147
|
if (files.filter((file) => file === '-').length > 1) throw new UsageError('stdin can only be read once');
|
|
152
148
|
if (streamMessages) {
|
|
153
149
|
if (odrl) throw new UsageError('--odrl cannot be combined with --stream-messages');
|
|
154
|
-
if (
|
|
150
|
+
if (owl2rl) throw new UsageError('--owl2rl cannot be combined with --stream-messages');
|
|
155
151
|
if (proofFile !== null || options.proof || proveAndCheck || printProgram || unused) {
|
|
156
152
|
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');
|
|
157
153
|
}
|
|
@@ -192,7 +188,7 @@ export function main(argv, io) {
|
|
|
192
188
|
}
|
|
193
189
|
const document = proofFile === null ? null : readSource(proofFile, io);
|
|
194
190
|
const loaded = loadInputs(files.map((file) => [readSource(file, io), file === '-' ? '<stdin>' : file]), io,
|
|
195
|
-
{ base, messageInputs: io.messageInputs, odrl,
|
|
191
|
+
{ base, messageInputs: io.messageInputs, odrl, owl2rl,
|
|
196
192
|
srlContext: document !== null && files.some((file) => inputKind(file) === 'srl') ? srlContextFromProof(document) : null });
|
|
197
193
|
const program = loaded.program;
|
|
198
194
|
if (printProgram) {
|
|
@@ -200,7 +196,7 @@ export function main(argv, io) {
|
|
|
200
196
|
return 0;
|
|
201
197
|
}
|
|
202
198
|
// N3, SRL and the RDF logic extensions have larger default bounds.
|
|
203
|
-
if (!['js', '
|
|
199
|
+
if (!['js', 'le'].includes(loaded.kind)) for (const [name, value] of Object.entries(COMPILED_LIMITS)) options[name] ??= value;
|
|
204
200
|
if (proofFile !== null) {
|
|
205
201
|
const report = checkProof(program, document, { goals });
|
|
206
202
|
stdout(asJson ? `${JSON.stringify(publicReport(report), null, 2)}\n` : checkReport(report));
|
package/src/formats.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The inputs of a run in other formats than Logic Script, and its output as
|
|
2
|
-
// RDF, N3 or
|
|
2
|
+
// RDF, N3 or Logical English.
|
|
3
3
|
//
|
|
4
4
|
// A file's extension says what it holds:
|
|
5
5
|
//
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
// rule set, its base graph
|
|
11
11
|
// .n3 Notation3, compiled to an LS program
|
|
12
12
|
// .srl a SPARQL 1.2 RL rule set, compiled to one
|
|
13
|
-
// .
|
|
13
|
+
// .le Logical English, compiled to LS
|
|
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
|
-
//
|
|
17
|
+
// owl2rl adds OWL 2 RL rules, including RDFS, to RDF inputs.
|
|
18
18
|
//
|
|
19
19
|
// The compiled program is ordinary LS: proofs, checking and --unused
|
|
20
20
|
// apply to it. SRL execution functions capture a context that a saved proof
|
|
@@ -26,19 +26,19 @@ import { DEFAULT_GRAPH, parseRdf, rdfDocument, rdfFormat, writeRdf } from './rdf
|
|
|
26
26
|
import { resultToN3, compileSources } from './n3.js';
|
|
27
27
|
import { compileSrl, srlAnswers, srlQuads } from './srl.js';
|
|
28
28
|
import { compileOdrl } from './odrl.js';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import { compileOwl2rl } from './owl2rl.js';
|
|
30
|
+
import { compileLe, writeLe } from './le.js';
|
|
31
31
|
import { write } from './writer.js';
|
|
32
32
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
33
33
|
|
|
34
|
-
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3', '
|
|
34
|
+
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3', 'le'];
|
|
35
35
|
|
|
36
|
-
// What a file holds: 'js', 'rdf', 'n3', 'srl' or '
|
|
36
|
+
// What a file holds: 'js', 'rdf', 'n3', 'srl' or 'le'.
|
|
37
37
|
export function inputKind(name) {
|
|
38
38
|
if (rdfFormat(name)) return 'rdf';
|
|
39
39
|
if (/\.n3$/i.test(name)) return 'n3';
|
|
40
40
|
if (/\.srl$/i.test(name)) return 'srl';
|
|
41
|
-
if (/\.
|
|
41
|
+
if (/\.le$/i.test(name)) return 'le';
|
|
42
42
|
return 'js';
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -50,7 +50,7 @@ export function rdfMessageFormat(name) {
|
|
|
50
50
|
// Load inputs, given as [text, name] pairs, as one program. io may supply
|
|
51
51
|
// readFile, for the documents N3 and IMPORTS name, and fileIri(name), the
|
|
52
52
|
// base IRI of a file. Returns { kind, program, text, prefixes, compiled }:
|
|
53
|
-
// kind is 'js', 'n3', 'srl', '
|
|
53
|
+
// kind is 'js', 'n3', 'srl', 'le', 'odrl' or 'owl2rl', text the compiled program,
|
|
54
54
|
// and compiled what writing the conclusions needs.
|
|
55
55
|
export function loadInputs(inputs, io = null, options = {}) {
|
|
56
56
|
try {
|
|
@@ -62,7 +62,7 @@ export function loadInputs(inputs, io = null, options = {}) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false,
|
|
65
|
+
function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false, owl2rl = false }) {
|
|
66
66
|
const kinds = inputs.map(([text, name]) => messageInputs?.has(name) ||
|
|
67
67
|
(inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
|
|
68
68
|
const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
|
|
@@ -71,25 +71,25 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
|
|
|
71
71
|
format: rdfFormat(name) ?? 'trig', base: baseOf(name), scope: scopeOf(inputs, name, k),
|
|
72
72
|
});
|
|
73
73
|
// These rule sets are added only when requested, never from vocabulary.
|
|
74
|
-
if (kinds.includes('
|
|
75
|
-
if (kinds.some((kind) => kind !== '
|
|
76
|
-
throw new EyemindError('a
|
|
74
|
+
if (kinds.includes('le')) {
|
|
75
|
+
if (kinds.some((kind) => kind !== 'le') || odrl || owl2rl) {
|
|
76
|
+
throw new EyemindError('a Logical English run takes .le files without RDF logic switches or other input formats');
|
|
77
77
|
}
|
|
78
|
-
return
|
|
78
|
+
return compileLe(inputs);
|
|
79
79
|
}
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
80
|
+
if (owl2rl && odrl) throw new EyemindError('--odrl cannot be combined with --owl2rl');
|
|
81
|
+
if (owl2rl) {
|
|
82
82
|
if (inputs.some(([, name], k) => kinds[k] !== 'rdf' && name !== '<stdin>')) {
|
|
83
|
-
throw new EyemindError('--
|
|
83
|
+
throw new EyemindError('--owl2rl takes RDF inputs; standard input is Turtle');
|
|
84
84
|
}
|
|
85
85
|
const prefixes = {}, quads = [];
|
|
86
86
|
inputs.forEach(([text, name], k) => {
|
|
87
87
|
const parsed = name === '<stdin>' ? parseRdf(text, { format: 'turtle', base: baseOf(name), scope: scopeOf(inputs, name, k) }) : rdf(text, name, k);
|
|
88
|
-
if (parsed.triples) throw new EyemindError('--
|
|
88
|
+
if (parsed.triples) throw new EyemindError('--owl2rl takes RDF graphs, not RDF Message Logs');
|
|
89
89
|
Object.assign(prefixes, parsed.prefixes);
|
|
90
90
|
quads.push(...parsed.quads);
|
|
91
91
|
});
|
|
92
|
-
return
|
|
92
|
+
return compileOwl2rl({ quads, prefixes }, { source: inputs.map(([, n]) => n).join(', ') });
|
|
93
93
|
}
|
|
94
94
|
if (odrl) {
|
|
95
95
|
if (inputs.length !== 1) throw new EyemindError('--odrl takes one Turtle snapshot containing policies, requests and SOTW');
|
|
@@ -153,15 +153,15 @@ function importResolver(io) {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
// Default output:
|
|
156
|
+
// Default output: LE for LE, N3 for N3, Turtle for SRL and the RDF logic
|
|
157
157
|
// extensions, and eyemind's own text for an LS program.
|
|
158
|
-
export const defaultFormat = (kind) => ({
|
|
158
|
+
export const defaultFormat = (kind) => ({ le: 'le', n3: 'n3', srl: 'turtle', odrl: 'turtle', owl2rl: 'turtle' })[kind] ?? 'eyemind';
|
|
159
159
|
|
|
160
160
|
// The conclusions of a run in an output format; null for eyemind's own text.
|
|
161
161
|
// all also writes given RDF or N3 data. Rejects conclusions the format cannot represent.
|
|
162
162
|
export function writeConclusions(loaded, result, { format, all = false, blankNodePrefix = '' } = {}) {
|
|
163
163
|
if (format === 'eyemind') return null;
|
|
164
|
-
if (format === '
|
|
164
|
+
if (format === 'le') return writeLe(result, { odrl: loaded.compiled?.odrl ?? null });
|
|
165
165
|
if (format === 'n3') {
|
|
166
166
|
if (loaded.kind !== 'n3') throw new EyemindError('--to n3 writes the conclusions of an N3 run');
|
|
167
167
|
return resultToN3(loaded.compiled.doc, result, { mode: all ? 'all' : 'new', blankNodePrefix }).n3;
|
package/src/index.js
CHANGED
|
@@ -14,4 +14,4 @@ export { readTerm, readTerms } from './reader.js';
|
|
|
14
14
|
export { EyemindError, Struct, Var } from './terms.js';
|
|
15
15
|
export { write } from './writer.js';
|
|
16
16
|
export { RdfMessageReader, parseRdfMessages } from './messages.js';
|
|
17
|
-
export {
|
|
17
|
+
export { compileLe, writeLe } from './le.js';
|
package/src/le-odrl.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// LE names for the existing ODRL snapshot profile. This module maps data and
|
|
2
|
+
// reports; validation and evaluation remain the rules of odrl.js.
|
|
3
|
+
import { compileOdrl, ODRL_EVAL } from './odrl.js';
|
|
4
|
+
import { loadText } from './lang.js';
|
|
5
|
+
import { DEFAULT_GRAPH, writeRdf } from './rdf.js';
|
|
6
|
+
import { EyemindError, Struct, isGround } from './terms.js';
|
|
7
|
+
import { readTerm } from './reader.js';
|
|
8
|
+
import { write } from './writer.js';
|
|
9
|
+
|
|
10
|
+
const ODRL = 'http://www.w3.org/ns/odrl/2/';
|
|
11
|
+
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
12
|
+
const XSD = 'http://www.w3.org/2001/XMLSchema#';
|
|
13
|
+
const iri = (value) => new Struct('iri', [value]);
|
|
14
|
+
const literal = (value, type) => new Struct('literal', [value, new Struct('datatype', [XSD + type])]);
|
|
15
|
+
const NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
16
|
+
const TYPES = new Map(Object.entries({
|
|
17
|
+
evaluation: ODRL_EVAL + 'Evaluation', policy: ODRL + 'Set', agreement: ODRL + 'Agreement',
|
|
18
|
+
permission: ODRL + 'Permission', prohibition: ODRL + 'Prohibition', constraint: ODRL + 'Constraint',
|
|
19
|
+
request: ODRL_EVAL + 'Request', state: ODRL_EVAL + 'State', action: ODRL + 'Action',
|
|
20
|
+
assetCollection: ODRL + 'AssetCollection', partyCollection: ODRL + 'PartyCollection',
|
|
21
|
+
evaluationReport: ODRL_EVAL + 'EvaluationReport', conflict: ODRL_EVAL + 'Conflict',
|
|
22
|
+
validationError: ODRL_EVAL + 'ValidationError', uncertainty: ODRL_EVAL + 'Uncertainty',
|
|
23
|
+
}));
|
|
24
|
+
const PROPERTIES = new Map();
|
|
25
|
+
for (const name of ['profile', 'permission', 'prohibition', 'assignee', 'assigner', 'action', 'target',
|
|
26
|
+
'constraint', 'leftOperand', 'operator', 'rightOperand', 'duty', 'obligation', 'inheritFrom',
|
|
27
|
+
'includedIn', 'partOf', 'refinement']) PROPERTIES.set(name, ODRL + name);
|
|
28
|
+
for (const name of ['policy', 'request', 'state', 'subject', 'conflictStrategy', 'decision', 'canHappen',
|
|
29
|
+
'validationStatus', 'invalidPolicy', 'reason', 'unmetConstraint', 'uncertainty', 'rule', 'property',
|
|
30
|
+
'validationError', 'focus', 'code', 'permissionPolicy', 'permissionRule', 'prohibitionPolicy',
|
|
31
|
+
'prohibitionRule', 'conflictCount']) PROPERTIES.set(name, ODRL_EVAL + name);
|
|
32
|
+
// A conflict is an evaluation report link; policy-local conflict has a
|
|
33
|
+
// separate name so neither meaning silently replaces the other.
|
|
34
|
+
PROPERTIES.set('conflict', ODRL_EVAL + 'conflict');
|
|
35
|
+
PROPERTIES.set('policyConflict', ODRL + 'conflict');
|
|
36
|
+
PROPERTIES.set('applicablePermission', ODRL_EVAL + 'permission');
|
|
37
|
+
PROPERTIES.set('applicableProhibition', ODRL_EVAL + 'prohibition');
|
|
38
|
+
PROPERTIES.set('reportConstraint', ODRL_EVAL + 'constraint');
|
|
39
|
+
PROPERTIES.set('type', RDF + 'type');
|
|
40
|
+
const VALUES = new Map(Object.entries({
|
|
41
|
+
snapshotProfile: ODRL_EVAL + 'SnapshotProfile',
|
|
42
|
+
perm: ODRL + 'perm', prohibit: ODRL + 'prohibit', invalid: ODRL + 'invalid',
|
|
43
|
+
eq: ODRL + 'eq', neq: ODRL + 'neq', gt: ODRL + 'gt', gteq: ODRL + 'gteq', lt: ODRL + 'lt', lteq: ODRL + 'lteq',
|
|
44
|
+
allowed: ODRL_EVAL + 'Allowed', prohibited: ODRL_EVAL + 'Prohibited',
|
|
45
|
+
notApplicable: ODRL_EVAL + 'NotApplicable', undetermined: ODRL_EVAL + 'Undetermined',
|
|
46
|
+
valid: ODRL_EVAL + 'Valid', invalidReport: ODRL_EVAL + 'Invalid',
|
|
47
|
+
}));
|
|
48
|
+
const reverse = (map) => new Map([...map].map(([name, value]) => [value, name]));
|
|
49
|
+
const TYPE_NAMES = reverse(TYPES), PROPERTY_NAMES = reverse(PROPERTIES), VALUE_NAMES = reverse(VALUES);
|
|
50
|
+
|
|
51
|
+
function rdfValue(term, namespace) {
|
|
52
|
+
if (typeof term === 'string') {
|
|
53
|
+
if (term === 'true' || term === 'false') return literal(term, 'boolean');
|
|
54
|
+
return iri(VALUES.get(term) ?? namespace + term);
|
|
55
|
+
}
|
|
56
|
+
if (typeof term === 'bigint') return term;
|
|
57
|
+
if (typeof term === 'number') return literal(write(term), 'double');
|
|
58
|
+
if (term instanceof Struct && ['iri', 'bnode', 'literal', 'triple', 'skolem'].includes(term.name)) return term;
|
|
59
|
+
throw new EyemindError('LE ODRL values need names, numbers or explicit RDF terms such as iri(...) and literal(...)');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resource(term) {
|
|
63
|
+
return term instanceof Struct && ['iri', 'bnode', 'triple', 'skolem'].includes(term.name);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function compileOdrlLe(statements, profile, source) {
|
|
67
|
+
const { namespace, evaluate } = profile;
|
|
68
|
+
const quads = [];
|
|
69
|
+
for (const statement of statements) {
|
|
70
|
+
if (statement.kind !== 'fact') throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL snapshot or report contains ground facts, not rules or questions`);
|
|
71
|
+
for (const head of statement.heads) {
|
|
72
|
+
if (!(head instanceof Struct) || !isGround(head)) throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL fact needs a ground class or property statement`);
|
|
73
|
+
let s, p, o;
|
|
74
|
+
if (head.name === 'rdf' && head.args.length === 3) [s, p, o] = head.args;
|
|
75
|
+
else if (head.args.length === 1) {
|
|
76
|
+
s = rdfValue(head.args[0], namespace); p = iri(RDF + 'type');
|
|
77
|
+
o = iri(TYPES.get(head.name) ?? namespace + head.name);
|
|
78
|
+
} else if (head.args.length === 2) {
|
|
79
|
+
s = rdfValue(head.args[0], namespace); p = iri(PROPERTIES.get(head.name) ?? namespace + head.name);
|
|
80
|
+
o = rdfValue(head.args[1], namespace);
|
|
81
|
+
} else throw new EyemindError(`${statement.file}: line ${statement.line}: use class facts, binary properties or explicit rdf(S, P, O) facts in LE ODRL`);
|
|
82
|
+
if (!resource(s) || !(p instanceof Struct && p.name === 'iri' && p.args.length === 1)) {
|
|
83
|
+
throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL triple needs a resource subject and an IRI property`);
|
|
84
|
+
}
|
|
85
|
+
quads.push([s, p, o, DEFAULT_GRAPH]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Validate RDF constructors without rewriting terms or witness identities.
|
|
89
|
+
const pending = quads.flatMap((quad) => quad.slice(0, 3));
|
|
90
|
+
while (pending.length) {
|
|
91
|
+
const term = pending.pop();
|
|
92
|
+
if (!(term instanceof Struct) || ['skolem', 'bnode'].includes(term.name)) continue;
|
|
93
|
+
if (term.name === 'iri' || term.name === 'datatype') {
|
|
94
|
+
const [value] = term.args;
|
|
95
|
+
if (term.args.length !== 1 || typeof value !== 'string' || !/^[A-Za-z][A-Za-z0-9+.-]*:/.test(value) || /[\s<>"{}|^`\\]/u.test(value)) {
|
|
96
|
+
throw new EyemindError('LE ODRL IRIs and datatype IRIs must be absolute, without whitespace or forbidden characters');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
pending.push(...term.args);
|
|
100
|
+
}
|
|
101
|
+
writeRdf(quads, { format: 'n-triples' });
|
|
102
|
+
const prefixes = { '': namespace, odrl: ODRL, eval: ODRL_EVAL };
|
|
103
|
+
let loaded;
|
|
104
|
+
if (evaluate) loaded = compileOdrl({ quads, prefixes }, { source });
|
|
105
|
+
else {
|
|
106
|
+
const facts = quads.map(([s, p, o]) => write(new Struct('rdf', [s, p, o]))).join('\n');
|
|
107
|
+
const text = `// RDF facts from an LE ODRL vocabulary document.\nfacts_from({ text: ${JSON.stringify(facts)} })\n`;
|
|
108
|
+
loaded = { text, program: loadText(text, source), prefixes };
|
|
109
|
+
}
|
|
110
|
+
return { ...loaded, kind: 'le', compiled: { statements, odrl: profile, quads } };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function leValue(term, namespace) {
|
|
114
|
+
if (term instanceof Struct && term.name === 'iri' && term.args.length === 1) {
|
|
115
|
+
const value = term.args[0], known = VALUE_NAMES.get(value);
|
|
116
|
+
if (known) return known;
|
|
117
|
+
if (value.startsWith(namespace)) {
|
|
118
|
+
const name = value.slice(namespace.length);
|
|
119
|
+
if (/^[A-Za-z][A-Za-z0-9_]*$/.test(name) && !VALUES.has(name) && name !== 'true' && name !== 'false') return name;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (term instanceof Struct && term.name === 'literal' && term.args.length === 2 &&
|
|
123
|
+
term.args[1] instanceof Struct && term.args[1].name === 'datatype' && term.args[1].args[0] === XSD + 'boolean' &&
|
|
124
|
+
['true', 'false'].includes(term.args[0])) return term.args[0];
|
|
125
|
+
return term;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function odrlLeReport(result, namespace) {
|
|
129
|
+
const answers = result.answers.map((answer) => {
|
|
130
|
+
const term = readTerm(answer);
|
|
131
|
+
if (!(term instanceof Struct) || term.name !== 'rdf' || term.args.length !== 3) throw new EyemindError('LE ODRL reports need rdf(S, P, O) conclusions');
|
|
132
|
+
const [s, p, o] = term.args;
|
|
133
|
+
if (p instanceof Struct && p.name === 'iri') {
|
|
134
|
+
if (p.args[0] === RDF + 'type' && o instanceof Struct && o.name === 'iri' && TYPE_NAMES.has(o.args[0])) {
|
|
135
|
+
return write(new Struct(TYPE_NAMES.get(o.args[0]), [leValue(s, namespace)]));
|
|
136
|
+
}
|
|
137
|
+
const name = PROPERTY_NAMES.get(p.args[0]) ?? (p.args[0].startsWith(namespace) ? p.args[0].slice(namespace.length) : null);
|
|
138
|
+
if (name && NAME.test(name) && (PROPERTIES.get(name) ?? namespace + name) === p.args[0]) {
|
|
139
|
+
return write(new Struct(name, [leValue(s, namespace), leValue(o, namespace)]));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return answer;
|
|
143
|
+
});
|
|
144
|
+
return { answers };
|
|
145
|
+
}
|
package/src/{me.js → le.js}
RENAMED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Logical English: an explicit grammar, ordinary LS clauses,
|
|
2
2
|
// and conclusions that can be read back as facts. No input text is executed.
|
|
3
3
|
import { PRIMITIVE_KEYS } from './builtins.js';
|
|
4
4
|
import { CONTROL_KEYS, Program, RESERVED_KEYS, Source } from './program.js';
|
|
5
5
|
import { readTerm } from './reader.js';
|
|
6
6
|
import { EMPTY, EyemindError, Struct, Var, conjunction, flattenConjunction } from './terms.js';
|
|
7
7
|
import { write } from './writer.js';
|
|
8
|
+
import { compileOdrlLe, odrlLeReport } from './le-odrl.js';
|
|
8
9
|
|
|
9
10
|
const st = (name, ...args) => new Struct(name, args);
|
|
10
11
|
const VARIABLE = /^[A-Z][0-9]*$/;
|
|
11
12
|
const NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
12
|
-
const SENTENCE_WORDS = new Set(['every', 'for', 'if', 'find', 'there', 'it', 'contradiction']);
|
|
13
|
+
const SENTENCE_WORDS = new Set(['every', 'for', 'if', 'find', 'there', 'it', 'contradiction', 'use']);
|
|
13
14
|
const RESERVED = new Set([...PRIMITIVE_KEYS, ...CONTROL_KEYS, ...RESERVED_KEYS].map((key) => key.split('/')[0]));
|
|
14
15
|
for (const name of ['true', 'false', 'fail']) RESERVED.add(name);
|
|
15
16
|
const OPERATORS = { '+': ['add', 1], '-': ['sub', 1], '*': ['mul', 2], '/': ['div', 2] };
|
|
@@ -53,7 +54,7 @@ class Parser {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
get token() { return this.tokens[this.at]; }
|
|
56
|
-
error(message, line = this.token?.line ?? 1) { throw new EyemindError(`${this.file}: line ${line}:
|
|
57
|
+
error(message, line = this.token?.line ?? 1) { throw new EyemindError(`${this.file}: line ${line}: Logical English: ${message}`); }
|
|
57
58
|
is(word) { return this.token.kind !== 'string' && this.token.value.toLowerCase() === word; }
|
|
58
59
|
take(word) { if (!this.is(word)) return false; this.at++; return true; }
|
|
59
60
|
need(word) { if (!this.take(word)) this.error(`expected ${JSON.stringify(word)}, found ${JSON.stringify(this.token.raw || 'end of input')}`); }
|
|
@@ -166,6 +167,10 @@ class Parser {
|
|
|
166
167
|
return st('not', this.atomic(false));
|
|
167
168
|
}
|
|
168
169
|
const subject = this.term();
|
|
170
|
+
if (this.take('has')) {
|
|
171
|
+
const name = this.name();
|
|
172
|
+
return st(name, subject, this.term());
|
|
173
|
+
}
|
|
169
174
|
if (this.take('is')) {
|
|
170
175
|
if (this.is('not')) this.error('ordinary "not" is unsupported; use "it is not known that" in a premise for absence, or a separate relation for explicit negative evidence');
|
|
171
176
|
if (!body && this.is('the')) this.error('put calculations in a premise, as in "Y is the value of X + 1", then state the result relation');
|
|
@@ -209,6 +214,20 @@ class Parser {
|
|
|
209
214
|
sentence() {
|
|
210
215
|
const line = this.token.line;
|
|
211
216
|
this.scope = new Map();
|
|
217
|
+
if (this.is('use') && this.tokens[this.at + 1]?.kind === 'word' && this.tokens[this.at + 1].value.toLowerCase() === 'odrl') {
|
|
218
|
+
this.at++;
|
|
219
|
+
this.need('odrl');
|
|
220
|
+
let evaluate = false;
|
|
221
|
+
if (this.take('snapshot')) { this.need('logic'); evaluate = true; }
|
|
222
|
+
else this.need('vocabulary');
|
|
223
|
+
this.need('with'); this.need('namespace');
|
|
224
|
+
if (this.token.kind !== 'string') this.error('an ODRL namespace must be a quoted absolute IRI');
|
|
225
|
+
const namespace = this.token.value;
|
|
226
|
+
try { new URL(namespace); } catch { this.error('an ODRL namespace must be an absolute IRI'); }
|
|
227
|
+
if (/[\s<>"{}|^`\\]/u.test(namespace)) this.error('an ODRL namespace must be an absolute IRI without whitespace or forbidden characters');
|
|
228
|
+
this.at++; this.need('.');
|
|
229
|
+
return { kind: 'odrl', namespace, evaluate, line };
|
|
230
|
+
}
|
|
212
231
|
if (this.take('every')) {
|
|
213
232
|
const from = this.name(); this.need('is');
|
|
214
233
|
const x = new Var('X'), heads = [];
|
|
@@ -271,12 +290,18 @@ function javascript(term) {
|
|
|
271
290
|
return JSON.stringify(term);
|
|
272
291
|
}
|
|
273
292
|
|
|
274
|
-
export function
|
|
293
|
+
export function compileLe(inputs) {
|
|
275
294
|
const clauses = [], statements = [], sources = [];
|
|
295
|
+
let profile = null;
|
|
276
296
|
for (const [text, file] of inputs) {
|
|
277
297
|
const parser = new Parser(String(text), file);
|
|
278
298
|
while (parser.token.kind !== 'end') {
|
|
279
299
|
const sentence = parser.sentence(), { kind, heads, body, line } = sentence;
|
|
300
|
+
if (kind === 'odrl') {
|
|
301
|
+
if (profile || statements.length || inputs.length !== 1) parser.error('an ODRL directive must be the first sentence of one LE file', line);
|
|
302
|
+
profile = { namespace: sentence.namespace, evaluate: sentence.evaluate };
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
280
305
|
statements.push({ ...sentence, file });
|
|
281
306
|
clauses.push(`// ${String(file).replace(/[\r\n\u2028\u2029]/g, ' ')}: line ${line}`);
|
|
282
307
|
if (kind === 'fact') {
|
|
@@ -293,52 +318,56 @@ export function compileMe(inputs) {
|
|
|
293
318
|
}
|
|
294
319
|
}
|
|
295
320
|
}
|
|
296
|
-
|
|
321
|
+
if (profile) return compileOdrlLe(statements, profile, inputs[0][1]);
|
|
322
|
+
return { kind: 'le', text: '// Compiled from Logical English to Logic Script.\n\n' + clauses.join('\n') + '\n',
|
|
297
323
|
program: new Program(sources), prefixes: {}, compiled: { statements } };
|
|
298
324
|
}
|
|
299
325
|
|
|
300
|
-
function
|
|
326
|
+
function leTerm(term, names) {
|
|
301
327
|
if (term instanceof Var) return names.get(term.name);
|
|
302
328
|
if (term === EMPTY) return '[]';
|
|
303
329
|
if (typeof term === 'string') {
|
|
304
330
|
return /^[A-Za-z][A-Za-z0-9_]*$/.test(term) && !VARIABLE.test(term) && !SENTENCE_WORDS.has(term.toLowerCase()) ? term : JSON.stringify(term);
|
|
305
331
|
}
|
|
306
332
|
if (typeof term === 'bigint' || typeof term === 'number') return write(term);
|
|
307
|
-
if (!(term instanceof Struct)) throw new EyemindError('cannot write this term as
|
|
333
|
+
if (!(term instanceof Struct)) throw new EyemindError('cannot write this term as Logical English');
|
|
308
334
|
if (term.name === 'skolem' && term.args.length === 3) {
|
|
309
335
|
const [rule, label, bindings] = term.args, args = listItems(bindings);
|
|
310
336
|
if (typeof rule === 'bigint' && rule > 0n && typeof label === 'string' && args !== null) {
|
|
311
337
|
const name = VARIABLE.test(label) ? label : JSON.stringify(label);
|
|
312
|
-
return `witness(rule ${rule}, ${name}${args.map((arg) => ', ' +
|
|
338
|
+
return `witness(rule ${rule}, ${name}${args.map((arg) => ', ' + leTerm(arg, names)).join('')})`;
|
|
313
339
|
}
|
|
314
340
|
}
|
|
315
341
|
if (term.name === '.') {
|
|
316
342
|
const items = listItems(term);
|
|
317
|
-
if (items !== null) return `[${items.map((item) =>
|
|
343
|
+
if (items !== null) return `[${items.map((item) => leTerm(item, names)).join(', ')}]`;
|
|
318
344
|
// Improper lists remain explicit compounds.
|
|
319
345
|
}
|
|
320
|
-
return `${JSON.stringify(term.name)}(${term.args.map((arg) =>
|
|
346
|
+
return `${JSON.stringify(term.name)}(${term.args.map((arg) => leTerm(arg, names)).join(', ')})`;
|
|
321
347
|
}
|
|
322
348
|
|
|
323
|
-
function
|
|
349
|
+
function leGoal(term, names, properties) {
|
|
324
350
|
if (term === 'false') return 'Contradiction';
|
|
325
|
-
if (typeof term === 'string' && NAME.test(term) && !RESERVED.has(term)) return
|
|
351
|
+
if (typeof term === 'string' && NAME.test(term) && !RESERVED.has(term)) return leTerm(term, names);
|
|
326
352
|
if (!(term instanceof Struct) || !NAME.test(term.name) || RESERVED.has(term.name)) {
|
|
327
|
-
throw new EyemindError(`${write(term)} is not a
|
|
353
|
+
throw new EyemindError(`${write(term)} is not a Logical English relation; use --to eyemind`);
|
|
328
354
|
}
|
|
329
355
|
const article = /^[aeiou]/.test(term.name) ? 'an' : 'a';
|
|
330
|
-
if (term.args.length === 1) return `${
|
|
331
|
-
if (term.args.length === 2) return `${
|
|
332
|
-
|
|
356
|
+
if (term.args.length === 1) return `${leTerm(term.args[0], names)} is ${article} ${term.name}`;
|
|
357
|
+
if (properties && term.args.length === 2) return `${leTerm(term.args[0], names)} has ${term.name} ${leTerm(term.args[1], names)}`;
|
|
358
|
+
if (term.args.length === 2) return `${leTerm(term.args[0], names)} is ${article} ${term.name} of ${leTerm(term.args[1], names)}`;
|
|
359
|
+
return `${term.name}(${term.args.map((arg) => leTerm(arg, names)).join(', ')})`;
|
|
333
360
|
}
|
|
334
361
|
|
|
335
|
-
export function
|
|
362
|
+
export function writeLe(result, { odrl = null } = {}) {
|
|
363
|
+
if (odrl) result = odrlLeReport(result, odrl.namespace);
|
|
336
364
|
const lines = [];
|
|
337
365
|
for (const answer of result.answers) {
|
|
338
366
|
const term = readTerm(answer);
|
|
339
367
|
const names = new Map([...variablesIn([term])].map((name, i) => [name, `X${i}`]));
|
|
340
368
|
const quantifier = names.size ? `For every ${[...names.values()].join(' and ')}, ` : '';
|
|
341
|
-
lines.push(quantifier + flattenConjunction(term).map((goal) =>
|
|
369
|
+
lines.push(quantifier + flattenConjunction(term).map((goal) => leGoal(goal, names, odrl !== null)).join(' and ') + '.');
|
|
342
370
|
}
|
|
343
|
-
|
|
371
|
+
const header = odrl ? `Use ODRL vocabulary with namespace ${JSON.stringify(odrl.namespace)}.\n\n` : '';
|
|
372
|
+
return header + (lines.length ? lines.join('\n') + '\n' : '# No conclusions.\n');
|
|
344
373
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// OWL 2 RL inference, including RDFS, compiled to standalone Logic Script.
|
|
2
2
|
// Rule names follow W3C OWL 2 RL/RDF tables 4–7 and 9:
|
|
3
3
|
// https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs
|
|
4
4
|
import { loadText } from './lang.js';
|
|
@@ -6,14 +6,13 @@ import { rdfDocument } from './rdf.js';
|
|
|
6
6
|
|
|
7
7
|
export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
|
|
8
8
|
|
|
9
|
-
export function
|
|
10
|
-
const
|
|
11
|
-
const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with --${kind}.\n` +
|
|
9
|
+
export function compileOwl2rl({ quads, prefixes }, { source = '<input>' } = {}) {
|
|
10
|
+
const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with --owl2rl.\n` +
|
|
12
11
|
'// rdf(S, P, O, G) is the working graph; result_rdf contains new RDF conclusions.\n' +
|
|
13
12
|
`facts_from({ text: ${JSON.stringify(rdfDocument(quads))} })\n` +
|
|
14
13
|
`facts_from({ text: ${JSON.stringify(rdfDocument(quads, 'ent_base'))} })\n` +
|
|
15
|
-
COMMON + RDFS +
|
|
16
|
-
return { kind, text, program: loadText(text, source), prefixes: { ...prefixes, ent: ENTAILMENT }, compiled: null };
|
|
14
|
+
COMMON + RDFS + OWL + OUTPUT;
|
|
15
|
+
return { kind: 'owl2rl', text, program: loadText(text, source), prefixes: { ...prefixes, ent: ENTAILMENT }, compiled: null };
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
const COMMON = String.raw`
|
|
@@ -28,7 +27,7 @@ implied_by(ent_resource(triple(A, B, C)), 'true');
|
|
|
28
27
|
implies(rdf(S, P, O, G), ent_graph(G));
|
|
29
28
|
implies(rdf(S, P, O, G), [ent_node(S, G), ent_node(P, G), ent_node(O, G)]);
|
|
30
29
|
|
|
31
|
-
// RDFS class/property propagation
|
|
30
|
+
// RDFS class/property propagation.
|
|
32
31
|
implies([t(P, s('domain'), C), t(X, P, Y)], t(X, r('type'), C));
|
|
33
32
|
implies([t(P, s('range'), C), t(X, P, Y)], t(Y, r('type'), C));
|
|
34
33
|
implies([t(C, s('subClassOf'), D), t(X, r('type'), C)], t(X, r('type'), D));
|
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.7.
|
|
2
|
+
export const VERSION = '0.7.2';
|