Skip to content

Commit 9b3ce19

Browse files
committed
feat: add eyeling as a reasoner
1 parent 8448da9 commit 9b3ce19

8 files changed

Lines changed: 247 additions & 113 deletions

File tree

demo/test-eyeling.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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()

package-lock.json

Lines changed: 55 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"@rdfjs/types": "^1.1.0",
5252
"@types/n3": "^1.16.3",
5353
"commit-and-tag-version": "^12.6.0",
54-
"eyereasoner": "^16.18.4",
54+
"eyereasoner": "^19.0.1",
55+
"eyeling":"^1.10.6",
5556
"n3": "^1.20.4",
5657
"odrl-atomizer": "^0.1.2",
5758
"rdf-isomorphic": "^1.3.1",

src/index.core.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export * from './evaluator/Engine'
44
export * from './evaluator/Evaluate'
55
export * from './evaluator/Validate'
66

7-
export * from './reasoner/EyeJsReasoner'
7+
export * from './reasoner/EyeJsReasoner'export * from './reasoner/EyelingReasoner'
88
export * from './reasoner/Reasoner'
99

1010
export * from './rules/Rules'
@@ -18,5 +18,4 @@ export * from './util/Prefixes'
1818
export * from './util/report/ComplianceReportTypes'
1919
export * from './util/report/ComplianceReportUtil'
2020
export * from './util/policy/PolicyUtil'
21-
export * from './util/request/RequestUtil'
22-
export * from './util/report/ComplianceReportUtil'
21+
export * from './util/request/RequestUtil'

src/reasoner/EyelingReasoner.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Reasoner } from "./Reasoner";
2+
import { reason } from "eyeling"
3+
4+
export class EyelingReasoner extends Reasoner {
5+
constructor() {
6+
super();
7+
}
8+
9+
public async run(abox: string[], tbox: string[]): Promise<string> {
10+
const data = abox.join("\n");
11+
const query = tbox.join("\n");
12+
13+
return reason({ output: "derivations", proofComments: false }, data + query)
14+
}
15+
}

0 commit comments

Comments
 (0)