3 SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 © 2024–2025 Lady [@ Ladys Computer].
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/>.
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"
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"/>
47 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
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"/>
64 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
66 <exslfunc:function name="Vocab:get-symmetrics">
67 <param name="resource-nodes"/>
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">
78 <value-of select="$relationship"/>
80 <value-of select="$kind"/>
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"/>
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"/>
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)"/>
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)])]"/>
108 <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
110 <exslfunc:function name="Vocab:relationship-names">
112 <param name="relationship"/>
113 <variable name="result-fragment">
114 <element name="Vocab:local-name">
116 <when test="$relationship='equivalent' and $kind='class'">
117 <text>equivalentClass</text>
119 <when test="$relationship='equivalent' and $kind='property'">
120 <text>equivalentProperty</text>
122 <when test="$relationship='equivalent' and $kind='individual'">
125 <when test="$relationship='super' and $kind='class'">
126 <text>subClassOf</text>
128 <when test="$relationship='super' and $kind='property'">
129 <text>subPropertyOf</text>
131 <when test="$relationship='inverse' and $kind='class'">
132 <text>complementOf</text>
134 <when test="$relationship='inverse' and $kind='property'">
135 <text>inverseOf</text>
137 <when test="$relationship='disjoint' and $kind='class'">
138 <text>disjointWith</text>
140 <when test="$relationship='disjoint' and $kind='property'">
141 <text>propertyDisjointWith</text>
145 <element name="Vocab:namespace">
147 <when test="$relationship='super'">
148 <text>http://www.w3.org/2000/01/rdf-schema#</text>
151 <text>http://www.w3.org/2002/07/owl#</text>
156 <exslfunc:result select="exsl:node-set($result-fragment)"/>
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"/>
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)"/>
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"/>
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="."/>
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"/>
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="."/>
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"/>
258 <template match="*" mode="Vocab:format-get">
259 <param name="source"/>
261 <when test="Vocabvocab:inferred-from">
262 <copy-of select="."/>
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"/>
269 <if test="string($source)!=''">
270 <element name="Vocabvocab:inferred-from">
271 <attribute name="rdf:resource">
272 <value-of select="$source"/>
279 <for-each select="*">
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"/>