Skip to content

Commit 61d1ff7

Browse files
committed
docs: reasoning problem
Signed-off-by: Wouter Termont <wouter.termont@ugent.be>
1 parent 6e9fd94 commit 61d1ff7

7 files changed

Lines changed: 331 additions & 0 deletions

File tree

demo/problem/context.ttl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
<http://example.org/context> <http://example.org/requestingParty> <http://localhost:3000/demo/public/vendor>;
3+
<http://example.org/target> <http://localhost:3000/ruben/private/derived/age>;
4+
<http://example.org/requestPermission> <urn:example:css:modes:read>.

demo/problem/policy1.ttl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
2+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
3+
4+
<urn:ucp:policy:1> a odrl:Agreement;
5+
odrl:permission <urn:ucp:rule:1>.
6+
<urn:ucp:rule:1> a odrl:Permission;
7+
odrl:action odrl:read;
8+
odrl:target <http://localhost:3000/ruben/private/derived/age>;
9+
odrl:assignee <http://localhost:3000/demo/public/vendor>;
10+
odrl:constraint <urn:ucp:constraint:1a>, <urn:ucp:constraint:1b>, <urn:ucp:constraint:1c>.
11+
<urn:ucp:constraint:1a> odrl:leftOperand odrl:dateTime;
12+
odrl:operator odrl:gt;
13+
odrl:rightOperand "2024-03-15T14:52:09.755Z"^^xsd:dateTime.
14+
<urn:ucp:constraint:1b> odrl:leftOperand odrl:dateTime;
15+
odrl:operator odrl:lt;
16+
odrl:rightOperand "2024-03-29T14:52:09.755Z"^^xsd:dateTime.
17+
<urn:ucp:constraint:1c> odrl:leftOperand odrl:purpose;
18+
odrl:operator odrl:eq;
19+
odrl:rightOperand "age-verification".

demo/problem/policy2.ttl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
2+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
3+
4+
<urn:ucp:policy:2> a odrl:Agreement;
5+
odrl:permission <urn:ucp:rule:2>.
6+
<urn:ucp:rule:2> a odrl:Permission;
7+
odrl:action odrl:read;
8+
odrl:target <http://localhost:3000/ruben/private/derived/age>;
9+
odrl:assignee <http://localhost:3000/demo/public/vendor>;
10+
odrl:constraint <urn:ucp:constraint:2a>, <urn:ucp:constraint:2b>, <urn:ucp:constraint:2c>.
11+
<urn:ucp:constraint:2a> odrl:leftOperand odrl:dateTime;
12+
odrl:operator odrl:gt;
13+
odrl:rightOperand "2024-03-15T14:52:09.755Z"^^xsd:dateTime.
14+
<urn:ucp:constraint:2b> odrl:leftOperand odrl:dateTime;
15+
odrl:operator odrl:lt;
16+
odrl:rightOperand "2024-03-29T14:52:09.755Z"^^xsd:dateTime.
17+
<urn:ucp:constraint:2c> odrl:leftOperand odrl:purpose;
18+
odrl:operator odrl:eq;
19+
odrl:rightOperand "age-verification".

demo/problem/policy3.ttl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
2+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
3+
4+
<urn:ucp:policy:3> a odrl:Agreement;
5+
odrl:permission <urn:ucp:rule:3>.
6+
<urn:ucp:rule:3> a odrl:Permission;
7+
odrl:action odrl:read;
8+
odrl:target <http://localhost:3000/ruben/private/derived/age>;
9+
odrl:assignee <http://localhost:3000/demo/public/vendor>;
10+
odrl:constraint <urn:ucp:constraint:3a>, <urn:ucp:constraint:3b>, <urn:ucp:constraint:3c>.
11+
<urn:ucp:constraint:3a> odrl:leftOperand odrl:dateTime;
12+
odrl:operator odrl:gt;
13+
odrl:rightOperand "2024-03-15T14:52:09.755Z"^^xsd:dateTime.
14+
<urn:ucp:constraint:3b> odrl:leftOperand odrl:dateTime;
15+
odrl:operator odrl:lt;
16+
odrl:rightOperand "2024-03-29T14:52:09.755Z"^^xsd:dateTime.
17+
<urn:ucp:constraint:3c> odrl:leftOperand odrl:purpose;
18+
odrl:operator odrl:eq;
19+
odrl:rightOperand "age-verification".

demo/problem/rules_crud.n3

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .
2+
@prefix : <http://example.org/> .
3+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
4+
@prefix fno: <https://w3id.org/function/ontology#> .
5+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
6+
@prefix string: <http://www.w3.org/2000/10/swap/string#> .
7+
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
8+
9+
# Read ODRL rule
10+
{
11+
?permission a odrl:Permission;
12+
odrl:action ?action ;
13+
odrl:target ?targetResource ;
14+
# odrl:assigner ?resourceOwner ;
15+
odrl:assignee ?requestedParty.
16+
17+
?action list:in (odrl:use odrl:read) . # multiple options
18+
19+
20+
# context of a request
21+
?context
22+
# :resourceOwner ?resourceOwner;
23+
:requestingParty ?requestedParty;
24+
:target ?targetResource;
25+
:requestPermission <urn:example:css:modes:read>.
26+
27+
:uuid5 log:uuid ?uuidStringdataUsagePolicyExecution.
28+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
29+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
30+
31+
# Constraint checking
32+
# No odrl:constraints may be present
33+
?SCOPE log:notIncludes { ?permission odrl:constraint ?anything }.
34+
} =>
35+
{
36+
?dataUsagePolicyExecution a fno:Execution;
37+
fno:executes <http://example.org/dataUsage> ;
38+
:accessModesAllowed <urn:example:css:modes:read>.
39+
}.
40+
41+
# Append ODRL Rule
42+
{
43+
?permission a odrl:Permission;
44+
odrl:action ?action ;
45+
odrl:target ?targetResource ;
46+
# odrl:assigner ?resourceOwner ;
47+
odrl:assignee ?requestedParty.
48+
49+
?action list:in (odrl:use odrl:modify). # multiple options
50+
51+
# context of a request
52+
?context
53+
# :resourceOwner ?resourceOwner;
54+
:requestingParty ?requestedParty;
55+
:target ?targetResource;
56+
:requestPermission <urn:example:css:modes:append>.
57+
58+
:uuid6 log:uuid ?uuidStringdataUsagePolicyExecution.
59+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
60+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
61+
62+
# Constraint checking
63+
# No odrl:constraints may be present
64+
?SCOPE log:notIncludes { ?permission odrl:constraint ?anything }.
65+
} =>
66+
{
67+
?dataUsagePolicyExecution a fno:Execution;
68+
fno:executes <http://example.org/dataUsage> ;
69+
:accessModesAllowed <urn:example:css:modes:append>.
70+
}.
71+
72+
# Write ODRL Rule
73+
{
74+
?permission a odrl:Permission;
75+
odrl:action ?action ;
76+
odrl:target ?targetResource ;
77+
# odrl:assigner ?resourceOwner ;
78+
odrl:assignee ?requestedParty.
79+
80+
?action list:in (odrl:use odrl:modify). # multiple options
81+
82+
# context of a request
83+
?context
84+
# :resourceOwner ?resourceOwner;
85+
:requestingParty ?requestedParty;
86+
:target ?targetResource;
87+
:requestPermission <urn:example:css:modes:write>.
88+
89+
:uuid6 log:uuid ?uuidStringdataUsagePolicyExecution.
90+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
91+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
92+
93+
# Constraint checking
94+
# No odrl:constraints may be present
95+
?SCOPE log:notIncludes { ?permission odrl:constraint ?anything }.
96+
} =>
97+
{
98+
?dataUsagePolicyExecution a fno:Execution;
99+
fno:executes <http://example.org/dataUsage> ;
100+
:accessModesAllowed <urn:example:css:modes:write>.
101+
}.
102+
103+
# Create ODRL Rule
104+
{
105+
?permission a odrl:Permission;
106+
odrl:action ?action ;
107+
odrl:target ?targetResource ;
108+
# odrl:assigner ?resourceOwner ;
109+
odrl:assignee ?requestedParty .
110+
111+
?action list:in (odrl:use odrl:modify). # multiple options
112+
113+
# context of a request
114+
?context
115+
# :resourceOwner ?resourceOwner;
116+
:requestingParty ?requestedParty;
117+
:target ?targetResource;
118+
:requestPermission <urn:example:css:modes:create>.
119+
120+
:uuid6 log:uuid ?uuidStringdataUsagePolicyExecution.
121+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
122+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
123+
124+
# Constraint checking
125+
# No odrl:constraints may be present
126+
?SCOPE log:notIncludes { ?permission odrl:constraint ?anything }.
127+
} =>
128+
{
129+
?dataUsagePolicyExecution a fno:Execution;
130+
fno:executes <http://example.org/dataUsage> ;
131+
:accessModesAllowed <urn:example:css:modes:create>.
132+
}.
133+
134+
# Delete ODRL Rule
135+
{
136+
?permission a odrl:Permission;
137+
odrl:action ?action ;
138+
odrl:target ?targetResource ;
139+
# odrl:assigner ?resourceOwner ;
140+
odrl:assignee ?requestedParty.
141+
142+
?action list:in (odrl:use odrl:delete). # multiple options
143+
144+
# context of a request
145+
?context
146+
# :resourceOwner ?resourceOwner;
147+
:requestingParty ?requestedParty;
148+
:target ?targetResource;
149+
:requestPermission <urn:example:css:modes:delete>.
150+
151+
:uuid6 log:uuid ?uuidStringdataUsagePolicyExecution.
152+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
153+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
154+
155+
# Constraint checking
156+
# No odrl:constraints may be present
157+
?SCOPE log:notIncludes { ?permission odrl:constraint ?anything }.
158+
} =>
159+
{
160+
?dataUsagePolicyExecution a fno:Execution;
161+
fno:executes <http://example.org/dataUsage> ;
162+
:accessModesAllowed <urn:example:css:modes:delete>.
163+
}.

demo/problem/rules_purpose.n3

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3+
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .
4+
@prefix : <http://example.org/> .
5+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
6+
@prefix fno: <https://w3id.org/function/ontology#> .
7+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
8+
@prefix string: <http://www.w3.org/2000/10/swap/string#> .
9+
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
10+
@prefix time: <http://www.w3.org/2000/10/swap/time#> .
11+
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
12+
13+
# ...
14+
{ :currentTime :is ?currentTime } <= { "" time:localTime ?currentTime }.
15+
16+
# Read ODRL rule
17+
{
18+
?permission a odrl:Permission;
19+
odrl:action ?action ;
20+
odrl:target ?targetResource ;
21+
# odrl:assigner ?resourceOwner ;
22+
odrl:assignee ?requestedParty.
23+
24+
?action list:in (odrl:use odrl:read) . # multiple options
25+
26+
# context of a request
27+
?context
28+
# :resourceOwner ?resourceOwner;
29+
:requestingParty ?requestedParty;
30+
:target ?targetResource;
31+
:requestPermission <urn:example:css:modes:read>.
32+
33+
:uuid5 log:uuid ?uuidStringdataUsagePolicyExecution.
34+
( "urn:uuid:" ?uuidStringdataUsagePolicyExecution) string:concatenation ?urnUuidStringdataUsagePolicyExecution.
35+
?dataUsagePolicyExecution log:uri ?urnUuidStringdataUsagePolicyExecution .
36+
37+
# Constraint checking
38+
39+
# number of constraints must be two (temporal needs lower and upper bound)
40+
(?template {?permission odrl:constraint _:s} ?L) log:collectAllIn ?SCOPE.
41+
?L list:length 3 .
42+
43+
:currentTime :is ?currentTime .
44+
45+
# lower bound
46+
?permission odrl:constraint ?lowerBoundIRI .
47+
?lowerBoundIRI
48+
odrl:leftOperand odrl:dateTime ;
49+
odrl:operator odrl:gt ;
50+
odrl:rightOperand ?lowerBound .
51+
52+
# greater bound
53+
?permission odrl:constraint ?upperBoundIRI .
54+
?upperBoundIRI
55+
odrl:leftOperand odrl:dateTime ;
56+
odrl:operator odrl:lt ;
57+
odrl:rightOperand ?upperBound .
58+
59+
# ?lowerBound < ?currentTime < ?upperBound
60+
?currentTime math:greaterThan ?lowerBound .
61+
?currentTime math:lessThan ?upperBound .
62+
63+
# purpose constraint
64+
?permission odrl:constraint ?purposeConstraint .
65+
?purposeConstraint
66+
odrl:leftOperand odrl:purpose ;
67+
odrl:operator odrl:eq ;
68+
odrl:rightOperand ?purposeValue .
69+
# Note: nothing is done with the purpose right now TODO: needs checking
70+
} =>
71+
{
72+
?dataUsagePolicyExecution a fno:Execution;
73+
fno:executes <http://example.org/dataUsage> ;
74+
:accessModesAllowed <urn:example:css:modes:read> ;
75+
<http://purl.org/dc/terms/issued> ?currentTime .
76+
77+
}.
78+
79+
# No ODRL rules for other access modes (`odrl:write` and `odrl:append` are deprecated)

demo/problem/test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { readFileSync } from "fs";
2+
import { EyeJsReasoner } from "koreografeye";
3+
import { Store, Parser, Writer } from "n3";
4+
import path from "path";
5+
6+
const parser = new Parser();
7+
const rules = new Array<string>();
8+
const facts = new Store();
9+
10+
facts.addQuads(parser.parse(readFileSync(path.join(__dirname, 'context.ttl')).toString()))
11+
facts.addQuads(parser.parse(readFileSync(path.join(__dirname, 'policy1.ttl')).toString()))
12+
// facts.addQuads(parser.parse(readFileSync(path.join(__dirname, 'policy2.ttl')).toString()))
13+
// facts.addQuads(parser.parse(readFileSync(path.join(__dirname, 'policy3.ttl')).toString()))
14+
15+
rules.push(readFileSync(path.join(__dirname, 'rules_purpose.n3')).toString());
16+
rules.push(readFileSync(path.join(__dirname, 'rules_crud.n3')).toString());
17+
18+
(async () => {
19+
20+
console.log('>>>>> BEFORE');
21+
const reasoner1 = new EyeJsReasoner(["--quiet", "--nope", "--pass"]);
22+
await reasoner1.reason(facts, rules);
23+
console.log('>>>>> BETWEEN');
24+
const reasoner2 = new EyeJsReasoner(["--quiet", "--nope", "--pass"]);
25+
await reasoner2.reason(facts, rules);
26+
console.log('>>>>> AFTER');
27+
28+
})();

0 commit comments

Comments
 (0)