forked from spinrdf/spinrdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspl.spin.ttl
247 lines (243 loc) · 8.74 KB
/
spl.spin.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
# baseURI: http://spinrdf.org/spl
# imports: http://spinrdf.org/spin
# prefix: spl
@prefix afn: <http://jena.hpl.hp.com/ARQ/function#> .
@prefix arg: <http://spinrdf.org/arg#> .
@prefix fn: <http://www.w3.org/2005/xpath-functions#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spif: <http://spinrdf.org/spif#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://spinrdf.org/spl>
a owl:Ontology ;
rdfs:comment "A collection of generally useful SPARQL functions (expressed as SPIN functions), and SPIN templates. Also provides a top-level classification of functions, and definitions of the standard SPARQL functions." ;
rdfs:label "SPIN Standard Library" ;
owl:imports <http://spinrdf.org/spin> ;
owl:versionInfo "1.4.2" ;
.
spl:Argument
a spin:ConstructTemplate ;
spin:body [ a sp:Construct ;
sp:text """PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX afn: <http://jena.apache.org/ARQ/function#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX spin: <http://spinrdf.org/spin#>
CONSTRUCT
{
_:c0 a spin:ConstraintViolation .
_:c0 spin:violationRoot ?this .
_:c0 spin:violationPath ?predicate .
_:c0 spin:violationValue ?value .
_:c0 rdfs:label ?label .
}
WHERE
{ { FILTER ( ( ! bound(?optional) ) || ( ?optional = false ) )
FILTER NOT EXISTS { ?this ?predicate ?value }
# FILTER isIRI(?this)
BIND(concat("Missing value for argument ", afn:localname(?predicate)) AS ?label)
}
UNION
{ FILTER bound(?valueType)
{ ?this ?predicate ?value
# FILTER isIRI(?this)
FILTER ( isURI(?value) || isBlank(?value) )
FILTER bound(?valueType)
FILTER ( ( ?valueType != rdfs:Resource ) || isLiteral(?value) )
FILTER NOT EXISTS { ?value a ?class .
?class (rdfs:subClassOf)* ?valueType
}
}
UNION
{ ?this ?predicate ?value
# FILTER isIRI(?this)
FILTER isLiteral(?value)
FILTER bound(?valueType)
FILTER ( ( ?valueType != rdfs:Resource ) || isLiteral(?value) )
BIND(datatype(?value) AS ?datatype)
FILTER ( ! ( ( ?datatype IN (?valueType, rdfs:Literal) ) || ( ( ( ! bound(?datatype) ) || ( ?datatype = rdf:langString ) ) && ( ?valueType = xsd:string ) ) ) )
}
BIND(concat("Incorrect type of argument ", afn:localname(?predicate), " (expected: ", afn:localname(?valueType), ")") AS ?label)
}
}"""
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:defaultValue ;
rdfs:comment "the default value for the argument" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:optional ;
spl:valueType xsd:boolean ;
rdfs:comment "indicates whether the argument is optional" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:valueType ;
spl:valueType rdfs:Class ;
rdfs:comment "the value type of the argument" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate rdfs:comment ;
spl:valueType xsd:string ;
rdfs:comment "a comment describing the argument" ;
] ;
spin:constraint [
a spl:Argument ;
spl:predicate spl:predicate ;
spl:valueType rdf:Property ;
rdfs:comment "the property holding the values of each function call" ;
] ;
spin:labelTemplate "Argument {?predicate} : {?valueType}" ;
rdfs:comment "Provides metadata about an argument of a SPIN Function or Template. Arguments wrap a given rdf:Property (predicate) and specify its value type and whether the argument is optional. When used as spin:constraint, the body of this template will verify that a non-optional value exists and that it has the specified value type. Arguments that have been declared spl:optional true become optional if the type of ?this is spl:UnionTemplate. " ;
rdfs:label "Argument" ;
rdfs:subClassOf spin:ConstructTemplates ;
.
spl:Attribute
a spin:ConstructTemplate ;
spin:body [
a sp:Construct ;
sp:text """PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX spin: <http://spinrdf.org/spin#>
CONSTRUCT {
_:b0 a spin:ConstraintViolation .
_:b0 spin:violationRoot ?this .
_:b0 spin:violationPath ?predicate .
_:b0 spin:violationValue ?value .
}
WHERE
{ { SELECT (count(*) AS ?cardinality)
WHERE
{ ?this ?predicate ?value
FILTER bound(?minCount)
}
HAVING ( ?cardinality < ?minCount )
}
UNION
{ { SELECT (count(*) AS ?cardinality)
WHERE
{ ?this ?predicate ?value
FILTER bound(?maxCount)
}
HAVING ( ?cardinality > ?maxCount )
}
}
UNION
{ ?this ?predicate ?value
FILTER ( isURI(?value) || isBlank(?value) )
FILTER bound(?valueType)
FILTER NOT EXISTS { ?value a ?class .
?class (rdfs:subClassOf)* ?valueType
}
}
UNION
{ ?this ?predicate ?value
FILTER isLiteral(?value)
FILTER bound(?valueType)
BIND(datatype(?value) AS ?datatype)
FILTER ( ! ( ( ?datatype IN (?valueType, rdfs:Literal) ) || ( ( ( ! bound(?datatype) ) || ( ?datatype = rdf:langString ) ) && ( ?valueType = xsd:string ) ) ) )
}
}"""
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:defaultValue ;
rdfs:comment "the default value of the attribute" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:maxCount ;
spl:valueType xsd:integer ;
rdfs:comment "the maximum number of values permitted for the property" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:minCount ;
spl:valueType xsd:integer ;
rdfs:comment "the minimum number of values permitted for the property" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate spl:valueType ;
spl:valueType rdfs:Class ;
rdfs:comment "the type that all values of the property must have" ;
] ;
spin:constraint [
a spl:Argument ;
spl:optional true ;
spl:predicate rdfs:comment ;
spl:valueType xsd:string ;
rdfs:comment "a comment describing the meaning of this attribute" ;
] ;
spin:constraint [
a spl:Argument ;
spl:predicate spl:predicate ;
spl:valueType rdf:Property ;
rdfs:comment "the RDF property holding the attribute value" ;
] ;
spin:labelTemplate "Attribute {?predicate} : {?valueType} [{?minCount},{?maxCount}]" ;
rdfs:comment """Defines an \"attribute\" of a class. Attribute definitions bundle common modeling patterns known from object-oriented languages like UML. Each attribute can have min and max cardinality, a value type and a default value. The attribute links a class with one RDF property. This template should be used as spin:constraints on a class to make sure that classes meet the expected cardinalities and valueType constraints.
If a model wants to use spl:defaultValue, then it should instantiate the spl:ConstructDefaultValues as a spin:constructor at some root class, such as rdfs:Resource.""" ;
rdfs:label "Attribute" ;
rdfs:subClassOf spin:ConstructTemplates ;
.
spl:optional
a rdf:Property ;
rdfs:label "optional"^^xsd:string ;
rdfs:range xsd:boolean ;
rdfs:subPropertyOf sp:arg ;
.
spl:predicate
a rdf:Property ;
rdfs:label "predicate"^^xsd:string ;
rdfs:subPropertyOf sp:arg ;
.
spl:valueType
a rdf:Property ;
rdfs:label "value type" ;
rdfs:subPropertyOf sp:arg ;
.
spl:minCount
a rdf:Property ;
rdfs:subPropertyOf spl:count ;
.
spl:maxCount
a rdf:Property ;
rdfs:subPropertyOf spl:count ;
.
spl:defaultValue
a rdf:Property ;
rdfs:label "default value" ;
rdfs:subPropertyOf sp:arg ;
.
# adding additional definitions so that SPL constraints successfully validate themselves
rdf:Property
a rdfs:Class .
rdfs:Resource
a rdfs:Class .
rdfs:Class
a rdfs:Class .
rdfs:comment
a rdf:Property, rdfs:Class .
xsd:boolean
a rdfs:Class .
xsd:string
a rdfs:Class .
xsd:integer
a rdfs:Class .