eyemind 0.8.37 → 0.8.38
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/LE-SPEC.md +129 -3
- package/LS-SPEC.md +1 -1
- package/README.md +15 -4
- package/package.json +1 -1
- package/src/dpv.js +19 -0
- package/src/formats.js +9 -3
- package/src/le-odrl.js +40 -3
- package/src/le.js +130 -30
- package/src/odrl.js +96 -7
- package/src/version.js +1 -1
package/LE-SPEC.md
CHANGED
|
@@ -78,6 +78,59 @@ For every X, matching(pair(X, X)).
|
|
|
78
78
|
Variables declared by `For every` are universal within that sentence. Each
|
|
79
79
|
sentence has its own scope. Repeating a declaration in one scope is an error.
|
|
80
80
|
|
|
81
|
+
## RDF vocabulary names
|
|
82
|
+
|
|
83
|
+
Declare a prefix before using its names. ODRL, DPV and DPV extension
|
|
84
|
+
namespaces can appear together in the same file.
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
Use prefix ex with namespace "https://example.org/research#".
|
|
88
|
+
Use prefix odrl with namespace "http://www.w3.org/ns/odrl/2/".
|
|
89
|
+
Use prefix dpv with namespace "https://w3id.org/dpv#".
|
|
90
|
+
|
|
91
|
+
ex:agreement is an odrl:Agreement.
|
|
92
|
+
ex:study is a dpv:Process.
|
|
93
|
+
ex:study has dpv:hasPurpose dpv:AcademicResearch.
|
|
94
|
+
|
|
95
|
+
Find every X such that X has dpv:hasPurpose dpv:AcademicResearch.
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Prefixes start with an ASCII letter and can also contain digits and
|
|
99
|
+
underscores. Local names contain ASCII letters, digits, underscores and
|
|
100
|
+
hyphens, and cannot start with a hyphen. Prefixes and local names are
|
|
101
|
+
case-sensitive. A declaration binds a prefix to a quoted absolute IRI.
|
|
102
|
+
Each file declares its own prefixes, at most once per prefix. Prefix
|
|
103
|
+
expansion appends the local name to the namespace exactly as stated.
|
|
104
|
+
`iri("...")` terms can express IRIs outside this abbreviation syntax.
|
|
105
|
+
|
|
106
|
+
In facts, rules and questions, a qualified class or property uses the
|
|
107
|
+
same `rdf/3` relation:
|
|
108
|
+
|
|
109
|
+
| LE form | LS term |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `T is a ex:Class` | `rdf(T, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), iri("https://example.org/research#Class"))` |
|
|
112
|
+
| `T has ex:property U` or `T is an ex:property of U` | `rdf(T, iri("https://example.org/research#property"), U)` |
|
|
113
|
+
| `ex:item` in any term position | `iri("https://example.org/research#item")` |
|
|
114
|
+
|
|
115
|
+
`Every` rules also accept qualified classes on either side. Qualified
|
|
116
|
+
statements take a resource or variable as their subject. Objects can
|
|
117
|
+
also be numbers and explicit RDF terms such as
|
|
118
|
+
`literal("dataset", datatype("http://www.w3.org/2001/XMLSchema#string"))`.
|
|
119
|
+
Ordinary unqualified class and relation names retain their LS meanings.
|
|
120
|
+
|
|
121
|
+
The default LE output abbreviates IRIs using available prefixes and
|
|
122
|
+
includes the declarations it uses. Other IRIs retain their explicit
|
|
123
|
+
terms. When input files assign the same prefix to different namespaces,
|
|
124
|
+
the final declaration supplies the output abbreviation. Earlier files'
|
|
125
|
+
expanded IRIs retain their values. For triple conclusions, `--to turtle`
|
|
126
|
+
writes the RDF graph and `--all` adds the stated RDF facts.
|
|
127
|
+
|
|
128
|
+
Prefix declarations specify names. The facts and rules supply their
|
|
129
|
+
meaning for a run. The research access example uses ODRL permissions,
|
|
130
|
+
prohibitions, constraints and a duty with DPV purpose and consent
|
|
131
|
+
evidence. Its ordinary LE rules specify the scenario's policy decisions.
|
|
132
|
+
[Research access example](https://eyereasoner.github.io/eyemind/examples/deck/research-access-le) · [ODRL Vocabulary](https://www.w3.org/TR/odrl-vocab/) · [Data Privacy Vocabulary 2.3](https://w3id.org/dpv/2.3/dpv/)
|
|
133
|
+
|
|
81
134
|
## Rules and calculations
|
|
82
135
|
|
|
83
136
|
```text
|
|
@@ -266,6 +319,36 @@ These programs use the grammar above without additional syntax:
|
|
|
266
319
|
Their decks state the modeled assumptions and what the checked proofs establish.
|
|
267
320
|
Bounds and finite expression domains are explicit in the programs.
|
|
268
321
|
|
|
322
|
+
## DPV hierarchies
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
Use DPV hierarchy logic.
|
|
326
|
+
Use prefix ex with namespace "https://example.org/research#".
|
|
327
|
+
Use prefix dpv with namespace "https://w3id.org/dpv#".
|
|
328
|
+
Use prefix skos with namespace "http://www.w3.org/2004/02/skos/core#".
|
|
329
|
+
|
|
330
|
+
ex:study has dpv:hasPurpose dpv:AcademicResearch.
|
|
331
|
+
dpv:AcademicResearch has skos:broader dpv:ResearchAndDevelopment.
|
|
332
|
+
Find whether ex:study has purposeWithin dpv:ResearchAndDevelopment.
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The directive adds hierarchy rules to an ordinary LE program. The
|
|
336
|
+
program supplies its observations and SKOS edges. DPV 2.3 uses SKOS
|
|
337
|
+
broader and narrower relations for its default taxonomy representation.
|
|
338
|
+
[DPV 2.3](https://w3id.org/dpv/2.3/dpv/)
|
|
339
|
+
|
|
340
|
+
| Observation property | LE conclusion |
|
|
341
|
+
| --- | --- |
|
|
342
|
+
| `dpv:hasPurpose` | `X has purposeWithin C` |
|
|
343
|
+
| `dpv:hasData` | `X has dataWithin C` |
|
|
344
|
+
| `dpv:hasPersonalData` | `X has personalDataWithin C` |
|
|
345
|
+
|
|
346
|
+
Each conclusion matches an observed category itself and its ancestors
|
|
347
|
+
reached by transitively following the supplied IRI-to-IRI
|
|
348
|
+
`skos:broader` and `skos:broaderTransitive` edges, or the inverse of
|
|
349
|
+
`skos:narrower` and `skos:narrowerTransitive`. A snapshot uses the same
|
|
350
|
+
hierarchy through its `withinCategory` operator.
|
|
351
|
+
|
|
269
352
|
## ODRL snapshots
|
|
270
353
|
|
|
271
354
|
An LE file can explicitly select the existing ODRL snapshot evaluator:
|
|
@@ -293,18 +376,21 @@ Names expand as follows, with case preserved:
|
|
|
293
376
|
| --- | --- |
|
|
294
377
|
| An ordinary individual name | An IRI formed by appending it to the declared namespace. |
|
|
295
378
|
| Classes `evaluation`, `request`, `state` | `eval:Evaluation`, `eval:Request`, `eval:State`. |
|
|
296
|
-
| Classes `policy`, `agreement`, `permission`, `prohibition`, `constraint`, `action` | `odrl:Set`, `odrl:Agreement`, `odrl:Permission`, `odrl:Prohibition`, `odrl:Constraint`, `odrl:Action`. |
|
|
379
|
+
| Classes `policy`, `agreement`, `permission`, `prohibition`, `constraint`, `logicalConstraint`, `duty`, `action` | `odrl:Set`, `odrl:Agreement`, `odrl:Permission`, `odrl:Prohibition`, `odrl:Constraint`, `odrl:LogicalConstraint`, `odrl:Duty`, `odrl:Action`. |
|
|
297
380
|
| Classes `assetCollection`, `partyCollection` | ODRL collection classes, rejected by the snapshot profile. |
|
|
298
381
|
| Properties `policy`, `request`, `state`, `subject`, `conflictStrategy` | The corresponding `eval:` properties. |
|
|
299
|
-
| Properties `profile`, `permission`, `prohibition`, `assignee`, `assigner`, `action`, `target`, `constraint`, `leftOperand`, `operator`, `rightOperand` | The corresponding `odrl:` properties. |
|
|
382
|
+
| Properties `profile`, `permission`, `prohibition`, `assignee`, `assigner`, `action`, `target`, `constraint`, `leftOperand`, `operator`, `rightOperand`, `duty` | The corresponding `odrl:` properties. |
|
|
383
|
+
| Properties `andOperands`, `orOperands`, `xoneOperands` | `odrl:and`, `odrl:or`, `odrl:xone`. LE lists become RDF collections. |
|
|
384
|
+
| Properties `fulfilledDuty`, `unfulfilledDuty` | The corresponding `eval:` request evidence properties. |
|
|
300
385
|
| Property `policyConflict` | `odrl:conflict`, the policy-local strategy. |
|
|
301
386
|
| Property `type` | `rdf:type`. |
|
|
302
387
|
| An otherwise unknown class or property | An IRI in the declared namespace; validation still applies. |
|
|
303
388
|
| Values `snapshotProfile`, `perm`, `prohibit`, `invalid`, `eq`, `neq`, `gt`, `gteq`, `lt`, `lteq` | `eval:SnapshotProfile` or the corresponding ODRL strategy/operator IRIs. |
|
|
389
|
+
| Value `withinCategory` | `eval:withinCategory`, the snapshot's DPV hierarchy operator. |
|
|
304
390
|
| Values `true`, `false` | Boolean RDF literals. Quoting does not change an LE name into an RDF string literal. |
|
|
305
391
|
| An integer or float | An exact RDF integer or an `xsd:double` literal. |
|
|
306
392
|
|
|
307
|
-
The unsupported ODRL properties `
|
|
393
|
+
The unsupported ODRL properties `obligation`, `inheritFrom`, `includedIn`,
|
|
308
394
|
`partOf` and `refinement` retain their ODRL IRIs so the shared validator can
|
|
309
395
|
report them. Explicit RDF values such as `iri("https://example.org/item")` and
|
|
310
396
|
`literal("text", datatype("http://www.w3.org/2001/XMLSchema#string"))` retain
|
|
@@ -334,6 +420,46 @@ use `has`; for example `issueAlice has decision allowed.`. Status values
|
|
|
334
420
|
input properties. Other report fields retain their `eval:` names. An IRI with
|
|
335
421
|
no unambiguous abbreviation stays explicit, including IRIs inside witness keys.
|
|
336
422
|
|
|
423
|
+
Prefix declarations can follow either ODRL directive. A qualified state
|
|
424
|
+
property or value can use a DPV IRI, for example
|
|
425
|
+
`ex:state has dpv:hasPurpose dpv:AcademicResearch.`. An equality constraint
|
|
426
|
+
can read `dpv:hasPurpose` as its left operand and use
|
|
427
|
+
`dpv:AcademicResearch` as its right operand.
|
|
428
|
+
|
|
429
|
+
```text
|
|
430
|
+
scope is a logicalConstraint and scope has andOperands [purpose, dataCategory].
|
|
431
|
+
purpose is a constraint and purpose has leftOperand dpv:hasPurpose.
|
|
432
|
+
purpose has operator withinCategory and purpose has rightOperand dpv:ResearchAndDevelopment.
|
|
433
|
+
credit is a duty and credit has action odrl:attribute.
|
|
434
|
+
researchUse has constraint scope and researchUse has duty credit.
|
|
435
|
+
ready has fulfilledDuty credit.
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
A logical constraint has one operator and a proper RDF list of at least two
|
|
439
|
+
distinct atomic constraints. `andOperands` requires all members,
|
|
440
|
+
`orOperands` at least one and `xoneOperands` exactly one. The result is
|
|
441
|
+
unknown when treating unknown members as satisfied or unsatisfied could
|
|
442
|
+
change the outcome. Reports cite the group for an unmet or unknown logical
|
|
443
|
+
constraint. The snapshot rejects nested groups and `odrl:andSequence`.
|
|
444
|
+
[ODRL Logical Constraint Class](https://www.w3.org/TR/odrl-model/#constraint-logical)
|
|
445
|
+
|
|
446
|
+
A permission can require several duties. Each is typed `odrl:Duty` and
|
|
447
|
+
has one action IRI. A request records whether it has fulfilled each duty.
|
|
448
|
+
An `unfulfilledDuty` record makes the permission inapplicable and gives
|
|
449
|
+
an `unmetDuty` report link. A missing record or conflicting records give
|
|
450
|
+
an uncertainty with `reportDuty` and a reason. The snapshot takes these
|
|
451
|
+
records as evidence of fulfillment. Duties that specify additional action
|
|
452
|
+
refinements, roles or consequences fail validation.
|
|
453
|
+
[ODRL Duty with a Permission](https://www.w3.org/TR/odrl-model/#duties)
|
|
454
|
+
|
|
455
|
+
`withinCategory` compares a single observed IRI with a required category IRI.
|
|
456
|
+
It accepts the three DPV observation properties in the hierarchy table.
|
|
457
|
+
An exact match or a supplied broader path satisfies the constraint. With
|
|
458
|
+
a known observation and no such path the constraint is unmet. The snapshot
|
|
459
|
+
reports missing, ambiguous or mistyped observations as unknown.
|
|
460
|
+
The research snapshot demonstrates compound scope, two DPV hierarchies and
|
|
461
|
+
request-local duty evidence. [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le)
|
|
462
|
+
|
|
337
463
|
Both ODRL directives take a single LE file and reject mixed-in ordinary LE
|
|
338
464
|
rules or questions. `--goal` can query their compiled LS program. The normal
|
|
339
465
|
`--odrl` switch continues to select the Turtle snapshot compiler.
|
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ program, a JavaScript library and a browser application.
|
|
|
13
13
|
- [Playground](https://eyereasoner.github.io/eyemind/playground/): run any
|
|
14
14
|
example or your own program in the browser, with its proof and check report.
|
|
15
15
|
- [Examples](https://eyereasoner.github.io/eyemind/examples/): the
|
|
16
|
-
|
|
16
|
+
160 runnable programs, each with a card deck and saved conclusions; all but
|
|
17
17
|
the two streamed examples also save proofs and check reports.
|
|
18
18
|
- [Specification](https://eyereasoner.github.io/eyemind/LS-SPEC): the
|
|
19
19
|
language, the proof format and how a proof is checked.
|
|
@@ -244,6 +244,15 @@ A first sentence `Use ODRL snapshot logic with namespace "..."` turns a file of
|
|
|
244
244
|
ground facts into an [ODRL snapshot](#odrl-snapshots) evaluation, with LE names
|
|
245
245
|
mapped to the `eval:` and `odrl:` vocabularies; see the
|
|
246
246
|
[handicap-card LE deck](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card-le).
|
|
247
|
+
Ordinary LE can declare RDF prefixes with `Use prefix dpv with namespace "https://w3id.org/dpv#".`
|
|
248
|
+
Qualified classes, properties and values work in facts, rules and questions.
|
|
249
|
+
The research access example combines ODRL rules with DPV purpose and consent
|
|
250
|
+
data and checks three policy decisions. [Research access LE deck](https://eyereasoner.github.io/eyemind/examples/deck/research-access-le)
|
|
251
|
+
|
|
252
|
+
`Use DPV hierarchy logic.` adds rules for matching purposes, data and
|
|
253
|
+
personal data against the supplied SKOS taxonomy. ODRL snapshots can use the same
|
|
254
|
+
hierarchy in category constraints. [Logical English specification](https://eyereasoner.github.io/eyemind/LE-SPEC#dpv-hierarchies)
|
|
255
|
+
|
|
247
256
|
For larger programs, try
|
|
248
257
|
[shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le),
|
|
249
258
|
[river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le),
|
|
@@ -433,9 +442,11 @@ eyemind --owl2rl -c examples/family-owl2rl.ttl
|
|
|
433
442
|
and their state of the world, selected by an `eval:Evaluation` resource. The
|
|
434
443
|
report gives each request's decision (`Allowed`, `Prohibited`,
|
|
435
444
|
`NotApplicable` or `Undetermined`) and the permission/prohibition conflicts.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
445
|
+
Each rule has one assignee, action and target. The snapshot compares state
|
|
446
|
+
properties with scalar or DPV category constraints and combines constraints
|
|
447
|
+
with `odrl:and`, `odrl:or` or `odrl:xone`. Permissions can require duties,
|
|
448
|
+
with fulfillment evidence attached to each request.
|
|
449
|
+
[Handicap-card example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card) · [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le)
|
|
439
450
|
|
|
440
451
|
## How eyemind reasons
|
|
441
452
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.38",
|
|
4
4
|
"description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/dpv.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// DPV's default serialization uses SKOS for concept hierarchies.
|
|
2
|
+
// https://w3id.org/dpv/2.3/dpv/
|
|
3
|
+
export const DPV = 'https://w3id.org/dpv#';
|
|
4
|
+
export const DPV_PROPERTIES = { hasPurpose: 'purposeWithin', hasData: 'dataWithin', hasPersonalData: 'personalDataWithin' };
|
|
5
|
+
|
|
6
|
+
export function dpvRules(input, includeConclusions = false) {
|
|
7
|
+
const skos = 'http://www.w3.org/2004/02/skos/core#';
|
|
8
|
+
return `
|
|
9
|
+
// Broader categories from the supplied DPV/SKOS graph.
|
|
10
|
+
implies(${input}(iri(C), iri('${skos}broader'), iri(P)), struct('dpv:broader', iri(C), iri(P)));
|
|
11
|
+
implies(${input}(iri(P), iri('${skos}narrower'), iri(C)), struct('dpv:broader', iri(C), iri(P)));
|
|
12
|
+
implies(${input}(iri(C), iri('${skos}broaderTransitive'), iri(P)), struct('dpv:broader', iri(C), iri(P)));
|
|
13
|
+
implies(${input}(iri(P), iri('${skos}narrowerTransitive'), iri(C)), struct('dpv:broader', iri(C), iri(P)));
|
|
14
|
+
implies([struct('dpv:broader', C, I), struct('dpv:broader', I, P)], struct('dpv:broader', C, P));
|
|
15
|
+
fact(struct('dpv:within', iri(C), iri(C)));
|
|
16
|
+
implied_by(struct('dpv:within', C, P), struct('dpv:broader', C, P));
|
|
17
|
+
` + (includeConclusions ? Object.entries(DPV_PROPERTIES).map(([property, predicate]) =>
|
|
18
|
+
`implies([rdf(X, iri('${DPV + property}'), iri(C)), struct('dpv:within', iri(C), P)], ${predicate}(X, P));\n`).join('') : '');
|
|
19
|
+
}
|
package/src/formats.js
CHANGED
|
@@ -211,20 +211,25 @@ export const defaultFormat = (kind) => RDF_PROFILES.includes(kind) ? 'turtle' :
|
|
|
211
211
|
// all also writes given RDF or N3 data. Rejects conclusions the format cannot represent.
|
|
212
212
|
export function writeConclusions(loaded, result, { format, all = false, blankNodePrefix = '' } = {}) {
|
|
213
213
|
if (format === 'eyemind') return null;
|
|
214
|
-
if (format === 'le') return writeLe(result, { odrl: loaded.compiled?.odrl ?? null
|
|
214
|
+
if (format === 'le') return writeLe(result, { odrl: loaded.compiled?.odrl ?? null,
|
|
215
|
+
prefixes: loaded.kind === 'le' ? loaded.prefixes : {} });
|
|
215
216
|
if (format === 'n3') {
|
|
216
217
|
if (loaded.kind !== 'n3') throw new EyemindError('--to n3 writes the conclusions of an N3 run');
|
|
217
218
|
return resultToN3(loaded.compiled.doc, result, { mode: all ? 'all' : 'new', blankNodePrefix }).n3;
|
|
218
219
|
}
|
|
219
220
|
let quads;
|
|
220
221
|
if (loaded.kind === 'srl') quads = srlQuads(loaded.compiled, srlAnswers(result), { all });
|
|
221
|
-
else
|
|
222
|
+
else if (all && loaded.kind === 'le' && !loaded.compiled?.odrl) {
|
|
223
|
+
const facts = loaded.program.sources.filter(({ kind, head }) => kind === 'fact' &&
|
|
224
|
+
head instanceof Struct && head.name === 'rdf' && (head.args.length === 3 || head.args.length === 4));
|
|
225
|
+
quads = conclusionQuads(result.answers, null, facts.map(({ head }) => head));
|
|
226
|
+
} else quads = conclusionQuads(result.answers, all ? loaded.text : null);
|
|
222
227
|
return writeRdf(quads, { format, prefixes: loaded.kind === 'n3' ? Object.fromEntries(loaded.prefixes) : loaded.prefixes, blankNodePrefix });
|
|
223
228
|
}
|
|
224
229
|
|
|
225
230
|
// Conclusions that are triples, rdf/3 or result/3, or quads, rdf/4 or
|
|
226
231
|
// result_rdf/4, as quads; given, the program's own rdf facts come first.
|
|
227
|
-
function conclusionQuads(answers, given) {
|
|
232
|
+
function conclusionQuads(answers, given, facts = []) {
|
|
228
233
|
const quads = [];
|
|
229
234
|
const seen = new Set();
|
|
230
235
|
const add = (t) => {
|
|
@@ -240,6 +245,7 @@ function conclusionQuads(answers, given) {
|
|
|
240
245
|
for (const [t] of readTerms(JSON.parse(match[1]))) add(t);
|
|
241
246
|
}
|
|
242
247
|
}
|
|
248
|
+
for (const fact of facts) add(fact);
|
|
243
249
|
for (const answer of answers) {
|
|
244
250
|
const [[t]] = readTerms(answer);
|
|
245
251
|
if (t === 'false') continue;
|
package/src/le-odrl.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { compileOdrl, ODRL_EVAL } from './odrl.js';
|
|
4
4
|
import { loadText } from './lang.js';
|
|
5
5
|
import { DEFAULT_GRAPH, writeRdf } from './rdf.js';
|
|
6
|
-
import { EyemindError, Struct, isGround } from './terms.js';
|
|
6
|
+
import { EyemindError, Struct, isGround, properListItems } from './terms.js';
|
|
7
7
|
import { readTerm } from './reader.js';
|
|
8
8
|
import { write } from './writer.js';
|
|
9
9
|
|
|
@@ -16,6 +16,7 @@ const NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
|
16
16
|
const TYPES = new Map(Object.entries({
|
|
17
17
|
evaluation: ODRL_EVAL + 'Evaluation', policy: ODRL + 'Set', agreement: ODRL + 'Agreement',
|
|
18
18
|
permission: ODRL + 'Permission', prohibition: ODRL + 'Prohibition', constraint: ODRL + 'Constraint',
|
|
19
|
+
logicalConstraint: ODRL + 'LogicalConstraint', duty: ODRL + 'Duty',
|
|
19
20
|
request: ODRL_EVAL + 'Request', state: ODRL_EVAL + 'State', action: ODRL + 'Action',
|
|
20
21
|
assetCollection: ODRL + 'AssetCollection', partyCollection: ODRL + 'PartyCollection',
|
|
21
22
|
evaluationReport: ODRL_EVAL + 'EvaluationReport', conflict: ODRL_EVAL + 'Conflict',
|
|
@@ -26,7 +27,7 @@ for (const name of ['profile', 'permission', 'prohibition', 'assignee', 'assigne
|
|
|
26
27
|
'constraint', 'leftOperand', 'operator', 'rightOperand', 'duty', 'obligation', 'inheritFrom',
|
|
27
28
|
'includedIn', 'partOf', 'refinement']) PROPERTIES.set(name, ODRL + name);
|
|
28
29
|
for (const name of ['policy', 'request', 'state', 'subject', 'conflictStrategy', 'decision', 'canHappen',
|
|
29
|
-
'validationStatus', 'invalidPolicy', 'reason', 'unmetConstraint', 'uncertainty', 'rule', 'property',
|
|
30
|
+
'validationStatus', 'invalidPolicy', 'reason', 'unmetConstraint', 'unmetDuty', 'fulfilledDuty', 'unfulfilledDuty', 'uncertainty', 'rule', 'property',
|
|
30
31
|
'validationError', 'focus', 'code', 'permissionPolicy', 'permissionRule', 'prohibitionPolicy',
|
|
31
32
|
'prohibitionRule', 'conflictCount']) PROPERTIES.set(name, ODRL_EVAL + name);
|
|
32
33
|
// A conflict is an evaluation report link; policy-local conflict has a
|
|
@@ -36,11 +37,19 @@ PROPERTIES.set('policyConflict', ODRL + 'conflict');
|
|
|
36
37
|
PROPERTIES.set('applicablePermission', ODRL_EVAL + 'permission');
|
|
37
38
|
PROPERTIES.set('applicableProhibition', ODRL_EVAL + 'prohibition');
|
|
38
39
|
PROPERTIES.set('reportConstraint', ODRL_EVAL + 'constraint');
|
|
40
|
+
PROPERTIES.set('reportDuty', ODRL_EVAL + 'duty');
|
|
39
41
|
PROPERTIES.set('type', RDF + 'type');
|
|
42
|
+
const LIST_OPERANDS = new Set();
|
|
43
|
+
for (const name of ['and', 'or', 'xone']) {
|
|
44
|
+
const property = ODRL + name;
|
|
45
|
+
PROPERTIES.set(name + 'Operands', property);
|
|
46
|
+
LIST_OPERANDS.add(property);
|
|
47
|
+
}
|
|
40
48
|
const VALUES = new Map(Object.entries({
|
|
41
49
|
snapshotProfile: ODRL_EVAL + 'SnapshotProfile',
|
|
42
50
|
perm: ODRL + 'perm', prohibit: ODRL + 'prohibit', invalid: ODRL + 'invalid',
|
|
43
51
|
eq: ODRL + 'eq', neq: ODRL + 'neq', gt: ODRL + 'gt', gteq: ODRL + 'gteq', lt: ODRL + 'lt', lteq: ODRL + 'lteq',
|
|
52
|
+
withinCategory: ODRL_EVAL + 'withinCategory',
|
|
44
53
|
allowed: ODRL_EVAL + 'Allowed', prohibited: ODRL_EVAL + 'Prohibited',
|
|
45
54
|
notApplicable: ODRL_EVAL + 'NotApplicable', undetermined: ODRL_EVAL + 'Undetermined',
|
|
46
55
|
valid: ODRL_EVAL + 'Valid', invalidReport: ODRL_EVAL + 'Invalid',
|
|
@@ -63,6 +72,32 @@ function resource(term) {
|
|
|
63
72
|
return term instanceof Struct && ['iri', 'bnode', 'triple', 'skolem'].includes(term.name);
|
|
64
73
|
}
|
|
65
74
|
|
|
75
|
+
// The LE operand abbreviations accept a list of constraint references.
|
|
76
|
+
// Convert it to the same RDF first/rest links used by Turtle collections.
|
|
77
|
+
function expandOperandLists(quads, namespace) {
|
|
78
|
+
const lists = quads.filter(([, p, o]) => LIST_OPERANDS.has(p.args[0]) && properListItems(o) !== null);
|
|
79
|
+
if (!lists.length) return;
|
|
80
|
+
const scopes = new Set(), pending = quads.flatMap((quad) => quad.slice(0, 3));
|
|
81
|
+
while (pending.length) {
|
|
82
|
+
const term = pending.pop();
|
|
83
|
+
if (!(term instanceof Struct)) continue;
|
|
84
|
+
if (term.name === 'bnode') scopes.add(term.args[0]);
|
|
85
|
+
pending.push(...term.args);
|
|
86
|
+
}
|
|
87
|
+
let scope = 'le-odrl-list', suffix = 0, label = 0;
|
|
88
|
+
while (scopes.has(scope)) scope = `le-odrl-list-${++suffix}`;
|
|
89
|
+
for (const quad of lists) {
|
|
90
|
+
let tail = iri(RDF + 'nil');
|
|
91
|
+
for (const item of properListItems(quad[2]).reverse()) {
|
|
92
|
+
const cell = new Struct('bnode', [scope, String(++label)]);
|
|
93
|
+
quads.push([cell, iri(RDF + 'first'), rdfValue(item, namespace), DEFAULT_GRAPH],
|
|
94
|
+
[cell, iri(RDF + 'rest'), tail, DEFAULT_GRAPH]);
|
|
95
|
+
tail = cell;
|
|
96
|
+
}
|
|
97
|
+
quad[2] = tail;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
66
101
|
export function compileOdrlLe(statements, profile, source) {
|
|
67
102
|
const { namespace, evaluate } = profile;
|
|
68
103
|
const quads = [];
|
|
@@ -77,7 +112,8 @@ export function compileOdrlLe(statements, profile, source) {
|
|
|
77
112
|
o = iri(TYPES.get(head.name) ?? namespace + head.name);
|
|
78
113
|
} else if (head.args.length === 2) {
|
|
79
114
|
s = rdfValue(head.args[0], namespace); p = iri(PROPERTIES.get(head.name) ?? namespace + head.name);
|
|
80
|
-
|
|
115
|
+
const value = head.args[1];
|
|
116
|
+
o = LIST_OPERANDS.has(p.args[0]) && properListItems(value) !== null ? value : rdfValue(value, namespace);
|
|
81
117
|
} 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
118
|
if (!resource(s) || !(p instanceof Struct && p.name === 'iri' && p.args.length === 1)) {
|
|
83
119
|
throw new EyemindError(`${statement.file}: line ${statement.line}: an LE ODRL triple needs a resource subject and an IRI property`);
|
|
@@ -85,6 +121,7 @@ export function compileOdrlLe(statements, profile, source) {
|
|
|
85
121
|
quads.push([s, p, o, DEFAULT_GRAPH]);
|
|
86
122
|
}
|
|
87
123
|
}
|
|
124
|
+
expandOperandLists(quads, namespace);
|
|
88
125
|
// Validate RDF constructors without rewriting terms or witness identities.
|
|
89
126
|
const pending = quads.flatMap((quad) => quad.slice(0, 3));
|
|
90
127
|
while (pending.length) {
|
package/src/le.js
CHANGED
|
@@ -6,10 +6,15 @@ 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
8
|
import { compileOdrlLe, odrlLeReport } from './le-odrl.js';
|
|
9
|
+
import { dpvRules } from './dpv.js';
|
|
10
|
+
import { loadText } from './lang.js';
|
|
9
11
|
|
|
10
12
|
const st = (name, ...args) => new Struct(name, args);
|
|
11
13
|
const VARIABLE = /^[A-Z][0-9]*$/;
|
|
12
14
|
const NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
15
|
+
const PREFIX = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
16
|
+
const LOCAL = /^[A-Za-z0-9_][A-Za-z0-9_-]*$/;
|
|
17
|
+
const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
13
18
|
const SENTENCE_WORDS = new Set(['every', 'for', 'if', 'find', 'there', 'it', 'contradiction', 'use']);
|
|
14
19
|
const RESERVED = new Set([...PRIMITIVE_KEYS, ...CONTROL_KEYS, ...RESERVED_KEYS].map((key) => key.split('/')[0]));
|
|
15
20
|
for (const name of ['true', 'false', 'fail']) RESERVED.add(name);
|
|
@@ -81,6 +86,7 @@ class Parser {
|
|
|
81
86
|
this.scope = new Map();
|
|
82
87
|
this.closed = new Set();
|
|
83
88
|
this.helpers = new Set();
|
|
89
|
+
this.prefixes = new Map();
|
|
84
90
|
this.aggregates = 0;
|
|
85
91
|
this.depth = 0;
|
|
86
92
|
let line = 1, pos = 0;
|
|
@@ -89,7 +95,7 @@ class Parser {
|
|
|
89
95
|
const whitespace = /^\s+/.exec(tail);
|
|
90
96
|
if (whitespace) { line += (whitespace[0].match(/\n/g) ?? []).length; pos += whitespace[0].length; continue; }
|
|
91
97
|
if (tail[0] === '#') { const end = text.indexOf('\n', pos); pos = end < 0 ? text.length : end; continue; }
|
|
92
|
-
const match = /^("(?:[^"\\\r\n]|\\.)*"|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|[A-Za-z][A-Za-z0-9_]
|
|
98
|
+
const match = /^("(?:[^"\\\r\n]|\\.)*"|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|[A-Za-z][A-Za-z0-9_]*(?::[A-Za-z0-9_][A-Za-z0-9_-]*)?|[()[\],.+*/-])/.exec(tail);
|
|
93
99
|
if (!match) this.error(`unexpected character ${JSON.stringify(tail[0])}`, line);
|
|
94
100
|
const raw = match[0];
|
|
95
101
|
let value = raw, kind = 'word';
|
|
@@ -98,6 +104,7 @@ class Parser {
|
|
|
98
104
|
kind = 'string';
|
|
99
105
|
} else if (/^[0-9]/.test(raw)) kind = 'number';
|
|
100
106
|
else if (!/^[A-Za-z]/.test(raw)) kind = 'punct';
|
|
107
|
+
else if (raw.includes(':')) kind = 'qualified';
|
|
101
108
|
this.tokens.push({ value, raw, kind, line });
|
|
102
109
|
pos += raw.length;
|
|
103
110
|
}
|
|
@@ -112,6 +119,7 @@ class Parser {
|
|
|
112
119
|
|
|
113
120
|
name() {
|
|
114
121
|
const token = this.token;
|
|
122
|
+
if (token.kind === 'qualified') return this.qualifiedName();
|
|
115
123
|
if (token.kind !== 'word' || !NAME.test(token.value) || RESERVED.has(token.value)) {
|
|
116
124
|
this.error('a relation or class name must start with a lowercase letter and must not name an LS primitive or control');
|
|
117
125
|
}
|
|
@@ -119,6 +127,21 @@ class Parser {
|
|
|
119
127
|
return token.value;
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
qualifiedName() {
|
|
131
|
+
const token = this.token, [prefix, local] = token.value.split(':');
|
|
132
|
+
if (!this.prefixes.has(prefix)) this.error(`prefix ${prefix} is undeclared; introduce it with "Use prefix ${prefix} with namespace …"`, token.line);
|
|
133
|
+
this.at++;
|
|
134
|
+
return st('iri', this.prefixes.get(prefix) + local);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
statement(name, subject, ...objects) {
|
|
138
|
+
if (typeof name === 'string') return st(name, subject, ...objects);
|
|
139
|
+
if (!rdfResource(subject)) this.error('a qualified RDF statement needs a resource subject such as ex:item, iri(...) or a variable');
|
|
140
|
+
if (!objects.length) return st('rdf', subject, st('iri', RDF_TYPE), name);
|
|
141
|
+
if (!rdfValue(objects[0])) this.error('a qualified RDF property needs an RDF value such as a qualified name, number or literal(...)');
|
|
142
|
+
return st('rdf', subject, name, objects[0]);
|
|
143
|
+
}
|
|
144
|
+
|
|
122
145
|
declarations() {
|
|
123
146
|
const vars = [];
|
|
124
147
|
do {
|
|
@@ -172,6 +195,7 @@ class Parser {
|
|
|
172
195
|
return st('skolem', rule, label.value, list(args));
|
|
173
196
|
}
|
|
174
197
|
const token = this.token;
|
|
198
|
+
if (token.kind === 'qualified') return this.qualifiedName();
|
|
175
199
|
if (!['word', 'string'].includes(token.kind)) this.error('expected a name, number, variable, list or compound term');
|
|
176
200
|
this.at++;
|
|
177
201
|
if (this.take('(')) {
|
|
@@ -221,14 +245,14 @@ class Parser {
|
|
|
221
245
|
const subject = this.term();
|
|
222
246
|
if (this.take('has')) {
|
|
223
247
|
const name = this.name();
|
|
224
|
-
return
|
|
248
|
+
return this.statement(name, subject, this.term());
|
|
225
249
|
}
|
|
226
250
|
if (this.take('is')) {
|
|
227
251
|
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');
|
|
228
252
|
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');
|
|
229
253
|
if (this.take('a') || this.take('an')) {
|
|
230
254
|
const name = this.name();
|
|
231
|
-
return this.take('of') ?
|
|
255
|
+
return this.take('of') ? this.statement(name, subject, this.term()) : this.statement(name, subject);
|
|
232
256
|
}
|
|
233
257
|
if (body) {
|
|
234
258
|
if (this.take('the')) {
|
|
@@ -252,7 +276,7 @@ class Parser {
|
|
|
252
276
|
}
|
|
253
277
|
}
|
|
254
278
|
// Adjectival class form, as in "Every human is mortal".
|
|
255
|
-
return
|
|
279
|
+
return this.statement(this.name(), subject);
|
|
256
280
|
}
|
|
257
281
|
if (subject instanceof Struct && subject.name !== '.' && NAME.test(subject.name) && !RESERVED.has(subject.name)) return subject;
|
|
258
282
|
if (typeof subject === 'string' && NAME.test(subject) && !RESERVED.has(subject)) return subject;
|
|
@@ -327,31 +351,50 @@ class Parser {
|
|
|
327
351
|
return bound;
|
|
328
352
|
}
|
|
329
353
|
|
|
354
|
+
namespace(label) {
|
|
355
|
+
this.need('with'); this.need('namespace');
|
|
356
|
+
if (this.token.kind !== 'string') this.error(`${label} namespace must be a quoted absolute IRI`);
|
|
357
|
+
const namespace = this.token.value;
|
|
358
|
+
try { new URL(namespace); } catch { this.error(`${label} namespace must be an absolute IRI`); }
|
|
359
|
+
if (/[\s<>"{}|^`\\]/u.test(namespace)) this.error(`${label} namespace must be an absolute IRI without whitespace or forbidden characters`);
|
|
360
|
+
this.at++; this.need('.');
|
|
361
|
+
return namespace;
|
|
362
|
+
}
|
|
363
|
+
|
|
330
364
|
sentence() {
|
|
331
365
|
const line = this.token.line;
|
|
332
366
|
this.scope = new Map();
|
|
333
367
|
this.closed = new Set();
|
|
368
|
+
if (this.is('use') && this.tokens[this.at + 1]?.kind === 'word' && this.tokens[this.at + 1].value.toLowerCase() === 'dpv') {
|
|
369
|
+
this.at += 2;
|
|
370
|
+
this.need('hierarchy'); this.need('logic'); this.need('.');
|
|
371
|
+
return { kind: 'dpv', line };
|
|
372
|
+
}
|
|
373
|
+
if (this.is('use') && this.tokens[this.at + 1]?.kind === 'word' && this.tokens[this.at + 1].value.toLowerCase() === 'prefix') {
|
|
374
|
+
this.at += 2;
|
|
375
|
+
const prefix = this.token.value;
|
|
376
|
+
if (this.token.kind !== 'word' || !PREFIX.test(prefix)) this.error('expected a prefix name such as dpv');
|
|
377
|
+
if (this.prefixes.has(prefix)) this.error(`prefix ${prefix} is already declared in this file`);
|
|
378
|
+
this.at++;
|
|
379
|
+
this.prefixes.set(prefix, this.namespace('a prefix'));
|
|
380
|
+
return { kind: 'prefix', line };
|
|
381
|
+
}
|
|
334
382
|
if (this.is('use') && this.tokens[this.at + 1]?.kind === 'word' && this.tokens[this.at + 1].value.toLowerCase() === 'odrl') {
|
|
335
383
|
this.at++;
|
|
336
384
|
this.need('odrl');
|
|
337
385
|
let evaluate = false;
|
|
338
386
|
if (this.take('snapshot')) { this.need('logic'); evaluate = true; }
|
|
339
387
|
else this.need('vocabulary');
|
|
340
|
-
this.
|
|
341
|
-
if (this.token.kind !== 'string') this.error('an ODRL namespace must be a quoted absolute IRI');
|
|
342
|
-
const namespace = this.token.value;
|
|
343
|
-
try { new URL(namespace); } catch { this.error('an ODRL namespace must be an absolute IRI'); }
|
|
344
|
-
if (/[\s<>"{}|^`\\]/u.test(namespace)) this.error('an ODRL namespace must be an absolute IRI without whitespace or forbidden characters');
|
|
345
|
-
this.at++; this.need('.');
|
|
388
|
+
const namespace = this.namespace('an ODRL');
|
|
346
389
|
return { kind: 'odrl', namespace, evaluate, line };
|
|
347
390
|
}
|
|
348
391
|
if (this.take('every')) {
|
|
349
392
|
const x = new Var('X'), froms = [this.name()], heads = [];
|
|
350
393
|
while (this.take('or')) froms.push(this.name());
|
|
351
394
|
this.need('is');
|
|
352
|
-
do { this.take('a') || this.take('an'); heads.push(
|
|
395
|
+
do { this.take('a') || this.take('an'); heads.push(this.statement(this.name(), x)); } while (this.take('and'));
|
|
353
396
|
this.need('.');
|
|
354
|
-
return { kind: 'forward', heads, bodies: froms.map((from) => [
|
|
397
|
+
return { kind: 'forward', heads, bodies: froms.map((from) => [this.statement(from, x)]), line };
|
|
355
398
|
}
|
|
356
399
|
let quantified = false;
|
|
357
400
|
if (this.take('for')) { this.need('every'); this.declarations(); this.need(','); quantified = true; }
|
|
@@ -392,6 +435,17 @@ class Parser {
|
|
|
392
435
|
}
|
|
393
436
|
}
|
|
394
437
|
|
|
438
|
+
function rdfResource(term) {
|
|
439
|
+
return term instanceof Var || term instanceof Struct &&
|
|
440
|
+
(term.name === 'iri' && term.args.length === 1 && typeof term.args[0] === 'string' ||
|
|
441
|
+
term.name === 'bnode' && term.args.length === 2 || term.name === 'skolem' && term.args.length === 3);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function rdfValue(term) {
|
|
445
|
+
return rdfResource(term) || typeof term === 'bigint' || typeof term === 'number' ||
|
|
446
|
+
term instanceof Struct && (term.name === 'literal' && term.args.length === 2 || term.name === 'triple' && term.args.length === 3);
|
|
447
|
+
}
|
|
448
|
+
|
|
395
449
|
function variablesIn(terms) {
|
|
396
450
|
const result = new Set(), pending = [...terms];
|
|
397
451
|
while (pending.length) {
|
|
@@ -412,14 +466,20 @@ function javascript(term) {
|
|
|
412
466
|
}
|
|
413
467
|
|
|
414
468
|
export function compileLe(inputs) {
|
|
415
|
-
const clauses = [], statements = [], sources = [], helpers = new Set();
|
|
416
|
-
let profile = null;
|
|
469
|
+
const clauses = [], statements = [], sources = [], helpers = new Set(), prefixes = new Map();
|
|
470
|
+
let profile = null, dpv = false;
|
|
417
471
|
for (const [text, file] of inputs) {
|
|
418
472
|
const parser = new Parser(String(text), file);
|
|
419
473
|
while (parser.token.kind !== 'end') {
|
|
420
474
|
const sentence = parser.sentence(), { kind, heads, bodies, line } = sentence;
|
|
475
|
+
if (kind === 'prefix') continue;
|
|
476
|
+
if (kind === 'dpv') {
|
|
477
|
+
if (profile) parser.error('the DPV hierarchy directive belongs to ordinary LE; an ODRL snapshot uses its withinCategory operator', line);
|
|
478
|
+
dpv = true;
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
421
481
|
if (kind === 'odrl') {
|
|
422
|
-
if (profile || statements.length || inputs.length !== 1) parser.error('an ODRL directive must be the first sentence of one LE file', line);
|
|
482
|
+
if (profile || dpv || statements.length || parser.prefixes.size || inputs.length !== 1) parser.error('an ODRL directive must be the first sentence of one LE file', line);
|
|
423
483
|
profile = { namespace: sentence.namespace, evaluate: sentence.evaluate };
|
|
424
484
|
continue;
|
|
425
485
|
}
|
|
@@ -441,8 +501,12 @@ export function compileLe(inputs) {
|
|
|
441
501
|
}
|
|
442
502
|
}
|
|
443
503
|
for (const name of parser.helpers) helpers.add(name);
|
|
504
|
+
for (const [prefix, namespace] of parser.prefixes) prefixes.set(prefix, namespace);
|
|
505
|
+
}
|
|
506
|
+
if (profile) {
|
|
507
|
+
const loaded = compileOdrlLe(statements, profile, inputs[0][1]);
|
|
508
|
+
return { ...loaded, prefixes: { ...loaded.prefixes, ...Object.fromEntries(prefixes) } };
|
|
444
509
|
}
|
|
445
|
-
if (profile) return compileOdrlLe(statements, profile, inputs[0][1]);
|
|
446
510
|
// The helpers follow every stated clause, so a witness's rule number is
|
|
447
511
|
// the same whether or not the program aggregates.
|
|
448
512
|
if (helpers.size) clauses.push('// Aggregation helpers.');
|
|
@@ -453,11 +517,16 @@ export function compileLe(inputs) {
|
|
|
453
517
|
sources.push(new Source('backward', head, body.length ? body : ['true'], null, null));
|
|
454
518
|
}
|
|
455
519
|
}
|
|
520
|
+
if (dpv) {
|
|
521
|
+
const rules = dpvRules('rdf', true);
|
|
522
|
+
sources.push(...loadText(rules, 'DPV hierarchy rules').sources);
|
|
523
|
+
clauses.push(rules);
|
|
524
|
+
}
|
|
456
525
|
return { kind: 'le', text: '// Compiled from Logical English to Logic Script.\n\n' + clauses.join('\n') + '\n',
|
|
457
|
-
program: new Program(sources), prefixes:
|
|
526
|
+
program: new Program(sources), prefixes: Object.fromEntries(prefixes), compiled: { statements } };
|
|
458
527
|
}
|
|
459
528
|
|
|
460
|
-
function leTerm(term, names) {
|
|
529
|
+
function leTerm(term, names, compact) {
|
|
461
530
|
if (term instanceof Var) return names.get(term.name);
|
|
462
531
|
if (term === EMPTY) return '[]';
|
|
463
532
|
if (typeof term === 'string') {
|
|
@@ -465,43 +534,74 @@ function leTerm(term, names) {
|
|
|
465
534
|
}
|
|
466
535
|
if (typeof term === 'bigint' || typeof term === 'number') return write(term);
|
|
467
536
|
if (!(term instanceof Struct)) throw new EyemindError('cannot write this term as Logical English');
|
|
537
|
+
const qualified = compact(term);
|
|
538
|
+
if (qualified) return qualified;
|
|
539
|
+
const render = (arg) => leTerm(arg, names, compact);
|
|
468
540
|
if (term.name === 'skolem' && term.args.length === 3) {
|
|
469
541
|
const [rule, label, bindings] = term.args, args = listItems(bindings);
|
|
470
542
|
if (typeof rule === 'bigint' && rule > 0n && typeof label === 'string' && args !== null) {
|
|
471
543
|
const name = VARIABLE.test(label) ? label : JSON.stringify(label);
|
|
472
|
-
return `witness(rule ${rule}, ${name}${args.map((arg) => ', ' +
|
|
544
|
+
return `witness(rule ${rule}, ${name}${args.map((arg) => ', ' + render(arg)).join('')})`;
|
|
473
545
|
}
|
|
474
546
|
}
|
|
475
547
|
if (term.name === '.') {
|
|
476
548
|
const items = listItems(term);
|
|
477
|
-
if (items !== null) return `[${items.map(
|
|
549
|
+
if (items !== null) return `[${items.map(render).join(', ')}]`;
|
|
478
550
|
// Improper lists remain explicit compounds.
|
|
479
551
|
}
|
|
480
|
-
return `${JSON.stringify(term.name)}(${term.args.map(
|
|
552
|
+
return `${JSON.stringify(term.name)}(${term.args.map(render).join(', ')})`;
|
|
481
553
|
}
|
|
482
554
|
|
|
483
|
-
function leGoal(term,
|
|
555
|
+
function leGoal(term, render, properties, compact) {
|
|
484
556
|
if (term === 'false') return 'Contradiction';
|
|
485
|
-
if (typeof term === 'string' && NAME.test(term) && !RESERVED.has(term)) return
|
|
557
|
+
if (typeof term === 'string' && NAME.test(term) && !RESERVED.has(term)) return render(term);
|
|
486
558
|
if (!(term instanceof Struct) || !NAME.test(term.name) || RESERVED.has(term.name)) {
|
|
487
559
|
throw new EyemindError(`${write(term)} is not a Logical English relation; use --to eyemind`);
|
|
488
560
|
}
|
|
561
|
+
if (term.name === 'rdf' && term.args.length === 3) {
|
|
562
|
+
const [s, p, o] = term.args;
|
|
563
|
+
if (rdfResource(s) && rdfValue(o)) {
|
|
564
|
+
if (p instanceof Struct && p.name === 'iri' && p.args.length === 1 && p.args[0] === RDF_TYPE) {
|
|
565
|
+
const type = compact(o);
|
|
566
|
+
if (type) return `${render(s)} is a ${type}`;
|
|
567
|
+
}
|
|
568
|
+
const property = compact(p);
|
|
569
|
+
if (property) return `${render(s)} has ${property} ${render(o)}`;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
489
572
|
const article = /^[aeiou]/.test(term.name) ? 'an' : 'a';
|
|
490
|
-
if (term.args.length === 1) return `${
|
|
491
|
-
if (properties && term.args.length === 2) return `${
|
|
492
|
-
if (term.args.length === 2) return `${
|
|
493
|
-
return `${term.name}(${term.args.map(
|
|
573
|
+
if (term.args.length === 1) return `${render(term.args[0])} is ${article} ${term.name}`;
|
|
574
|
+
if (properties && term.args.length === 2) return `${render(term.args[0])} has ${term.name} ${render(term.args[1])}`;
|
|
575
|
+
if (term.args.length === 2) return `${render(term.args[0])} is ${article} ${term.name} of ${render(term.args[1])}`;
|
|
576
|
+
return `${term.name}(${term.args.map(render).join(', ')})`;
|
|
494
577
|
}
|
|
495
578
|
|
|
496
|
-
export function writeLe(result, { odrl = null } = {}) {
|
|
579
|
+
export function writeLe(result, { odrl = null, prefixes = {} } = {}) {
|
|
497
580
|
if (odrl) result = odrlLeReport(result, odrl.namespace);
|
|
581
|
+
const namespaces = odrl ? [] : Object.entries(prefixes).filter(([prefix]) => PREFIX.test(prefix))
|
|
582
|
+
.sort((a, b) => b[1].length - a[1].length);
|
|
583
|
+
const used = new Map();
|
|
584
|
+
const compact = (term) => {
|
|
585
|
+
if (!(term instanceof Struct) || term.name !== 'iri' || term.args.length !== 1 || typeof term.args[0] !== 'string') return null;
|
|
586
|
+
for (const [prefix, namespace] of namespaces) {
|
|
587
|
+
if (!term.args[0].startsWith(namespace)) continue;
|
|
588
|
+
const local = term.args[0].slice(namespace.length);
|
|
589
|
+
if (!LOCAL.test(local)) continue;
|
|
590
|
+
used.set(prefix, namespace);
|
|
591
|
+
return `${prefix}:${local}`;
|
|
592
|
+
}
|
|
593
|
+
return null;
|
|
594
|
+
};
|
|
498
595
|
const lines = [];
|
|
499
596
|
for (const answer of result.answers) {
|
|
500
597
|
const term = readTerm(answer);
|
|
501
598
|
const names = new Map([...variablesIn([term])].map((name, i) => [name, `X${i}`]));
|
|
502
599
|
const quantifier = names.size ? `For every ${[...names.values()].join(' and ')}, ` : '';
|
|
503
|
-
|
|
600
|
+
const render = (arg) => leTerm(arg, names, compact);
|
|
601
|
+
lines.push(quantifier + flattenConjunction(term).map((goal) => leGoal(goal, render, odrl !== null, compact)).join(' and ') + '.');
|
|
504
602
|
}
|
|
505
|
-
const
|
|
603
|
+
const declarations = [...used].sort().map(([prefix, namespace]) => `Use prefix ${prefix} with namespace ${JSON.stringify(namespace)}.`);
|
|
604
|
+
const header = odrl ? `Use ODRL vocabulary with namespace ${JSON.stringify(odrl.namespace)}.\n\n`
|
|
605
|
+
: declarations.length ? `${declarations.join('\n')}\n\n` : '';
|
|
506
606
|
return header + (lines.length ? lines.join('\n') + '\n' : '# No conclusions.\n');
|
|
507
607
|
}
|
package/src/odrl.js
CHANGED
|
@@ -6,6 +6,7 @@ import { EyemindError, Struct } from './terms.js';
|
|
|
6
6
|
import { DEFAULT_GRAPH } from './rdf.js';
|
|
7
7
|
import { loadText } from './lang.js';
|
|
8
8
|
import { write } from './writer.js';
|
|
9
|
+
import { DPV, DPV_PROPERTIES, dpvRules } from './dpv.js';
|
|
9
10
|
|
|
10
11
|
export const ODRL_EVAL = 'https://eyereasoner.github.io/eyemind/odrl#';
|
|
11
12
|
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
@@ -35,7 +36,10 @@ const evalNS = 'https://eyereasoner.github.io/eyemind/odrl#';
|
|
|
35
36
|
const xsdNS = 'http://www.w3.org/2001/XMLSchema#';
|
|
36
37
|
const o = (name) => iri(odrlNS + name);
|
|
37
38
|
const e = (name) => iri(evalNS + name);
|
|
38
|
-
const
|
|
39
|
+
const rdfNS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
40
|
+
const rdfType = iri(rdfNS + 'type');
|
|
41
|
+
const rdfFirst = iri(rdfNS + 'first'), rdfRest = iri(rdfNS + 'rest'), rdfNil = iri(rdfNS + 'nil');
|
|
42
|
+
${dpvRules('odrl_input')}
|
|
39
43
|
|
|
40
44
|
implies(odrl_input(E, rdfType, e('Evaluation')), odrl_evaluation(E));
|
|
41
45
|
implies(odrl_evaluation(E), odrl_node(E, E, 'evaluation'));
|
|
@@ -44,7 +48,11 @@ implies([odrl_evaluation(E), odrl_input(E, e('request'), Q)], odrl_node(E, Q, 'r
|
|
|
44
48
|
implies([odrl_node(E, P, 'policy'), odrl_input(P, o('permission'), R)], odrl_rule(E, P, R, 'permission'));
|
|
45
49
|
implies([odrl_node(E, P, 'policy'), odrl_input(P, o('prohibition'), R)], odrl_rule(E, P, R, 'prohibition'));
|
|
46
50
|
implies(odrl_rule(E, P, R, K), odrl_node(E, R, K));
|
|
47
|
-
implies([odrl_rule(E, P, R, K), odrl_input(R, o('constraint'), C)],
|
|
51
|
+
implies([odrl_rule(E, P, R, K), odrl_input(R, o('constraint'), C)], odrl_root_constraint(E, C));
|
|
52
|
+
implies([odrl_root_constraint(E, C), odrl_input(C, rdfType, o('LogicalConstraint'))], odrl_node(E, C, 'logical'));
|
|
53
|
+
implies([odrl_root_constraint(E, C), not(odrl_input(C, rdfType, o('LogicalConstraint')))], odrl_node(E, C, 'constraint'));
|
|
54
|
+
implies([odrl_node(E, C, 'logical'), odrl_logical(C, Op, Members), odrl_member(A, Members)], odrl_node(E, A, 'constraint'));
|
|
55
|
+
implies([odrl_rule(E, P, R, 'permission'), odrl_input(R, o('duty'), D)], odrl_node(E, D, 'duty'));
|
|
48
56
|
implies([odrl_node(E, Q, 'request'), odrl_input(Q, e('state'), S)], odrl_node(E, S, 'state'));
|
|
49
57
|
implies([odrl_rule(E, P, R, K), odrl_input(R, o('action'), A)], odrl_node(E, A, 'action'));
|
|
50
58
|
implies([odrl_node(E, Q, 'request'), odrl_input(Q, o('action'), A)], odrl_node(E, A, 'action'));
|
|
@@ -70,14 +78,23 @@ for (const [kind, predicate, min, max, valueKind] of [
|
|
|
70
78
|
['request', o('target'), 1, 1, 'resource'],
|
|
71
79
|
['request', e('subject'), 1, 1, 'resource'],
|
|
72
80
|
['request', e('state'), 1, 1, 'resource'],
|
|
81
|
+
['request', e('fulfilledDuty'), 0, -1, 'resource'],
|
|
82
|
+
['request', e('unfulfilledDuty'), 0, -1, 'resource'],
|
|
73
83
|
['state', rdfType, 1, 1, 'type'],
|
|
74
84
|
['state', e('subject'), 1, 1, 'resource'],
|
|
75
85
|
['constraint', rdfType, 0, 1, 'type'],
|
|
76
86
|
['constraint', o('leftOperand'), 1, 1, 'iri'],
|
|
77
87
|
['constraint', o('operator'), 1, 1, 'operator'],
|
|
78
88
|
['constraint', o('rightOperand'), 1, 1, 'scalar'],
|
|
89
|
+
['logical', rdfType, 1, 1, 'type'],
|
|
90
|
+
['duty', rdfType, 1, 1, 'type'],
|
|
91
|
+
['duty', o('action'), 1, 1, 'iri'],
|
|
79
92
|
['action', rdfType, 0, 1, 'type'],
|
|
80
93
|
]) fact(odrl_field(kind, predicate, min, max, valueKind));
|
|
94
|
+
fact(odrl_field('permission', o('duty'), 0, -1, 'resource'));
|
|
95
|
+
for (const name of ['and', 'or', 'xone']) {
|
|
96
|
+
fact(odrl_operand(o(name)), odrl_field('logical', o(name), 0, 1, 'resource'));
|
|
97
|
+
}
|
|
81
98
|
for (const kind of ['permission', 'prohibition']) {
|
|
82
99
|
fact(odrl_field(kind, rdfType, 0, 1, 'type'));
|
|
83
100
|
for (const name of ['assignee', 'action', 'target']) fact(odrl_field(kind, o(name), 1, 1, name === 'action' ? 'iri' : 'resource'));
|
|
@@ -87,6 +104,7 @@ for (const [kind, type] of [
|
|
|
87
104
|
['evaluation', e('Evaluation')], ['request', e('Request')], ['state', e('State')],
|
|
88
105
|
['policy', o('Set')], ['policy', o('Agreement')],
|
|
89
106
|
['permission', o('Permission')], ['prohibition', o('Prohibition')], ['constraint', o('Constraint')],
|
|
107
|
+
['logical', o('LogicalConstraint')], ['duty', o('Duty')],
|
|
90
108
|
['action', o('Action')],
|
|
91
109
|
]) fact(odrl_type(kind, type));
|
|
92
110
|
for (const predicate of [
|
|
@@ -95,11 +113,33 @@ for (const predicate of [
|
|
|
95
113
|
]) fact(odrl_metadata(iri(predicate)));
|
|
96
114
|
for (const name of ['perm', 'prohibit', 'invalid']) fact(odrl_strategy_value(o(name)));
|
|
97
115
|
for (const name of ['eq', 'neq', 'gt', 'gteq', 'lt', 'lteq']) fact(odrl_operator(o(name)));
|
|
116
|
+
fact(odrl_operator(e('withinCategory')));
|
|
117
|
+
for (const property of ${JSON.stringify(Object.keys(DPV_PROPERTIES).map((name) => DPV + name))}) {
|
|
118
|
+
fact(odrl_category_property(iri(property)));
|
|
119
|
+
}
|
|
98
120
|
|
|
99
121
|
fact(odrl_count([], 0));
|
|
100
122
|
implied_by(odrl_count([_, ...T], N), [odrl_count(T, M), is(N, add(M, 1))]);
|
|
101
123
|
implied_by(odrl_resource(iri(V)), is_atom(V));
|
|
102
124
|
implied_by(odrl_resource(bnode(S, V)), [is_atom(S), is_atom(V)]);
|
|
125
|
+
|
|
126
|
+
// Read the one RDF operand list. Follow each cell once and require distinct
|
|
127
|
+
// members, so cyclic, branching and repeated lists cannot grant permission.
|
|
128
|
+
fact(odrl_member(X, [X, ...Tail]));
|
|
129
|
+
implied_by(odrl_member(X, [Head, ...Tail]), odrl_member(X, Tail));
|
|
130
|
+
implied_by(odrl_list(rdfNil, Seen, []), [not(odrl_input(rdfNil, rdfFirst, _)), not(odrl_input(rdfNil, rdfRest, _))]);
|
|
131
|
+
implied_by(odrl_list(Cell, Seen, [A, ...Tail]), [
|
|
132
|
+
odrl_resource(Cell), not_identical(Cell, rdfNil), not(odrl_member(Cell, Seen)),
|
|
133
|
+
findall_sorted(V, odrl_input(Cell, rdfFirst, V), First), unify(First, [A]), odrl_resource(A),
|
|
134
|
+
findall_sorted(V, odrl_input(Cell, rdfRest, V), Rest), unify(Rest, [Next]),
|
|
135
|
+
odrl_list(Next, [Cell, ...Seen], Tail), not(odrl_member(A, Tail)),
|
|
136
|
+
]);
|
|
137
|
+
implied_by(odrl_operand_value(C, Op, L), [odrl_operand(Op), odrl_input(C, Op, L)]);
|
|
138
|
+
implied_by(odrl_logical(C, Op, Members), [
|
|
139
|
+
findall_sorted(pair(P, L), odrl_operand_value(C, P, L), Operands), unify(Operands, [pair(Op, Head)]),
|
|
140
|
+
odrl_list(Head, [], Members), unify(Members, [A, B, ...Tail]),
|
|
141
|
+
]);
|
|
142
|
+
|
|
103
143
|
implied_by(odrl_scalar(V, 'integer', V), is_int(V));
|
|
104
144
|
implied_by(odrl_scalar(iri(V), 'iri', V), is_atom(V));
|
|
105
145
|
implied_by(odrl_scalar(literal(V, datatype(xsdNS + 'string')), 'string', V), is_atom(V));
|
|
@@ -132,6 +172,11 @@ implies([odrl_node(E, S, K), odrl_input(S, P, V), not(odrl_known_field(K, P))],
|
|
|
132
172
|
implies([odrl_node(E, S, K), odrl_input(S, rdfType, T), not(odrl_type(K, T))],
|
|
133
173
|
odrl_problem(E, S, rdfType, e('UnsupportedType')));
|
|
134
174
|
implies([odrl_node(E, P, 'policy'), not(odrl_has_rule(P))], odrl_problem(E, P, rdfType, e('MissingRule')));
|
|
175
|
+
implies([odrl_node(E, C, 'logical'), not(odrl_logical(C, _, _))], odrl_problem(E, C, o('operand'), e('InvalidLogicalOperands')));
|
|
176
|
+
for (const name of ['fulfilledDuty', 'unfulfilledDuty']) {
|
|
177
|
+
implies([odrl_node(E, Q, 'request'), odrl_input(Q, e(name), D), not(odrl_node(E, D, 'duty'))],
|
|
178
|
+
odrl_problem(E, Q, e(name), e('UnknownDuty')));
|
|
179
|
+
}
|
|
135
180
|
implies([odrl_evaluation(E), findall_sorted(X, odrl_evaluation(X), Es), odrl_count(Es, N), ne(N, 1)],
|
|
136
181
|
odrl_problem(E, E, rdfType, e('MultipleEvaluations')));
|
|
137
182
|
implies([odrl_node(E, Q, 'request'), odrl_input(Q, e('state'), S),
|
|
@@ -151,6 +196,10 @@ implied_by(odrl_syntax_error(E), odrl_problem(E, _, _, _));
|
|
|
151
196
|
implied_by(odrl_order_kind(o('eq'), K), 'true');
|
|
152
197
|
implied_by(odrl_order_kind(o('neq'), K), 'true');
|
|
153
198
|
for (const name of ['gt', 'gteq', 'lt', 'lteq']) fact(odrl_order_kind(o(name), 'integer'));
|
|
199
|
+
fact(odrl_order_kind(e('withinCategory'), 'iri'));
|
|
200
|
+
implies([odrl_node(E, C, 'constraint'), odrl_input(C, o('operator'), e('withinCategory')),
|
|
201
|
+
odrl_input(C, o('leftOperand'), P), not(odrl_category_property(P))],
|
|
202
|
+
odrl_problem(E, C, o('leftOperand'), e('UnsupportedCategoryProperty')));
|
|
154
203
|
implies([odrl_node(E, C, 'constraint'), odrl_input(C, o('operator'), Op),
|
|
155
204
|
odrl_input(C, o('rightOperand'), V), odrl_scalar(V, K, N), not(odrl_order_kind(Op, K))],
|
|
156
205
|
odrl_problem(E, C, o('rightOperand'), e('OperatorTypeMismatch')));
|
|
@@ -160,11 +209,16 @@ implied_by(odrl_compare(o('gt'), 'integer', V, W), gt(V, W));
|
|
|
160
209
|
implied_by(odrl_compare(o('gteq'), 'integer', V, W), ge(V, W));
|
|
161
210
|
implied_by(odrl_compare(o('lt'), 'integer', V, W), lt(V, W));
|
|
162
211
|
implied_by(odrl_compare(o('lteq'), 'integer', V, W), le(V, W));
|
|
212
|
+
implied_by(odrl_compare(e('withinCategory'), 'iri', V, W), struct('dpv:within', iri(V), iri(W)));
|
|
163
213
|
implies([odrl_rule(E, P, R, K), odrl_node(E, Q, 'request'), not(odrl_syntax_error(E)),
|
|
164
214
|
odrl_input(R, o('assignee'), Who), odrl_input(Q, o('assignee'), Who),
|
|
165
215
|
odrl_input(R, o('action'), Act), odrl_input(Q, o('action'), Act),
|
|
166
216
|
odrl_input(R, o('target'), Target), odrl_input(Q, o('target'), Target)], odrl_candidate(E, Q, P, R, K));
|
|
167
|
-
implies([odrl_candidate(E, Q, P, R, K), odrl_input(R, o('constraint'), C),
|
|
217
|
+
implies([odrl_candidate(E, Q, P, R, K), odrl_input(R, o('constraint'), C), odrl_node(E, C, 'constraint')],
|
|
218
|
+
odrl_atomic(E, Q, R, C));
|
|
219
|
+
implies([odrl_candidate(E, Q, P, R, K), odrl_input(R, o('constraint'), C), odrl_node(E, C, 'logical'),
|
|
220
|
+
odrl_logical(C, Op, Members), odrl_member(A, Members)], odrl_atomic(E, Q, R, A));
|
|
221
|
+
implies([odrl_atomic(E, Q, R, C),
|
|
168
222
|
odrl_input(C, o('leftOperand'), Left), odrl_input(Q, e('state'), S),
|
|
169
223
|
findall_sorted(V, odrl_input(S, Left, V), Values)], odrl_observation(E, Q, R, C, Values));
|
|
170
224
|
implies(odrl_observation(E, Q, R, C, []), odrl_condition(E, Q, R, C, 'unknown', e('MissingObservation')));
|
|
@@ -180,8 +234,38 @@ implies([odrl_observation(E, Q, R, C, [V]), odrl_scalar(V, K, VN),
|
|
|
180
234
|
implies([odrl_observation(E, Q, R, C, [V]), odrl_scalar(V, K, VN),
|
|
181
235
|
odrl_input(C, o('rightOperand'), W), odrl_scalar(W, K, WN), odrl_input(C, o('operator'), Op),
|
|
182
236
|
not(odrl_compare(Op, K, VN, WN))], odrl_condition(E, Q, R, C, 'unmet', e('Unsatisfied')));
|
|
183
|
-
|
|
184
|
-
|
|
237
|
+
|
|
238
|
+
// The observed number of satisfied members is a lower bound. Unknown
|
|
239
|
+
// members add to the upper bound. Compare that interval with what the
|
|
240
|
+
// operator accepts before deciding whether missing data matters.
|
|
241
|
+
fact(odrl_group_bounds(o('and'), N, N, N), odrl_group_bounds(o('or'), N, 1, N),
|
|
242
|
+
odrl_group_bounds(o('xone'), N, 1, 1));
|
|
243
|
+
implied_by(odrl_group_status(L, H, Min, Max, 'met', e('Satisfied')), [ge(L, Min), le(H, Max)]);
|
|
244
|
+
implied_by(odrl_group_status(L, H, Min, Max, 'unmet', e('UnsatisfiedLogicalConstraint')), or(lt(H, Min), gt(L, Max)));
|
|
245
|
+
implied_by(odrl_group_status(L, H, Min, Max, 'unknown', e('LogicalConstraintUndetermined')),
|
|
246
|
+
[ge(H, Min), le(L, Max), or(lt(L, Min), gt(H, Max))]);
|
|
247
|
+
implies([odrl_candidate(E, Q, P, R, K), odrl_input(R, o('constraint'), C), odrl_node(E, C, 'logical'),
|
|
248
|
+
odrl_logical(C, Op, Members), odrl_count(Members, Total), odrl_group_bounds(Op, Total, Min, Max),
|
|
249
|
+
findall_sorted(A, [odrl_member(A, Members), odrl_condition(E, Q, R, A, 'met', _)], Yes), odrl_count(Yes, L),
|
|
250
|
+
findall_sorted(A, [odrl_member(A, Members), odrl_condition(E, Q, R, A, 'unknown', _)], Maybe), odrl_count(Maybe, U),
|
|
251
|
+
is(H, add(L, U)), odrl_group_status(L, H, Min, Max, Status, Reason)],
|
|
252
|
+
odrl_rule_condition(E, Q, R, C, Status, Reason, Op));
|
|
253
|
+
implies([odrl_input(R, o('constraint'), C), odrl_condition(E, Q, R, C, Status, Reason),
|
|
254
|
+
odrl_input(C, o('leftOperand'), Left)], odrl_rule_condition(E, Q, R, C, Status, Reason, Left));
|
|
255
|
+
|
|
256
|
+
// Fulfillment is evidence scoped to a request and a named duty. A missing
|
|
257
|
+
// or contradictory record leaves that permission uncertain.
|
|
258
|
+
implies([odrl_candidate(E, Q, P, R, 'permission'), odrl_input(R, o('duty'), D)], odrl_required_duty(E, Q, R, D));
|
|
259
|
+
implies([odrl_required_duty(E, Q, R, D), odrl_input(Q, e('unfulfilledDuty'), D),
|
|
260
|
+
not(odrl_input(Q, e('fulfilledDuty'), D))], odrl_unmet_duty(E, Q, R, D));
|
|
261
|
+
implies([odrl_required_duty(E, Q, R, D), not(odrl_input(Q, e('fulfilledDuty'), D)),
|
|
262
|
+
not(odrl_input(Q, e('unfulfilledDuty'), D))], odrl_unknown_duty(E, Q, R, D, e('MissingDutyEvidence')));
|
|
263
|
+
implies([odrl_required_duty(E, Q, R, D), odrl_input(Q, e('fulfilledDuty'), D),
|
|
264
|
+
odrl_input(Q, e('unfulfilledDuty'), D)], odrl_unknown_duty(E, Q, R, D, e('ConflictingDutyEvidence')));
|
|
265
|
+
implied_by(odrl_failed(E, Q, R), odrl_rule_condition(E, Q, R, _, 'unmet', _, _));
|
|
266
|
+
implied_by(odrl_failed(E, Q, R), odrl_unmet_duty(E, Q, R, _));
|
|
267
|
+
implied_by(odrl_unknown(E, Q, R), odrl_rule_condition(E, Q, R, _, 'unknown', _, _));
|
|
268
|
+
implied_by(odrl_unknown(E, Q, R), odrl_unknown_duty(E, Q, R, _, _));
|
|
185
269
|
implies([odrl_candidate(E, Q, P, R, K), not(odrl_failed(E, Q, R)), not(odrl_unknown(E, Q, R))],
|
|
186
270
|
odrl_applies(E, Q, P, R, K));
|
|
187
271
|
implied_by(odrl_uncertain(E, Q), [odrl_candidate(E, Q, P, R, K), not(odrl_failed(E, Q, R)), odrl_unknown(E, Q, R)]);
|
|
@@ -231,12 +315,17 @@ implies(odrl_applies(E, Q, P, R, 'permission'), rdf(Q, e('permission'), R));
|
|
|
231
315
|
implies(odrl_applies(E, Q, P, R, 'prohibition'), rdf(Q, e('prohibition'), R));
|
|
232
316
|
implies(odrl_void_policy(E, P), rdf(E, e('invalidPolicy'), P));
|
|
233
317
|
implies([odrl_input(E, e('conflictStrategy'), o('invalid')), odrl_cross_conflict(E)], rdf(E, e('reason'), e('ConflictingPolicies')));
|
|
234
|
-
implies(
|
|
235
|
-
implies(
|
|
318
|
+
implies(odrl_rule_condition(E, Q, R, C, 'unmet', Why, Left), rdf(Q, e('unmetConstraint'), C));
|
|
319
|
+
implies(odrl_rule_condition(E, Q, R, C, 'unknown', Why, Left), [
|
|
236
320
|
rdf(Q, e('uncertainty'), Issue), rdf(Issue, rdfType, e('Uncertainty')),
|
|
237
321
|
rdf(Issue, e('constraint'), C), rdf(Issue, e('rule'), R),
|
|
238
322
|
rdf(Issue, e('property'), Left), rdf(Issue, e('reason'), Why),
|
|
239
323
|
]);
|
|
324
|
+
implies(odrl_unmet_duty(E, Q, R, D), rdf(Q, e('unmetDuty'), D));
|
|
325
|
+
implies(odrl_unknown_duty(E, Q, R, D, Why), [
|
|
326
|
+
rdf(Q, e('uncertainty'), Issue), rdf(Issue, rdfType, e('Uncertainty')),
|
|
327
|
+
rdf(Issue, e('duty'), D), rdf(Issue, e('rule'), R), rdf(Issue, e('reason'), Why),
|
|
328
|
+
]);
|
|
240
329
|
implies(odrl_problem(E, S, P, Code), [
|
|
241
330
|
rdf(E, e('validationError'), Issue), rdf(Issue, rdfType, e('ValidationError')),
|
|
242
331
|
rdf(Issue, e('focus'), S), rdf(Issue, e('property'), P), rdf(Issue, e('code'), Code),
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.8.
|
|
2
|
+
export const VERSION = '0.8.38';
|