-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-n3-evaluator.ts
86 lines (75 loc) · 3.29 KB
/
test-n3-evaluator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { ODRLEngineMultipleSteps, ODRLEvaluator, resourceToOptimisedTurtle, turtleStringToStore } from "../dist/index";
const odrlPolicyText = `
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
@prefix ex: <http://example.org/>.
@prefix temp: <http://example.com/request/>.
@prefix dct: <http://purl.org/dc/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix report: <http://example.com/report/temp/>.
<urn:uuid:95efe0e8-4fb7-496d-8f3c-4d78c97829bc> a odrl:Set;
dct:description "ZENO is data owner of resource X. ALICE may READ resource X.";
dct:source <https://github.com/woutslabbinck/UCR-test-suite/blob/main/ODRL-Example.md>;
odrl:permission <urn:uuid:f5199b0a-d824-45a0-bc08-1caa8d19a001>.
<urn:uuid:f5199b0a-d824-45a0-bc08-1caa8d19a001> a odrl:Permission;
odrl:action odrl:read;
odrl:target ex:x;
odrl:assignee ex:alice;
odrl:assigner ex:zeno.
`;
const odrlRequestText = `
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
@prefix ex: <http://example.org/>.
@prefix temp: <http://example.com/request/>.
@prefix dct: <http://purl.org/dc/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix report: <http://example.com/report/temp/>.
<urn:uuid:1bafee59-006c-46a3-810c-5d176b4be364> a odrl:Request;
dct:description "Requesting Party ALICE requests to READ resource X.";
odrl:permission <urn:uuid:186be541-5857-4ce3-9f03-1a274f16bf59>.
<urn:uuid:186be541-5857-4ce3-9f03-1a274f16bf59> a odrl:Permission;
odrl:assignee ex:alice;
odrl:action odrl:read;
odrl:target ex:x.
`;
const stateOfTheWorldText = `
@prefix odrl: <http://www.w3.org/ns/odrl/2/>.
@prefix ex: <http://example.org/>.
@prefix temp: <http://example.com/request/>.
@prefix dct: <http://purl.org/dc/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix report: <http://example.com/report/temp/>.
<urn:uuid:f580eb45-e8bf-4bf0-b85f-f3d37774e2d4> a ex:Sotw ;
ex:includes temp:currentTime, ex:alice, ex:zeno.
temp:currentTime dct:issued "2024-02-12T11:20:10.999Z"^^xsd:dateTime.
ex:alice a foaf:Person.
ex:zeno a foaf:Person.
`;
async function main() {
// parse input
const odrlPolicyStore = await turtleStringToStore(odrlPolicyText);
const odrlRequestStore = await turtleStringToStore(odrlRequestText);
const stateOfTheWorldStore = await turtleStringToStore(stateOfTheWorldText);
// evaluator (assumes proper policies, requests and sotw)
const evaluator = new ODRLEvaluator(new ODRLEngineMultipleSteps());
const reasoningResult = await evaluator.evaluate(
odrlPolicyStore.getQuads(null, null, null, null),
odrlRequestStore.getQuads(null, null, null, null),
stateOfTheWorldStore.getQuads(null, null, null, null))
// printing report nicely
const prefixes = {
'odrl': 'http://www.w3.org/ns/odrl/2/',
'ex': 'http://example.org/',
'temp': 'http://example.com/request/',
'dct': 'http://purl.org/dc/terms/',
'xsd': 'http://www.w3.org/2001/XMLSchema#',
'foaf': 'http://xmlns.com/foaf/0.1/',
'report': 'http://example.com/report/temp/'
}
// created report with N3
// @ts-ignore
console.log(resourceToOptimisedTurtle(reasoningResult, prefixes));
}
main()