forked from w3c/wot-thing-description
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.txt
382 lines (349 loc) · 14.4 KB
/
templates.txt
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
371
372
373
374
375
376
377
378
379
380
381
382
prefix st: <http://ns.inria.fr/sparql-template/>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :classes(?ns) {
"<section>"
format { "<h3><code>%s</code></h3>" st:call-template(:label, ?class) }
if(?class = <https://www.w3.org/2019/wot-security#APIKeySecurityScheme> ||
?class = <https://www.w3.org/2019/wot-security#CertSecurityScheme> ||
?class = <https://www.w3.org/2019/wot-security#OAuth2SecurityScheme> ||
?class = <https://www.w3.org/2019/wot-security#PoPSecurityScheme> ||
?class = <https://www.w3.org/2019/wot-security#PSKSecurityScheme> ||
?class = <https://www.w3.org/2019/wot-security#PublicSecurityScheme>,
"<p><span class=\"at-risk\">This section is at risk.</span></p>",
""
)
format { "<p>%s</p>" st:call-template(:desc, ?class) }
format { "%s" st:call-template(:fields, ?class) }
format { "%s" st:call-template(:subclasses, ?class) }
format { "%s" st:call-template(:notes, ?class) }
"</section>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class .
filter(strstarts(str(?class), str(?ns)))
optional { ?shape sh:order ?predefined }
bind (if(bound(?predefined), ?predefined, "1000"^^xsd:integer) as ?rank)
} order by ?rank
---
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 xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :fields(?class) {
"<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/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>string or array</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 array 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>unique identifier of the Thing (URI, e.g. custom URN).</td>",
"<td>mandatory</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/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 array 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/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 array 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 array 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)
}
"</table>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class .
filter exists {
?shape sh:property ?propShape .
?propShape sh:path ?prop .
}
}
---
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 xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :field(?class) {
format { "<tr class=\"rfc2119-table-assertion\" id=\"td-vocab-%s" st:call-template(:label, ?prop) }
format { "--%s\">" st:call-template(:label, ?class) }
"<td>"
format { "<code>%s</code>" st:call-template(:label, ?prop) }
"</td>"
"<td>"
format { "%s" st:call-template(:desc, ?prop) }
if (?prop = <https://www.w3.org/2019/td#forms>,
if(?class = <https://www.w3.org/2019/td#Thing>,
" In this version of TD, all operations that can be described at the Thing level are concerning how to interact with the Thing's <a href=\"#propertyaffordance\">property affordances</a> collectively at once.", ""
) , ""
)
if (?prop = <https://www.w3.org/2019/td#base>,
"<br/><br/><code>base</code> does not affect the URIs used in <code>@context</code> and the IRIs [[?RFC3987]] used within Linked Data [[?LINKED-DATA]] graphs that are relevant when semantic processing is applied to TD instances.", ""
)
"</td>"
"<td>"
format {
"%s"
if(?hasDef || ?prop = <https://www.w3.org/2019/td#op>,
"<a href=\"#sec-default-values\">with default</a>",
if(?mandatory, "mandatory", "optional"))
}
"</td>"
"<td>"
format {
# TODO use path expressions like sh:oneOrMorePath instead?
"%s%s"
if(?prop = <https://www.w3.org/2019/td#op> ||
?prop = <https://www.w3.org/2019/json-schema#items> ||
?prop = <https://www.w3.org/2019/td#security> ||
?prop = <https://www.w3.org/2019/wot-security#scopes>,
concat(st:call-template(:type, ?class, ?prop),
" or array of ",
st:call-template(:type, ?class, ?prop)),
if(?array,
"array of ",
if(?map, "map of ", "")))
if(?prop = <https://www.w3.org/2019/td#op> ||
?prop = <https://www.w3.org/2019/json-schema#items> ||
?prop = <https://www.w3.org/2019/td#security> ||
?prop = <https://www.w3.org/2019/wot-security#scopes>,
"",
if(?hasType, st:call-template(:type, ?class, ?prop), "any type"))
}
format {
"%s%s%s"
if(?hasEnum, " (", "")
st:call-template(:enum, ?class, ?prop)
if(?hasEnum, ")", "")
}
"</td>"
"</tr>"
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop .
optional { ?propShape sh:datatype|sh:class ?type }
optional { ?propShape sh:minCount ?count }
optional {
?mSet a jsonld:Mapping ;
jsonld:iri ?prop ;
jsonld:container jsonld:set
}
optional {
?mIndex a jsonld:Mapping ;
jsonld:iri ?prop ;
jsonld:container jsonld:index
}
optional {
?propShape sh:in ?list
}
optional { ?propShape sh:defaultValue ?def }
bind (bound(?count) as ?mandatory)
bind (bound(?def) as ?hasDef)
bind (bound(?mSet) as ?array)
bind (bound(?mIndex) as ?map)
bind (bound(?type) as ?hasType)
bind (bound(?list) as ?hasEnum)
optional { ?propShape sh:order ?predefined }
bind (if(bound(?predefined), ?predefined, "1000"^^xsd:integer) as ?rank)
} order by ?rank
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :type(?class ?prop) {
format {
"<a href=\"%s\"><code>%s</code></a>"
st:call-template(:href, ?type)
st:call-template(:label, ?type)
}
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop .
{ ?propShape sh:datatype ?type }
union
{ ?propShape sh:class ?type }
}
---
prefix sh: <http://www.w3.org/ns/shacl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :enum(?class ?prop) {
format {
"%s<code>%s</code>%s"
if(?first,
if (?prop = <https://www.w3.org/2019/td#subprotocol> ||
?prop = <https://www.w3.org/2019/wot-security#scheme>,
"e.g. ",
"one of "),
if(?last, "or ", ""))
?val
if(?last, "", ", ")
}; separator = ""
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:property ?propShape .
?propShape sh:path ?prop ;
sh:in ?list .
?list rdf:rest* ?r .
?r rdf:first ?val .
?r rdf:rest ?next
bind ((?list = ?r) as ?first)
bind ((?next = rdf:nil) as ?last)
}
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :subclasses(?class) {
"<p>"
"The class "
format { "<code>%s</code>" st:call-template(:label, ?class) }
" has the following subclasses:"
"</p>"
"<ul>"
st:call-template(:subclass, ?class)
"</ul>"
} where {
?subclass rdfs:subClassOf+ ?class .
}
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :subclass(?class) {
"<li>"
format {
"<a href=\"%s\"><code>%s</code></a>"
st:call-template(:href, ?subclass)
st:call-template(:label, ?subclass)
}
"</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), "#"))
}
---
prefix sh: <http://www.w3.org/ns/shacl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :notes(?class) {
format { "%s" ?note } ; separator = ""
} where {
?shape a sh:NodeShape ;
sh:targetClass ?class ;
sh:description ?note .
filter (datatype(?note) = rdf:HTML)
}
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :href(?term) {
if(strstarts(str(?term), "http://www.w3.org/2001/XMLSchema#"),
st:call-template(:href-xsd, ?term),
st:call-template(:href-fragment, ?term))
} where {}
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :href-xsd(?term) {
format {
"http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#%s"
st:call-template(:label, ?term)
}
} where {}
---
prefix st: <http://ns.inria.fr/sparql-template/>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :href-fragment(?term) {
format {
"#%s"
lcase(st:call-template(:label, ?term))
}
} where {}
---
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix jsonld: <http://www.w3.org/ns/json-ld#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :label(?term) {
format { "%s" ?label }
} where {
optional {
?m a jsonld:Mapping ;
jsonld:iri ?term ;
jsonld:term ?name .
filter not exists { ?term a owl:Class }
}
bind (if(bound(?name), ?name, strafter(str(?term), "#")) as ?label)
}
---
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix : <http://w3c.github.io/wot-thing-description/#>
template :desc(?term) {
format {
"%s%s"
if(strends(?desc, "."), ?desc, concat(?desc, "."))
if(?term = <https://www.w3.org/2019/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 .
}