+<?xml version="1.0"?>
+<!--
+SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: MPL-2.0
+-->
+<!--
+© 2024–2025 Lady [@ Ladys Computer].
+
+This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
+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/>.
+-->
+<transform
+ xmlns="http://www.w3.org/1999/XSL/Transform"
+ xmlns:Vocab="urn:fdc:vocab.ladys.computer:20240731:ns"
+ xmlns:Vocabvocab="urn:fdc:vocab.ladys.computer:20240731:vocab:"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:exslfunc="http://exslt.org/functions"
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
+ exclude-result-prefixes="Vocab Vocabvocab"
+ extension-element-prefixes="exsl exslfunc"
+ version="1.0"
+>
+ <书社:id>urn:fdc:vocab.ladys.computer:20240731:transforms:infer.xslt</书社:id>
+ <key name="Vocab:equivalent-class" match="owl:Class|owl:Restriction|rdfs:Datatype" use="owl:equivalentClass/@rdf:resource"/>
+ <key name="Vocab:equivalent-property" match="owl:AnnotationProperty|owl:DatatypeProperty|owl:ObjectProperty" use="owl:equivalentProperty/@rdf:resource"/>
+ <key name="Vocab:equivalent-individual" match="owl:NamedIndividual" use="owl:sameAs/@rdf:resource"/>
+ <key name="Vocab:inverse-class" match="owl:Class|rdfs:Datatype" use="owl:complementOf/@rdf:resource"/>
+ <key name="Vocab:inverse-property" match="owl:DatatypeProperty|owl:ObjectProperty" use="owl:inverseOf/@rdf:resource"/>
+ <key name="Vocab:disjoint-class" match="owl:Class|rdfs:Datatype" use="owl:disjointWith/@rdf:resource"/>
+ <key name="Vocab:disjoint-property" match="owl:DatatypeProperty|owl:ObjectProperty" use="owl:propertyDisjointWith/@rdf:resource"/>
+ <exslfunc:function name="Vocab:get-equivalents">
+ <param name="resource-nodes"/>
+ <param name="kind" select="'individual'"/>
+ <param name="include-self" select="false()"/>
+ <param name="exclude" select="/.."/>
+ <variable name="result-fragment">
+ <call-template name="Vocab:get-fragment-of-equivalents">
+ <with-param name="kind" select="$kind"/>
+ <with-param name="resource-nodes" select="$resource-nodes"/>
+ <with-param name="include-self" select="$include-self"/>
+ <with-param name="exclude" select="$exclude"/>
+ </call-template>
+ </variable>
+ <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
+ </exslfunc:function>
+ <exslfunc:function name="Vocab:get-transitives">
+ <param name="resource-nodes"/>
+ <param name="kind" select="'individual'"/>
+ <param name="relationship"/>
+ <param name="include-self" select="false()"/>
+ <param name="exclude" select="/.."/>
+ <variable name="result-fragment">
+ <call-template name="Vocab:get-fragment-of-transitives">
+ <with-param name="kind" select="$kind"/>
+ <with-param name="relationship" select="$relationship"/>
+ <with-param name="resource-nodes" select="$resource-nodes"/>
+ <with-param name="include-self" select="$include-self"/>
+ <with-param name="exclude" select="$exclude"/>
+ </call-template>
+ </variable>
+ <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
+ </exslfunc:function>
+ <exslfunc:function name="Vocab:get-symmetrics">
+ <param name="resource-nodes"/>
+ <param name="kind"/>
+ <param name="relationship"/>
+ <param name="include-self" select="false()"/>
+ <param name="exclude" select="/.."/>
+ <variable name="root" select="/"/>
+ <variable name="relationship-names" select="Vocab:relationship-names($kind, $relationship)"/>
+ <variable name="result-fragment">
+ <if test="string($relationship-names/Vocab:local-name)!=''">
+ <variable name="relationship-key">
+ <text>Vocab:</text>
+ <value-of select="$relationship"/>
+ <text>-</text>
+ <value-of select="$kind"/>
+ </variable>
+ <variable name="equivalents" select="Vocab:get-equivalents($resource-nodes, $kind, true(), $exclude)"/>
+ <variable name="unfiltered-result-fragment">
+ <if test="$include-self">
+ <copy-of select="$equivalents"/>
+ </if>
+ <for-each select="$equivalents/@rdf:about">
+ <variable name="source" select="string()"/>
+ <for-each select="$root">
+ <for-each select="key(concat('Vocab:named-', $kind), $source)">
+ <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
+ <with-param name="source" select="$source"/>
+ </apply-templates>
+ </for-each>
+ <for-each select="key($relationship-key, $source)">
+ <apply-templates select="." mode="Vocab:format-get">
+ <with-param name="source" select="string(@rdf:about)"/>
+ </apply-templates>
+ </for-each>
+ </for-each>
+ </for-each>
+ </variable>
+ <for-each select="exsl:node-set($unfiltered-result-fragment)/*">
+ <copy-of select="self::*[not(@rdf:about and ($exclude|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])]"/>
+ </for-each>
+ </if>
+ </variable>
+ <exslfunc:result select="exsl:node-set($result-fragment)/*"/>
+ </exslfunc:function>
+ <exslfunc:function name="Vocab:relationship-names">
+ <param name="kind"/>
+ <param name="relationship"/>
+ <variable name="result-fragment">
+ <element name="Vocab:local-name">
+ <choose>
+ <when test="$relationship='equivalent' and $kind='class'">
+ <text>equivalentClass</text>
+ </when>
+ <when test="$relationship='equivalent' and $kind='property'">
+ <text>equivalentProperty</text>
+ </when>
+ <when test="$relationship='equivalent' and $kind='individual'">
+ <text>sameAs</text>
+ </when>
+ <when test="$relationship='super' and $kind='class'">
+ <text>subClassOf</text>
+ </when>
+ <when test="$relationship='super' and $kind='property'">
+ <text>subPropertyOf</text>
+ </when>
+ <when test="$relationship='inverse' and $kind='class'">
+ <text>complementOf</text>
+ </when>
+ <when test="$relationship='inverse' and $kind='property'">
+ <text>inverseOf</text>
+ </when>
+ <when test="$relationship='disjoint' and $kind='class'">
+ <text>disjointWith</text>
+ </when>
+ <when test="$relationship='disjoint' and $kind='property'">
+ <text>propertyDisjointWith</text>
+ </when>
+ </choose>
+ </element>
+ <element name="Vocab:namespace">
+ <choose>
+ <when test="$relationship='super'">
+ <text>http://www.w3.org/2000/01/rdf-schema#</text>
+ </when>
+ <otherwise>
+ <text>http://www.w3.org/2002/07/owl#</text>
+ </otherwise>
+ </choose>
+ </element>
+ </variable>
+ <exslfunc:result select="exsl:node-set($result-fragment)"/>
+ </exslfunc:function>
+ <template name="Vocab:get-fragment-of-equivalents">
+ <param name="kind" select="'individual'"/>
+ <param name="resource-nodes" select="/.."/> <!-- not yet processed, but selected -->
+ <param name="include-self" select="true()"/> <!-- make false on first run to not include provided nodes -->
+ <param name="exclude" select="/.."/> <!-- leave named nodes out of result -->
+ <param name="gotten" select="/.."/> <!-- already processed -->
+ <variable name="root" select="/"/>
+ <variable name="relationship-names" select="Vocab:relationship-names($kind, 'equivalent')"/>
+ <variable name="gotten-nodes" select="exsl:node-set($gotten)/*"/>
+ <variable name="next"> <!-- new selection -->
+ <for-each select="$resource-nodes/@rdf:about">
+ <!-- Iterate over each named resource to get, find it, and get the equivalent resources. -->
+ <if test="not(($gotten-nodes|../preceding-sibling::*)/@rdf:about[string()=string(current())])">
+ <variable name="source" select="string()"/>
+ <for-each select="$root">
+ <for-each select="key(concat('Vocab:named-', $kind), $source)">
+ <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
+ <with-param name="source" select="$source"/>
+ </apply-templates>
+ </for-each>
+ <for-each select="key(concat('Vocab:equivalent-', $kind), $source)">
+ <apply-templates select="." mode="Vocab:format-get">
+ <with-param name="source" select="string(@rdf:about)"/>
+ </apply-templates>
+ </for-each>
+ </for-each>
+ </if>
+ </for-each>
+ </variable>
+ <variable name="next-nodes" select="exsl:node-set($next)/*"/>
+ <if test="$include-self">
+ <for-each select="$resource-nodes">
+ <if test="not(@rdf:about and ($exclude|$gotten-nodes|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])">
+ <apply-templates select="." mode="Vocab:format-get"/>
+ </if>
+ </for-each>
+ </if>
+ <if test="$next-nodes">
+ <call-template name="Vocab:get-fragment-of-equivalents">
+ <with-param name="kind" select="$kind"/>
+ <with-param name="resource-nodes" select="$next-nodes"/>
+ <with-param name="exclude" select="$exclude"/>
+ <with-param name="gotten">
+ <copy-of select="$gotten-nodes"/>
+ <for-each select="$resource-nodes">
+ <if test="not(@rdf:about and ($gotten-nodes|preceding-sibling::*)/@rdf:about[string()=string(current()/@rdf:about)])">
+ <copy-of select="."/>
+ </if>
+ </for-each>
+ </with-param>
+ </call-template>
+ </if>
+ </template>
+ <template name="Vocab:get-fragment-of-transitives">
+ <param name="kind" select="'individual'"/>
+ <param name="relationship"/>
+ <param name="resource-nodes" select="/.."/> <!-- not yet processed, but selected -->
+ <param name="include-self" select="true()"/> <!-- make false on first run to not include provided nodes -->
+ <param name="exclude" select="/.."/> <!-- leave named nodes out of result -->
+ <param name="gotten" select="/.."/> <!-- already processed -->
+ <variable name="root" select="/"/>
+ <variable name="relationship-names" select="Vocab:relationship-names($kind, $relationship)"/>
+ <if test="string($relationship-names/Vocab:local-name)!=''">
+ <variable name="gotten-nodes" select="exsl:node-set($gotten)/*"/>
+ <variable name="equivalent-nodes" select="Vocab:get-equivalents($resource-nodes, $kind, true(), $gotten-nodes)"/> <!-- already deduped -->
+ <variable name="next"> <!-- new selection -->
+ <for-each select="$equivalent-nodes/@rdf:about">
+ <!-- Iterate over each named resource to get, find it, and get the related resources. -->
+ <variable name="source" select="string()"/>
+ <for-each select="$root">
+ <for-each select="key(concat('Vocab:named-', $kind), $source)">
+ <apply-templates select="*[local-name()=$relationship-names/Vocab:local-name and namespace-uri()=$relationship-names/Vocab:namespace]" mode="Vocab:format-get">
+ <with-param name="source" select="$source"/>
+ </apply-templates>
+ </for-each>
+ </for-each>
+ </for-each>
+ </variable>
+ <variable name="next-nodes" select="exsl:node-set($next)/*"/>
+ <if test="$include-self">
+ <for-each select="$equivalent-nodes">
+ <if test="not(@rdf:about and $exclude/@rdf:about[string()=string(current()/@rdf:about)])">
+ <copy-of select="."/>
+ </if>
+ </for-each>
+ </if>
+ <if test="$next-nodes">
+ <call-template name="Vocab:get-fragment-of-transitives">
+ <with-param name="kind" select="$kind"/>
+ <with-param name="relationship" select="$relationship"/>
+ <with-param name="resource-nodes" select="$next-nodes"/>
+ <with-param name="exclude" select="$exclude"/>
+ <with-param name="gotten">
+ <copy-of select="$gotten-nodes"/>
+ <copy-of select="$equivalent-nodes"/>
+ </with-param>
+ </call-template>
+ </if>
+ </if>
+ </template>
+ <template match="*" mode="Vocab:format-get">
+ <param name="source"/>
+ <choose>
+ <when test="Vocabvocab:inferred-from">
+ <copy-of select="."/>
+ </when>
+ <when test="@rdf:about|@rdf:resource">
+ <element name="rdf:Description">
+ <attribute name="rdf:about">
+ <value-of select="@rdf:about|@rdf:resource"/>
+ </attribute>
+ <if test="string($source)!=''">
+ <element name="Vocabvocab:inferred-from">
+ <attribute name="rdf:resource">
+ <value-of select="$source"/>
+ </attribute>
+ </element>
+ </if>
+ </element>
+ </when>
+ <otherwise>
+ <for-each select="*">
+ <copy>
+ <copy-of select="@*|node()"/>
+ <if test="string($source)!=''">
+ <element name="Vocabvocab:inferred-from">
+ <attribute name="rdf:resource">
+ <value-of select="$source"/>
+ </attribute>
+ </element>
+ </if>
+ </copy>
+ </for-each>
+ </otherwise>
+ </choose>
+ </template>
+</transform>