-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDeliveryBasketExample-shacl.ttl
318 lines (297 loc) · 8.52 KB
/
DeliveryBasketExample-shacl.ttl
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
###
### Sample SHACL, demonstrating the use of various types of shapes, targets, paths, constraints
### Accompanies the model/data in DeliveryBasketExample.owl
###
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dbex: <http://DeliveryBasketExample#> .
### A FruitBasket must include between 1 and 3 fruits
### A FruitBasket pack date must be earlier than its expiration date (if exists)
### A FruitBasket pack date must be earlier than or equal to its expiration date (if exists)
### A FruitBasket pack date and expiration date must both be before Jan 15 2023 (if exists)
### A FruitBasket pack date or expiration date must be before Jan 01 2000 (if exists)
dbex:FruitBasketConforms
a sh:NodeShape;
sh:targetClass dbex:FruitBasket;
sh:property [
sh:path dbex:includes;
sh:minCount 1;
sh:maxCount 3;
];
sh:property [
sh:path dbex:packDate;
sh:lessThan dbex:expirationDate;
];
sh:property [
sh:path dbex:packDate;
sh:lessThanOrEquals dbex:expirationDate;
];
sh:and (
[
sh:path dbex:packDate;
sh:maxExclusive "2023-01-15"^^xsd:date;
]
[
sh:path dbex:expirationDate;
sh:maxExclusive "2023-01-15"^^xsd:date;
]
);
sh:or (
[
sh:path dbex:packDate;
sh:maxExclusive "2000-01-01"^^xsd:date;
]
[
sh:path dbex:expirationDate;
sh:maxExclusive "2000-01-01"^^xsd:date;
]
);
.
### An identifier of anything that FruitBasket includes (e.g. a Fruit) must have min length 5
### Note: demonstrates sequence path
dbex:FruitBasketIdentifierLength
a sh:NodeShape;
sh:targetClass dbex:FruitBasket;
sh:property [
sh:path ( dbex:includes dbex:identifier );
sh:minLength 5;
sh:severity sh:Info;
];
.
### A specific FruitBasket must include at least 2 peaches
### Note: demonstrates targetNode
dbex:FruitBasketIncludesAtLeastTwoPeaches
a sh:NodeShape;
sh:targetNode dbex:basket4;
sh:property [
sh:message "Must include at least 2 peaches";
sh:path dbex:includes;
sh:qualifiedValueShape [
sh:class dbex:Peach;
];
sh:qualifiedMinCount 2;
sh:severity sh:Warning;
];
.
### A specific FruitBasket may include at most 2 peaches
dbex:FruitBasketIncludesAtMostTwoPeaches
a sh:NodeShape;
sh:targetNode dbex:basket100;
sh:property [
sh:message "Must include at most 2 peaches";
sh:path dbex:includes;
sh:qualifiedValueShape [
sh:class dbex:Peach;
];
sh:qualifiedMaxCount 2;
sh:severity sh:Warning;
];
.
### A Fruit must be held in exactly one FruitBasket
### Note: demonstrates inverse path
dbex:FruitIsInABasket
a sh:NodeShape;
sh:targetClass dbex:Fruit;
sh:property [
sh:path [ sh:inversePath dbex:includes];
sh:minCount 1;
sh:maxCount 1;
];
.
### URI must contain "peach"
### Note: demonstrates multiple targets
dbex:URIContainsPeach
a sh:NodeShape;
sh:targetNode dbex:basket100;
sh:targetClass dbex:Peach;
sh:pattern "(.+)peach(.+)";
sh:severity sh:Info;
.
### For anything that "includes" something, capacity (if exists) must be at least 1
### Note: demonstrates targetSubjectsOf
dbex:SomethingThatIncludesHasCapacity
a sh:NodeShape;
sh:targetSubjectsOf dbex:includes;
sh:property [
sh:path dbex:capacity;
sh:minInclusive 1;
sh:severity sh:Warning;
];
.
### Identifier length must be at least 5
### Identifiers must be unique (2 subjects cannot have the same identifier)
### Note: demonstrates targetObjectsOf
dbex:IdentifierIsUniqueAndMinLength5
a sh:NodeShape;
sh:targetObjectsOf dbex:identifier;
sh:minLength 5;
sh:property [
sh:path [ sh:inversePath dbex:identifier];
sh:maxCount 1;
];
.
### A specific FruitBasket cannot include more than 2 objects, and they must be Peaches
### A specific FruitBasket's capacity (if exists) must be an int (for testing purposes only - does not match ontology)
### A specific FruitBasket's capacity (if exists) must be an IRI (for testing purposes only - does not match ontology)
dbex:Basket100HasTwoPeachesAndCapacity
a sh:NodeShape;
sh:targetNode dbex:basket100;
sh:property [
sh:path dbex:includes;
sh:maxCount 2;
sh:class dbex:Peach;
];
sh:property [
sh:path dbex:capacity;
sh:datatype xsd:int;
sh:nodeKind sh:IRI;
];
.
### A specific FruitBasket cannot have any properties besides those in sh:property and sh:ignoredProperties
dbex:Basket100HasNoExtraProperties
a sh:NodeShape;
sh:targetNode dbex:basket100;
sh:closed true;
sh:ignoredProperties (<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>);
sh:property [
sh:path dbex:includes;
];
.
### An Address must have at least 1 recipient
### An Address must have a zipCode or zipCodePlusFour, but not both
### An Address recipient must be the same as the care-of person (both must exist or not)
### An Address recipient must be different from the care-of person (both must exist or not)
dbex:AddressConforms
a sh:NodeShape;
sh:targetClass dbex:Address;
sh:node dbex:HasAtLeastOneRecipient;
sh:xone (
[
sh:property [
sh:path dbex:zipCode ;
sh:minCount 1 ;
]
]
[
sh:property [
sh:path dbex:zipCodePlusFour ;
sh:minCount 1 ;
]
]
);
sh:property [
sh:path dbex:recipientName;
sh:equals dbex:careOfName;
sh:severity sh:Warning;
];
sh:property [
sh:path dbex:recipientName;
sh:disjoint dbex:careOfName;
sh:severity sh:Warning;
];
.
### An Address zip code cannot be 53217-1234
dbex:AddressIsNot53217-1234
a sh:NodeShape;
sh:targetClass dbex:Address;
sh:message "Zip code cannot be 53217-1234";
sh:not[
sh:path dbex:zipCodePlusFour;
sh:hasValue "53217-1234";
];
.
### An Address recipient and care-of person must be of form "Firstname Lastname" (if exists)
### Note: demonstrates a PropertyShape with a target
### Note: demonstrates alternative path
dbex:AddressPersonsHaveFirstLastNameOnly
a sh:PropertyShape;
sh:targetClass dbex:Address;
sh:property [
sh:path [ sh:alternativePath ( dbex:recipientName dbex:careOfName) ];
sh:pattern "^[A-Z][a-z]* [A-Z][a-z]*$";
sh:severity sh:Warning;
];
.
### Any Delivery address must have at least 1 recipient
### An identifier of anything that is (recursively) included in the delivery must be at least length 10 (if exists)
### Note: demonstrates one-or-more path
dbex:DeliveryHasRecipientAndLongEnoughIdentifiers
a sh:NodeShape ;
sh:targetClass dbex:Delivery;
sh:property [
sh:path dbex:address;
sh:node dbex:HasAtLeastOneRecipient;
];
sh:property [
sh:path ( [ sh:oneOrMorePath dbex:includes ] dbex:identifier );
sh:minLength 10;
sh:severity sh:Info;
]
.
### An instance must have at least 1 recipient
### Note: this shape has no target - it is used in shape-based constraints
dbex:HasAtLeastOneRecipient
a sh:NodeShape;
sh:property [
sh:path dbex:recipientName;
sh:minCount 1;
];
.
### Shape using a SPARQL-based constraint
### An Address recipient name cannot contain 'Unknown'
dbex:AddressRecipientIsNotUnknown1
a sh:NodeShape ;
sh:targetClass dbex:Address;
sh:sparql [
a sh:SPARQLConstraint;
sh:message "Recipient name cannot contain 'unknown', but it does";
sh:prefixes dbex: ;
sh:select """
SELECT $this (dbex:recipientName AS ?path) ?value
WHERE {
$this dbex:recipientName ?value .
FILTER contains(lcase(?value), "unknown")
}
""" ;
] .
### this prefix declaration is needed to recognize "dbex" in the SPARQL
dbex:
a owl:Ontology ;
owl:imports sh: ;
sh:declare [
sh:prefix "dbex" ;
sh:namespace "http://DeliveryBasketExample#"^^xsd:anyURI ;
];
.
### Shape using a SPARQL-based constraint component that implements reusable sh:substringNotPresent
### An Address recipient name cannot contain 'Unknown'
dbex:AddressRecipientIsNotUnknown2
a sh:NodeShape ;
sh:targetNode dbex:addressTwoZips;
sh:property [
sh:path dbex:recipientName;
sh:substringNotPresent "Unknown";
];
.
dbex:SubstringNotPresentConstraintComponent
a sh:ConstraintComponent ;
sh:parameter [
sh:path sh:substringNotPresent;
];
sh:validator [
a sh:SPARQLAskValidator;
sh:message "Value contains substring '{$substringNotPresent}'";
sh:ask """ ASK { FILTER (!isBlank($value) && contains(lcase(?value),$substring)) } """;
]
.
### An Address zip code must be one of 3 in a list
### Omitting from JUnit because value inserted as #int may be queried from Fuseki as #int or #integer
#dbex:AddressZipCodeConforms
# a sh:NodeShape;
# sh:targetClass dbex:Address;
# sh:property [
# sh:path dbex:zipCode;
# sh:in ( "53217"^^xsd:integer "53217"^^xsd:int "53211"^^xsd:integer "53211"^^xsd:int );
# ];
# .