-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleRules.n3
204 lines (193 loc) · 5.46 KB
/
simpleRules.n3
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@prefix : <http://example.org/> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .
@prefix report: <http://example.com/report/temp/> .
@prefix string: <http://www.w3.org/2000/10/swap/string#> .
@prefix temp: <http://example.com/request/> .
# uuid backward rule (component)
{
?input :getUUID ?urnUuid
}
<=
{
?input log:skolem ?uniqueNode .
?uniqueNode log:uuid ?uuidString .
( "urn:uuid:" ?uuidString ) string:concatenation ?urnUuidString .
?urnUuid log:uri ?urnUuidString .
} .
# Policy report
{
?policy a ?policyType .
?policyType list:in ( odrl:Agreement odrl:Set odrl:Policy odrl:Offer ) .
?policyRequest a odrl:Request .
temp:currentTime dct:issued ?time .
( ?policy ) :getUUID ?urnUuid .
}
=>
{
?urnUuid a report:PolicyReport ;
dct:created ?time ;
report:policy ?policy ;
report:policyRequest ?policyRequest .
} .
# Permission report (expecting explicit permission type)
# create permission report
{
?policyReport a report:PolicyReport ;
report:policy ?policy ;
report:policyRequest ?policyRequest .
?policy odrl:permission ?permission .
?policyRequest odrl:permission ?requestPermission .
( ?permission ) :getUUID ?urnUuid .
}
=>
{
?policyReport report:ruleReport ?urnUuid .
?urnUuid a report:PermissionReport ;
report:attemptState report:Attempted ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
} .
# check whether permission report is active
{
?urnUuid a report:PermissionReport ;
report:attemptState report:Attempted ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
# check for number of constraint reports
(
?template
{
?urnUuid report:premiseReport _:s
}
?L
) log:collectAllIn ?SCOPE .
?L list:length ?numberConstraints .
# check for satisfied constraints
(
?premiseReport
{
?urnUuid report:premiseReport ?premiseReport .
?premiseReport report:satisfactionState report:Satisfied .
}
?list
) log:collectAllIn ?SCOPE .
?list list:length ?satisfiedConstraints .
?satisfiedConstraints log:equalTo ?numberConstraints .
}
=>
{
?urnUuid report:activationState report:Active .
} .
{
?urnUuid a report:PermissionReport ;
report:attemptState report:Attempted ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
# check for number of constraint reports
(
?template
{
?urnUuid report:premiseReport _:s
}
?L
) log:collectAllIn ?SCOPE .
?L list:length ?numberConstraints .
# check for satisfied constraints
(
?premiseReport
{
?urnUuid report:premiseReport ?premiseReport .
?premiseReport report:satisfactionState report:Satisfied .
}
?list
) log:collectAllIn ?SCOPE .
?list list:length ?satisfiedConstraints .
?satisfiedConstraints log:notEqualTo ?numberConstraints .
}
=>
{
?urnUuid report:activationState report:Inactive .
} .
# Constraint report
# Target report
{
?ruleReport a report:PermissionReport ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
?permission odrl:target ?resource .
?requestPermission odrl:target ?requestedResource .
?resource log:equalTo ?requestedResource .
( ?resource ) :getUUID ?urnUuid .
}
=>
{
?ruleReport report:premiseReport ?urnUuid .
?urnUuid a report:TargetReport ;
report:satisfactionState report:Satisfied .
} .
# Party report
{
?ruleReport a report:PermissionReport ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
?permission odrl:assignee ?party .
?requestPermission odrl:assignee ?requestedParty .
?party log:equalTo ?requestedParty .
( ?party ) :getUUID ?urnUuid .
}
=>
{
?ruleReport report:premiseReport ?urnUuid .
?urnUuid a report:PartyReport ;
report:satisfactionState report:Satisfied .
} .
{
?ruleReport a report:PermissionReport ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
?permission odrl:assignee ?party .
?requestPermission odrl:assignee ?requestedParty .
?party log:notEqualTo ?requestedParty .
( ?party ) :getUUID ?urnUuid .
}
=>
{
?ruleReport report:premiseReport ?urnUuid .
?urnUuid a report:PartyReport ;
report:satisfactionState report:Unsatisfied .
} .
# Action report -> simple action
{
?ruleReport a report:PermissionReport ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
?permission odrl:action ?action .
?requestPermission odrl:action ?requestedAction .
?action log:equalTo ?requestedAction .
( ?action ) :getUUID ?urnUuid .
}
=>
{
?ruleReport report:premiseReport ?urnUuid .
?urnUuid a report:ActionReport ;
report:satisfactionState report:Satisfied .
} .
{
?ruleReport a report:PermissionReport ;
report:rule ?permission ;
report:ruleRequest ?requestPermission .
?permission odrl:action ?action .
?requestPermission odrl:action ?requestedAction .
?action log:notEqualTo ?requestedAction .
( ?action ) :getUUID ?urnUuid .
}
=>
{
?ruleReport report:premiseReport ?urnUuid .
?urnUuid a report:ActionReport ;
report:satisfactionState report:Unsatisfied .
} .