Skip to content

Commit ff1158f

Browse files
committed
feat: add support for all logical constraints
1 parent dc6c4f0 commit ff1158f

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "odrl-evaluator",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "An open implementation of an ODRL Evaluator that evaluates ODRL policies by generating Compliance Reports",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/rules/constraints.n3

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@
152152
report:satisfactionState report:Satisfied .
153153
} .
154154
# Logical operands
155-
155+
# logical operand premisereport generation
156156
{
157157
# match and constraint
158158
?constraint a odrl:LogicalConstraint;
159-
odrl:and ?otherConstraint .
159+
?operandType?otherConstraint .
160+
161+
?operandType list:in ( odrl:and odrl:or odrl:xone odrl:andSequence) .
160162
# create uuid
161163
( ?constraint ) :getUUID ?logicalConstraintReportID .
162164

@@ -167,25 +169,28 @@
167169
?logicalConstraintReportID report:constraint ?constraint .
168170

169171
# Again, I don't think I can do it without explanation
170-
?logicalConstraintReportID report:constraintLogicalOperand odrl:and .
172+
?logicalConstraintReportID report:constraintLogicalOperand ?operandType .
171173
}.
172174

173-
# connect and constraint with other constraints
175+
# connect logical operand constraints with other premise reports
174176
{
175177
?logicalConstraintReportID a report:ConstraintReport .
176178
?logicalConstraintReportID report:constraint ?constraint .
177179

178-
?constraint odrl:and ?otherConstraint.
180+
?constraint ?operandType ?otherConstraint.
181+
?operandType list:in ( odrl:and odrl:or odrl:xone odrl:andSequence) .
179182

180183
?otherConstraintReportID report:constraint ?otherConstraint.
181184
} => {
182185
?logicalConstraintReportID report:premiseReport ?otherConstraintReportID .
183186
} .
184187

185-
# Is and constraint report satisfied?
188+
# Is and constraint report satisfied? (same for andsequence if you ask me)
186189
{
187190
?logicalConstraintReportID a report:ConstraintReport ;
188-
report:constraintLogicalOperand odrl:and .
191+
report:constraintLogicalOperand ?operandType .
192+
?operandType list:in ( odrl:and odrl:andSequence) .
193+
189194

190195
# check for number of constraint reports
191196
(
@@ -215,7 +220,8 @@
215220
}.
216221
{
217222
?logicalConstraintReportID a report:ConstraintReport ;
218-
report:constraintLogicalOperand odrl:and .
223+
report:constraintLogicalOperand ?operandType .
224+
?operandType list:in ( odrl:and odrl:andSequence) .
219225

220226
# check for number of constraint reports
221227
(
@@ -240,4 +246,64 @@
240246
?satisfiedConstraints log:notEqualTo ?numberConstraints .
241247
} => {
242248
?logicalConstraintReportID report:satisfactionState report:Unsatisfied .
249+
}.
250+
251+
# Is or constraint report satisfied?
252+
{
253+
?logicalConstraintReportID a report:ConstraintReport ;
254+
report:constraintLogicalOperand odrl:or .
255+
256+
# check for satisfied constraints: At least on of them MUST be satisfied
257+
(
258+
?template
259+
{
260+
?logicalConstraintReportID report:premiseReport ?premiseReport .
261+
?premiseReport report:satisfactionState report:Satisfied .
262+
}
263+
?list
264+
) log:collectAllIn ?SCOPE .
265+
?list list:length ?satisfiedConstraints .
266+
?satisfiedConstraints math:notLessThan 1 .
267+
} => {
268+
?logicalConstraintReportID report:satisfactionState report:Satisfied .
269+
270+
}.
271+
{
272+
?logicalConstraintReportID a report:ConstraintReport ;
273+
report:constraintLogicalOperand odrl:or .
274+
275+
# check for satisfied constraints: At least on of them MUST be satisfied
276+
(
277+
?template
278+
{
279+
?logicalConstraintReportID report:premiseReport ?premiseReport .
280+
?premiseReport report:satisfactionState report:Satisfied .
281+
}
282+
?list
283+
) log:collectAllIn ?SCOPE .
284+
?list list:length ?satisfiedConstraints .
285+
?satisfiedConstraints log:equalTo 0 .
286+
} => {
287+
?logicalConstraintReportID report:satisfactionState report:Unsatisfied .
288+
289+
}.
290+
# is xone premise report satisfied? only one, and not more, of the Constraints MUST be satisfied
291+
{
292+
?logicalConstraintReportID a report:ConstraintReport ;
293+
report:constraintLogicalOperand odrl:xone .
294+
295+
# check for satisfied constraints: At least on of them MUST be satisfied
296+
(
297+
?template
298+
{
299+
?logicalConstraintReportID report:premiseReport ?premiseReport .
300+
?premiseReport report:satisfactionState report:Satisfied .
301+
}
302+
?list
303+
) log:collectAllIn ?SCOPE .
304+
?list list:length ?satisfiedConstraints .
305+
?satisfiedConstraints log:equalTo 1 .
306+
} => {
307+
?logicalConstraintReportID report:satisfactionState report:Satisfied .
308+
243309
}.

0 commit comments

Comments
 (0)