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