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