]> Lady’s Gitweb - Vocab/blob - transforms/site/infer.xslt
Initial commit; initial set of vocabs
[Vocab] / transforms / site / infer.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 © 2024 Lady [@ Ladys Computer].
8
9 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
10 If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
11 -->
12
13 <transform
14 xmlns="http://www.w3.org/1999/XSL/Transform"
15 xmlns:Vocab="urn:fdc:vocab.ladys.computer:20240731:ns"
16 xmlns:Vocabvocab="urn:fdc:vocab.ladys.computer:20240731:vocab:"
17 xmlns:exsl="http://exslt.org/common"
18 xmlns:exslfunc="http://exslt.org/functions"
19 xmlns:owl="http://www.w3.org/2002/07/owl#"
20 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
21 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 exclude-result-prefixes="Vocab Vocabvocab"
24 extension-element-prefixes="exsl exslfunc"
25 version="1.0"
26 >
27 <书社:id>urn:fdc:vocab.ladys.computer:20240731:transforms:site:infer.xslt</书社:id>
28 <key name="Vocab:equivalent-class" match="owl:Class|owl:Restriction|rdfs:Datatype" use="owl:equivalentClass/@rdf:resource"/>
29 <key name="Vocab:equivalent-property" match="owl:AnnotationProperty|owl:DatatypeProperty|owl:ObjectProperty" use="owl:equivalentProperty/@rdf:resource"/>
30 <key name="Vocab:equivalent-individual" match="owl:NamedIndividual" use="owl:sameAs/@rdf:resource"/>
31 <key name="Vocab:inverse-class" match="owl:Class|rdfs:Datatype" use="owl:complementOf/@rdf:resource"/>
32 <key name="Vocab:inverse-property" match="owl:DatatypeProperty|owl:ObjectProperty" use="owl:inverseOf/@rdf:resource"/>
33 <key name="Vocab:disjoint-class" match="owl:Class|rdfs:Datatype" use="owl:disjointWith/@rdf:resource"/>
34 <key name="Vocab:disjoint-property" match="owl:DatatypeProperty|owl:ObjectProperty" use="owl:propertyDisjointWith/@rdf:resource"/>
35 <exslfunc:function name="Vocab:get-equivalents">
36 <param name="resource-nodes"/>
37 <param name="kind" select="'individual'"/>
38 <param name="include-self" select="false()"/>
39 <param name="exclude" select="/.."/>
40 <variable name="result-fragment">
41 <call-template name="Vocab:get-fragment-of-equivalents">
42 <with-param name="kind" select="$kind"/>
43 <with-param name="resource-nodes" select="$resource-nodes"/>
44 <with-param name="include-self" select="$include-self"/>
45 <with-param name="exclude" select="$exclude"/>
46 </call-template>
47 </variable>
48 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
49 </exslfunc:function>
50 <exslfunc:function name="Vocab:get-transitives">
51 <param name="resource-nodes"/>
52 <param name="kind" select="'individual'"/>
53 <param name="relationship"/>
54 <param name="include-self" select="false()"/>
55 <param name="exclude" select="/.."/>
56 <variable name="result-fragment">
57 <call-template name="Vocab:get-fragment-of-transitives">
58 <with-param name="kind" select="$kind"/>
59 <with-param name="relationship" select="$relationship"/>
60 <with-param name="resource-nodes" select="$resource-nodes"/>
61 <with-param name="include-self" select="$include-self"/>
62 <with-param name="exclude" select="$exclude"/>
63 </call-template>
64 </variable>
65 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
66 </exslfunc:function>
67 <exslfunc:function name="Vocab:get-symmetrics">
68 <param name="resource-nodes"/>
69 <param name="kind"/>
70 <param name="relationship"/>
71 <param name="include-self" select="false()"/>
72 <param name="exclude" select="/.."/>
73 <variable name="root" select="/"/>
74 <variable name="relationship-names" select="Vocab:relationship-names($kind, $relationship)"/>
75 <variable name="result-fragment">
76 <if test="string($relationship-names/Vocab:local-name)!=''">
77 <variable name="relationship-key">
78 <text>Vocab:</text>
79 <value-of select="$relationship"/>
80 <text>-</text>
81 <value-of select="$kind"/>
82 </variable>
83 <variable name="equivalents" select="Vocab:get-equivalents($resource-nodes, $kind, true(), $exclude)"/>
84 <variable name="unfiltered-result-fragment">
85 <if test="$include-self">
86 <copy-of select="$equivalents"/>
87 </if>
88 <for-each select="$equivalents/@rdf:about">
89 <variable name="source" select="string()"/>
90 <for-each select="$root">
91 <for-each select="key(concat('Vocab:named-', $kind), $source)">
92 <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
93 <with-param name="source" select="$source"/>
94 </apply-templates>
95 </for-each>
96 <for-each select="key($relationship-key, $source)">
97 <apply-templates select="." mode="Vocab:format-get">
98 <with-param name="source" select="string(@rdf:about)"/>
99 </apply-templates>
100 </for-each>
101 </for-each>
102 </for-each>
103 </variable>
104 <for-each select="exsl:node-set($unfiltered-result-fragment)/*">
105 <copy-of select="self::*[not(@rdf:about and ($exclude|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])]"/>
106 </for-each>
107 </if>
108 </variable>
109 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
110 </exslfunc:function>
111 <exslfunc:function name="Vocab:relationship-names">
112 <param name="kind"/>
113 <param name="relationship"/>
114 <variable name="result-fragment">
115 <element name="Vocab:local-name">
116 <choose>
117 <when test="$relationship='equivalent' and $kind='class'">
118 <text>equivalentClass</text>
119 </when>
120 <when test="$relationship='equivalent' and $kind='property'">
121 <text>equivalentProperty</text>
122 </when>
123 <when test="$relationship='equivalent' and $kind='individual'">
124 <text>sameAs</text>
125 </when>
126 <when test="$relationship='super' and $kind='class'">
127 <text>subClassOf</text>
128 </when>
129 <when test="$relationship='super' and $kind='property'">
130 <text>subPropertyOf</text>
131 </when>
132 <when test="$relationship='inverse' and $kind='class'">
133 <text>complementOf</text>
134 </when>
135 <when test="$relationship='inverse' and $kind='property'">
136 <text>inverseOf</text>
137 </when>
138 <when test="$relationship='disjoint' and $kind='class'">
139 <text>disjointWith</text>
140 </when>
141 <when test="$relationship='disjoint' and $kind='property'">
142 <text>propertyDisjointWith</text>
143 </when>
144 </choose>
145 </element>
146 <element name="Vocab:namespace">
147 <choose>
148 <when test="$relationship='super'">
149 <text>http://www.w3.org/2000/01/rdf-schema#</text>
150 </when>
151 <otherwise>
152 <text>http://www.w3.org/2002/07/owl#</text>
153 </otherwise>
154 </choose>
155 </element>
156 </variable>
157 <exslfunc:result select="exsl:node-set($result-fragment)"/>
158 </exslfunc:function>
159 <template name="Vocab:get-fragment-of-equivalents">
160 <param name="kind" select="'individual'"/>
161 <param name="resource-nodes" select="/.."/> <!-- not yet processed, but selected -->
162 <param name="include-self" select="true()"/> <!-- make false on first run to not include provided nodes -->
163 <param name="exclude" select="/.."/> <!-- leave named nodes out of result -->
164 <param name="gotten" select="/.."/> <!-- already processed -->
165 <variable name="root" select="/"/>
166 <variable name="relationship-names" select="Vocab:relationship-names($kind, 'equivalent')"/>
167 <variable name="gotten-nodes" select="exsl:node-set($gotten)/*"/>
168 <variable name="next"> <!-- new selection -->
169 <for-each select="$resource-nodes/@rdf:about">
170 <!-- Iterate over each named resource to get, find it, and get the equivalent resources. -->
171 <if test="not(($gotten-nodes|../preceding-sibling::*)/@rdf:about[string()=string(current())])">
172 <variable name="source" select="string()"/>
173 <for-each select="$root">
174 <for-each select="key(concat('Vocab:named-', $kind), $source)">
175 <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
176 <with-param name="source" select="$source"/>
177 </apply-templates>
178 </for-each>
179 <for-each select="key(concat('Vocab:equivalent-', $kind), $source)">
180 <apply-templates select="." mode="Vocab:format-get">
181 <with-param name="source" select="string(@rdf:about)"/>
182 </apply-templates>
183 </for-each>
184 </for-each>
185 </if>
186 </for-each>
187 </variable>
188 <variable name="next-nodes" select="exsl:node-set($next)/*"/>
189 <if test="$include-self">
190 <for-each select="$resource-nodes">
191 <if test="not(@rdf:about and ($exclude|$gotten-nodes|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])">
192 <apply-templates select="." mode="Vocab:format-get"/>
193 </if>
194 </for-each>
195 </if>
196 <if test="$next-nodes">
197 <call-template name="Vocab:get-fragment-of-equivalents">
198 <with-param name="kind" select="$kind"/>
199 <with-param name="resource-nodes" select="$next-nodes"/>
200 <with-param name="exclude" select="$exclude"/>
201 <with-param name="gotten">
202 <copy-of select="$gotten-nodes"/>
203 <for-each select="$resource-nodes">
204 <if test="not(@rdf:about and ($gotten-nodes|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])">
205 <copy-of select="."/>
206 </if>
207 </for-each>
208 </with-param>
209 </call-template>
210 </if>
211 </template>
212 <template name="Vocab:get-fragment-of-transitives">
213 <param name="kind" select="'individual'"/>
214 <param name="relationship"/>
215 <param name="resource-nodes" select="/.."/> <!-- not yet processed, but selected -->
216 <param name="include-self" select="true()"/> <!-- make false on first run to not include provided nodes -->
217 <param name="exclude" select="/.."/> <!-- leave named nodes out of result -->
218 <param name="gotten" select="/.."/> <!-- already processed -->
219 <variable name="root" select="/"/>
220 <variable name="relationship-names" select="Vocab:relationship-names($kind, $relationship)"/>
221 <if test="string($relationship-names/Vocab:local-name)!=''">
222 <variable name="gotten-nodes" select="exsl:node-set($gotten)/*"/>
223 <variable name="equivalent-nodes" select="Vocab:get-equivalents($resource-nodes, $kind, true(), $gotten-nodes)"/> <!-- already deduped -->
224 <variable name="next"> <!-- new selection -->
225 <for-each select="$equivalent-nodes/@rdf:about">
226 <!-- Iterate over each named resource to get, find it, and get the related resources. -->
227 <variable name="source" select="string()"/>
228 <for-each select="$root">
229 <for-each select="key(concat('Vocab:named-', $kind), $source)">
230 <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
231 <with-param name="source" select="$source"/>
232 </apply-templates>
233 </for-each>
234 </for-each>
235 </for-each>
236 </variable>
237 <variable name="next-nodes" select="exsl:node-set($next)/*"/>
238 <if test="$include-self">
239 <for-each select="$equivalent-nodes">
240 <if test="not(@rdf:about and $exclude/@rdf:about[string()=string(current()/@rdf:about)])">
241 <copy-of select="."/>
242 </if>
243 </for-each>
244 </if>
245 <if test="$next-nodes">
246 <call-template name="Vocab:get-fragment-of-transitives">
247 <with-param name="kind" select="$kind"/>
248 <with-param name="relationship" select="$relationship"/>
249 <with-param name="resource-nodes" select="$next-nodes"/>
250 <with-param name="exclude" select="$exclude"/>
251 <with-param name="gotten">
252 <copy-of select="$gotten-nodes"/>
253 <copy-of select="$equivalent-nodes"/>
254 </with-param>
255 </call-template>
256 </if>
257 </if>
258 </template>
259 <template match="*" mode="Vocab:format-get">
260 <param name="source"/>
261 <choose>
262 <when test="Vocabvocab:inferred-from">
263 <copy-of select="."/>
264 </when>
265 <when test="@rdf:about|@rdf:resource">
266 <element name="rdf:Description">
267 <attribute name="rdf:about">
268 <value-of select="@rdf:about|@rdf:resource"/>
269 </attribute>
270 <if test="string($source)!=''">
271 <element name="Vocabvocab:inferred-from">
272 <attribute name="rdf:resource">
273 <value-of select="$source"/>
274 </attribute>
275 </element>
276 </if>
277 </element>
278 </when>
279 <otherwise>
280 <for-each select="*">
281 <copy>
282 <copy-of select="@*|node()"/>
283 <if test="string($source)!=''">
284 <element name="Vocabvocab:inferred-from">
285 <attribute name="rdf:resource">
286 <value-of select="$source"/>
287 </attribute>
288 </element>
289 </if>
290 </copy>
291 </for-each>
292 </otherwise>
293 </choose>
294 </template>
295 </transform>
This page took 0.136248 seconds and 5 git commands to generate.