forked from w3c/wot-thing-description
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.sparql
370 lines (343 loc) · 14.6 KB
/
templates.sparql
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
prefix st: <http://ns.inria.fr/sparql-template/>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix jsonld: <http://www.w3.org/ns/json-ld#>
prefix vann: <http://purl.org/vocab/vann/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :main {
format {
<file://./index.template.html>
st:call-template(:classes, <https://www.w3.org/2019/wot/td#>)
st:call-template(:classes, <https://www.w3.org/2019/wot/json-schema#>)
st:call-template(:classes, <https://www.w3.org/2019/wot/security#>)
st:call-template(:classes, <https://www.w3.org/2019/wot/hypermedia#>)
}
} where {}
template :classes(?ns) {
"<section>"
format { "<h3><code>%s</code></h3>" st:call-template(:default-label, ?class) }
if(?atRisk, "<p><span class=\"at-risk\">This section is at risk.</span></p>", "")
format { "<p>%s</p>" ?def }
format { "%s" st:call-template(:fields, ?class, ?ns) }
format { "%s" st:call-template(:subclasses, ?class, ?ns) }
format { "%s" st:call-template(:notes, ?class) }
"</section>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
skos:definition ?def .
filter(strstarts(str(?class), str(?ns)))
optional { ?shape sh:order ?predefined }
bind (if(bound(?predefined), ?predefined, "1000"^^xsd:integer) as ?rank)
optional {
?shape skos:editorialNote ?note .
# FIXME only if note is "at risk"
}
bind (bound(?note) as ?atRisk)
} order by ?rank
template :fields(?class ?ns) {
"<table class=\"def\">"
"<thead>"
"<tr>"
"<th><a>Vocabulary term</a></th>"
"<th>Description</th>"
"<th>Assignment</th>"
"<th>Type</th>"
"</tr>"
"</thead>"
format {
"<tbody>%s%s%s%s%s</tbody>"
# custom property for Thing (id = @id = IRI)
if(?class = <https://www.w3.org/2019/wot/td#Thing>,
concat("<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-at-context--Thing\">",
"<td><code>@context</code></td>",
"<td>JSON-LD keyword to define short-hand names called terms that are used throughout a TD document.</td>",
"<td>mandatory</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#anyURI\"><code>anyURI</code></a> or <a>Array</a></td>",
"</tr>",
"<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-at-type--Thing\">",
"<td><code>@type</code></td>",
"<td>JSON-LD keyword to label the object with semantic tags (or types).</td>",
"<td>optional</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a> or <a>Array</a> of <a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a></td>",
"</tr>",
"<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-id--Thing\">",
"<td><code>id</code></td>",
"<td>Identifier of the Thing in form of a URI [[RFC3986]] (e.g., stable URI, temporary and mutable URI, URI with local IP address, URN, etc.).</td>",
"<td>optional</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#anyURI\"><code>anyURI</code></a></td>",
"</tr>"
), "")
if(?class = <https://www.w3.org/2019/wot/td#InteractionAffordance>,
concat("<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-at-type--InteractionAffordance\">",
"<td><code>@type</code></td>",
"<td>JSON-LD keyword to label the object with semantic tags (or types).</td>",
"<td>optional</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a> or <a>Array</a> of <a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a></td>",
"</tr>"
), "")
if(?class = <https://www.w3.org/2019/wot/json-schema#DataSchema>,
concat("<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-at-type--DataSchema\">",
"<td><code>@type</code></td>",
"<td>JSON-LD keyword to label the object with semantic tags (or types)</td>",
"<td>optional</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a> or <a>Array</a> of <a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a></td>",
"</tr>"
), "")
if(?class = <https://www.w3.org/2019/wot/security#SecurityScheme>,
concat("<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-at-type--SecurityScheme\">",
"<td><code>@type</code></td>",
"<td>JSON-LD keyword to label the object with semantic tags (or types).</td>",
"<td>optional</td>",
"<td><a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a> or <a>Array</a> of <a href=\"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a></td>",
"</tr>"
), "")
st:call-template(:field, ?class, ?ns)
}
"</table>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class .
filter exists {
?shape sh:property ?propShape .
?propShape sh:path ?prop .
}
}
template :field(?class ?ns) {
format { "<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-%s" st:call-template(:numbered-label, ?prop, ?ns, ?singleton) }
format { "--%s\">" st:call-template(:default-label, ?class, ?ns) }
"<td>"
format { "<code>%s</code>" st:call-template(:numbered-label, ?prop, ?ns, ?singleton) }
"</td>"
"<td>"
format { "%s" ?def }
if (?prop = <https://www.w3.org/2019/wot/td#baseUri>,
"<br/><br/><code>base</code> does not affect the URIs used in <code>@context</code> and the IRIs used within Linked Data [[?LINKED-DATA]] graphs that are relevant when semantic processing is applied to TD instances.", ""
)
"</td>"
"<td>"
format {
"%s"
# work around only for forOperationType, in, qop etc.
if(?hasDefault || ?prop = <https://www.w3.org/2019/wot/hypermedia#hasOperationType> || ?prop = <https://www.w3.org/2019/wot/security#in>
|| ?prop = <https://www.w3.org/2019/wot/security#qop> || ?prop = <https://www.w3.org/2019/wot/security#alg> || ?prop = <https://www.w3.org/2019/wot/security#format> ,
"<a href=\"#sec-default-values\">with default</a>",
if(?mandatory, "mandatory", "optional"))
}
"</td>"
"<td>"
# work around only for description(s) and title(s) otherwise it returns 'string MultiLanguage' at the same time
if ((?prop = <http://purl.org/dc/terms/description> || ?prop = <http://purl.org/dc/terms/title>),
if(?map, "<a href=\"#multilanguage\"><code>MultiLanguage</code></a>", "<a href=\"https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#string\"><code>string</code></a>"),
# start the normal processing
concat(
if(?array, "<a>Array</a> of ",
if(?map, "<a>Map</a> of ",
if(!?singleton && ?hasType,
concat(st:call-template(:type, ?class, ?prop, ?ns), " or <a>Array</a> of "),
""))),
if(?hasType, st:call-template(:type, ?class, ?prop, ?ns), "any type"),
if(?hasEnum, " (", ""),
st:call-template(:enum, ?class, ?prop, ?ns, 0),
if(?hasEnum, ")", "")
)
)
"</td>"
"</tr>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop ;
skos:definition ?def .
filter (isIRI(?prop))
optional {
{ ?propShape sh:datatype ?type }
union
{ ?propShape sh:nodeKind sh:IRI . bind (xsd:anyURI as ?type) }
union
{ ?propShape sh:node ?valueShape . ?valueShape sh:targetClass ?type }
}
bind (bound(?type) as ?hasType)
optional { ?propShape sh:minCount ?minCount }
bind (bound(?minCount) as ?mandatory)
optional { ?propShape sh:maxCount ?maxCount }
bind (bound(?maxCount) as ?singleton)
optional {
?mSet a jsonld:Mapping ;
jsonld:iri ?prop ;
jsonld:container jsonld:set
}
bind (bound(?mSet) && !?singleton as ?array)
optional {
?mIndex a jsonld:Mapping ;
jsonld:iri ?prop .
{ ?mIndex jsonld:container jsonld:index }
union
{ ?mIndex jsonld:container jsonld:language }
}
bind (bound(?mIndex) && !?singleton as ?map)
optional {
{ ?propShape sh:in ?list }
union
{ ?propShape skos:example ?list }
}
bind (bound(?list) as ?hasEnum)
optional { ?propShape sh:defaultValue ?default }
bind (bound(?default) as ?hasDefault)
optional { ?propShape sh:order ?predefined }
bind (if(bound(?predefined), ?predefined, "1000"^^xsd:integer) as ?rank)
} order by ?rank
template :type(?class ?prop ?ns) {
format {
"<a href=\"%s\"><code>%s</code></a>"
st:call-template(:href, ?type, ?ns)
st:call-template(:label, ?type, ?ns)
}
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop .
{ ?propShape sh:datatype ?type }
union
{ ?propShape sh:nodeKind sh:IRI . bind (xsd:anyURI as ?type) }
union
{ ?propShape sh:node ?valueShape . ?valueShape sh:targetClass ?type }
}
template :enum(?class ?prop ?ns ?index) {
format {
"%s<code>%s</code>%s"
if(?first, if(?eg, "e.g., ", "one of "),
if(?last, "or ", ""))
if(isIRI(?val), st:call-template(:label, ?val, ?ns), ?val)
if(?last, "", concat(", ", st:call-template(:enum, ?class, ?prop, ?ns, ?index + 1)))
}
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop .
{ ?propShape sh:in ?list bind (false as ?eg) }
union
{ ?propShape skos:example ?list bind (true as ?eg) }
bind (<javascript:urdf.valueAt>(?list, ?index) as ?val)
bind ((?index = 0) as ?first)
bind ((?index + 1 = <javascript:urdf.length>(?list)) as ?last)
}
template :subclasses(?class ?ns) {
"<p>"
"The class "
format { "<code>%s</code>" st:call-template(:default-label, ?class, ?ns) }
" has the following subclasses:"
"</p>"
"<ul>"
st:call-template(:subclass, ?class, ?ns)
"</ul>"
} where {
?subclass rdfs:subClassOf ?class .
}
template :subclass(?class ?ns) {
"<li>"
format {
"<a href=\"%s\"><code>%s</code></a>"
st:call-template(:href, ?subclass, ?ns)
st:call-template(:default-label, ?subclass, ?ns)
}
"</li>"
} where {
?subclass rdfs:subClassOf ?class .
?subclassShape a sh:NodeShape ;
sh:targetClass ?subclass .
?classShape a sh:NodeShape ;
sh:targetClass ?class .
filter (isIRI(?subclass) &&
isIRI(?class) &&
# same namespace restriction
strbefore(str(?class), "#") = strbefore(str(?subclass), "#"))
optional { ?subclassShape sh:order ?predefined }
bind (if(bound(?predefined), ?predefined, "1000"^^xsd:integer) as ?rank)
} order by ?rank
template :notes(?class) {
format { "%s" ?note } ; separator = ""
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
skos:scopeNote ?note .
filter (datatype(?note) = rdf:HTML)
}
template :href(?term ?ns) {
if(strstarts(str(?term), "http://www.w3.org/2001/XMLSchema#"),
st:call-template(:href-xsd, ?term, ?ns),
st:call-template(:href-fragment, ?term, ?ns))
} where {}
template :href-xsd(?term ?ns) {
format {
"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#%s"
st:call-template(:label, ?term, ?ns)
}
} where {}
template :href-fragment(?term ?ns) {
format {
"#%s"
lcase(st:call-template(:default-label, ?term, ?ns))
}
} where {}
template :numbered-label(?term ?ns ?singular) {
format { "%s" ?name }
} where {
optional {
?ctx jsonld:definition ?m1 ;
jsonld:vocab ?ns .
?m1 a jsonld:Mapping ;
jsonld:iri ?term ;
jsonld:term ?singularName .
filter not exists {
?m1 jsonld:container ?container
}
}
optional {
?ctx jsonld:definition ?m2 ;
jsonld:vocab ?ns .
?m2 a jsonld:Mapping ;
jsonld:iri ?term ;
jsonld:term ?pluralName ;
jsonld:container ?container .
}
bind (
if(!bound(?singularName) && !bound(?pluralName), "",
if(!bound(?singularName), ?pluralName,
if(!bound(?pluralName), ?singularName,
if(?singular, ?singularName, ?pluralName))))
as ?name
)
}
template :label(?term ?ns) {
format { "%s" if(?mapping, ?name, st:call-template(:default-label, ?term)) }
} where {
optional {
?m a jsonld:Mapping ;
jsonld:iri ?term ;
jsonld:term ?name .
}
bind (bound(?name) as ?mapping)
}
template :default-label(?term) {
format { "%s" strafter(str(?term), "#") }
} where {}
#template :desc(?term) {
# format {
# "%s%s"
# if(strends(?desc, "."), ?desc, concat(?desc, "."))
# if(?term = <https://www.w3.org/2019/wot/td#MultiLanguage>,
# " See <a href=\"#titles-descriptions-serialization-json\"></a> for example usages of this container in a Thing Description instance.",
# "")
#
# } ; separator = " "
#} where {
# ?term rdfs:comment ?desc .
#}