Changeset 3798 for CMDI-Interoperability


Ignore:
Timestamp:
10/18/13 11:27:01 (11 years ago)
Author:
mwindhouwer
Message:

M xsl/CMDRecord2RDF.xsl
M xsl/Component2RDF.xsl

Location:
CMDI-Interoperability/CMD2RDF/trunk/xsl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CMDI-Interoperability/CMD2RDF/trunk/xsl/CMDRecord2RDF.xsl

    r3792 r3798  
    44    <!ENTITY rdfs 'http://www.w3.org/TR/WD-rdf-schema#'>
    55    <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
     6    <!ENTITY cmdm 'http://www.clarin.eu/cmd/general.ttl#'>
    67]>
    78<xsl:stylesheet
     
    1112    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    1213    xmlns:cmd="http://www.clarin.eu/cmd/"
    13     xmlns:rel="http://www.isocat.org/relcat/relations#"
     14    xmlns:cmdm="http://www.clarin.eu/cmd/general.ttl"
    1415>
    1516   
     
    106107                <xsl:otherwise>
    107108                    <!-- use the generic RELcat related relationship for the nesting of components -->
    108                     <rel:related>
     109                    <cmdm:contains>
    109110                        <xsl:copy-of select="$class"/>
    110                     </rel:related>
     111                    </cmdm:contains>
    111112                </xsl:otherwise>
    112113            </xsl:choose>
     
    123124        <!-- extend the context with this element -->
    124125        <xsl:variable name="id" select="cmd:path($context,$name)"/>
     126        <xsl:variable name="has" select="cmd:path($context,concat('has',@name))"/>
    125127        <!-- find the matching instances -->
    126128        <xsl:for-each select="$instance/*[local-name()=$name]">
    127129            <!-- use the generic RELcat related relationship for the nesting of the element in its component -->
    128             <rel:related>
     130            <cmdm:contains>
    129131                <!-- a CMD element is a RDF class -->
    130132                <xsl:element name="{$id}" namespace="{$ns}">
    131133                    <xsl:attribute name="rdf:about" select="concat('#',generate-id(.))"/>
    132134                    <!-- the value is assigned to a propery of the CMD element RDF class -->
    133                     <xsl:element name="{$id}Value" namespace="{$ns}">
    134                         <xsl:choose>
    135                             <!-- the value comes from an enumeration and has its own URI -->
    136                             <xsl:when test="exists($profile/ValueScheme/enumeration)">
    137                                 <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>
    138                             </xsl:when>
    139                             <!-- the value is a literal -->
    140                             <xsl:otherwise>
    141                                 <!-- map the CMD XSD datatype to a datatype supported by RDF -->
    142                                 <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/@ValueScheme))"/>
    143                                 <!-- copy @xml:lang -->
    144                                 <xsl:copy-of select="@xml:lang"/>
    145                                 <!-- copy the literal -->
    146                                 <xsl:value-of select="."/>
    147                             </xsl:otherwise>
    148                         </xsl:choose>
     135                    <xsl:element name="{$has}ElementValue" namespace="{$ns}">
     136                        <!-- map the CMD XSD datatype to a datatype supported by RDF -->
     137                        <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/@ValueScheme))"/>
     138                        <!-- copy @xml:lang -->
     139                        <xsl:copy-of select="@xml:lang"/>
     140                        <!-- copy the literal -->
     141                        <xsl:value-of select="."/>
    149142                    </xsl:element>
     143                    <!-- if there is enum we also have an entity property -->
     144                    <xsl:if test="exists($profile/ValueScheme/enumeration)">
     145                        <xsl:element name="{$id}ElementEntity" namespace="{$ns}">
     146                            <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>
     147                        </xsl:element>
     148                    </xsl:if>
    150149                    <!-- switch back from the instance to the profile to handle the attributes -->
    151150                    <xsl:apply-templates select="$profile/AttributeList/Attribute">
     
    155154                    </xsl:apply-templates>
    156155                </xsl:element>
    157             </rel:related>
     156            </cmdm:contains>
    158157        </xsl:for-each>
    159158    </xsl:template>
     
    168167        <!-- extend the context with this attribute -->
    169168        <xsl:variable name="id" select="concat(cmd:path($context,$name),'Attribute')"/>
     169        <xsl:variable name="has" select="concat(cmd:path($context,concat('has',$name)),'Attribute')"/>
    170170        <!-- find the matching instances -->
    171171        <xsl:for-each select="$instance/@*[local-name()=$name]">
    172             <xsl:element name="{$id}" namespace="{$ns}">
    173                 <xsl:choose>
    174                     <!-- the value comes from an enumeration and has its own URI -->
    175                     <xsl:when test="exists($profile/ValueScheme/enumeration)">
    176                         <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>
    177                     </xsl:when>
    178                     <!-- the value is a literal -->
    179                     <xsl:otherwise>
    180                         <!-- map the CMD XSD datatype to a datatype supported by RDF -->
    181                         <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/Type))"/>
    182                         <!-- copy the literal -->
    183                         <xsl:value-of select="."/>
    184                     </xsl:otherwise>
    185                 </xsl:choose>
     172            <xsl:element name="{$has}" namespace="{$ns}">
     173                <!-- map the CMD XSD datatype to a datatype supported by RDF -->
     174                <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/Type))"/>
     175                <!-- copy the literal -->
     176                <xsl:value-of select="."/>
    186177            </xsl:element>
     178            <xsl:if test="exists($profile/ValueScheme/enumeration)">
     179                <xsl:element name="{$has}Entity" namespace="{$ns}">
     180                    <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>
     181                </xsl:element>
     182            </xsl:if>
    187183        </xsl:for-each>
    188184    </xsl:template>
  • CMDI-Interoperability/CMD2RDF/trunk/xsl/Component2RDF.xsl

    r3792 r3798  
    44    <!ENTITY rdfs 'http://www.w3.org/TR/WD-rdf-schema#'>
    55    <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
     6    <!ENTITY cmdm 'http://www.clarin.eu/cmd/general.ttl#'>
    67]>
    78<xsl:stylesheet
     
    1112    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    1213    xmlns:cmd="http://www.clarin.eu/cmd/"
     14    xmlns:cmdm="http://www.clarin.eu/cmd/general.ttl"
    1315>
    1416   
     
    5860        <!-- a component maps to an RDF class -->
    5961        <rdfs:Class rdf:about="{$id}">
     62            <xsl:choose>
     63                <xsl:when test="../CMD_ComponentSpec/@isProfile='true'">
     64                    <rdfs:subClassOf rdf:resource="&cmdm;Profile"/>
     65                </xsl:when>
     66                <xsl:otherwise>
     67                    <rdfs:subClassOf rdf:resource="&cmdm;Component"/>
     68                </xsl:otherwise>
     69            </xsl:choose>
    6070            <xsl:call-template name="generic"/>
    6171        </rdfs:Class>
     
    7181        <!-- extend the context with this element -->
    7282        <xsl:variable name="id" select="cmd:path($context,@name)"/>
     83        <xsl:variable name="has" select="cmd:path($context,concat('has',@name))"/>
    7384        <!-- element becomes a class to be able to group attributes and value together -->
    7485        <rdfs:Class rdf:about="{$id}">
     86            <rdfs:subClassOf rdf:resource="&cmdm;Element"/>
    7587            <xsl:call-template name="generic"/>
    7688        </rdfs:Class>
    7789        <!-- the value property -->
    78         <rdf:Property rdf:about="{$id}Value">
    79             <xsl:call-template name="generic"/>
     90        <rdf:Property rdf:about="{$has}ElementValue">
     91            <rdfs:subPropertyOf rdf:resource="&cmdm;hasElementValue"/>
    8092            <!-- the domain of the value property is the class corresponding to the CMD element -->
    8193            <rdfs:domain rdf:resource="{$id}"/>
    8294            <xsl:choose>
    83                 <!-- if the value scheme is an enumeration the range consists of a superclass for the specific value classes -->
     95                <!-- if the value scheme is an enumeration the range consists of the labels of the values -->
    8496                <xsl:when test="exists(ValueScheme/enumeration)">
    85                     <rdfs:range rdf:resource="{concat($id,'ValueScheme')}"/>
     97                    <rdfs:range rdf:resource="&xsd;string"/>
    8698                </xsl:when>
    8799                <!-- if the value scheme is an XSD datatype the range becomes the equivalent RDF XSD datatype -->
     
    95107            </xsl:choose>
    96108        </rdf:Property>
     109        <!-- if there is an value enumeration also have a hasElementEntity property -->
     110        <if test="exists(ValueScheme/enumeration)">
     111            <rdf:Property rdf:about="{$has}ElementEntity">
     112                <rdfs:subPropertyOf rdf:resource="&cmdm;hasElementEntity"/>
     113                <!-- the domain of the value property is the class corresponding to the CMD element -->
     114                <rdfs:domain rdf:resource="{$id}"/>
     115                <!-- the range consists of a superclass for the specific value classes -->
     116                <rdfs:range rdf:resource="{$id}Value"/>
     117            </rdf:Property>
     118        </if>
    97119        <!-- continue with the attributes and values -->
    98120        <xsl:apply-templates>
     
    109131        <xsl:variable name="id" select="replace($label,'\s','')"/>
    110132        <!-- a value in a value scheme becomes a subclass of that scheme -->
    111         <rdf:Class rdf:about="{concat($context,'ValueScheme',$STEP,$id)}">
    112             <rdf:subClassOf rdf:resource="{concat($context,'ValueScheme')}"/>
     133        <rdf:Class rdf:about="{$context}Value{$STEP}{$id}">
     134            <rdf:subClassOf rdf:resource="{$context}Value"/>
    113135            <xsl:call-template name="generic"/>
    114136            <rdfs:label>
     
    123145        <!-- extend the context with this attribute -->
    124146        <xsl:variable name="id" select="concat(cmd:path($context,Name),'Attribute')"/>
     147        <xsl:variable name="has" select="concat(cmd:path($context,concat('has',Name)),'Attribute')"/>
    125148        <!-- an attribute becomes a property -->
    126         <rdf:Property rdf:about="{$id}">
     149        <rdf:Property rdf:about="{$has}">
     150            <rdfs:subPropertyOf rdf:resource="&cmdm;hasAttributeValue"/>
    127151            <xsl:call-template name="generic"/>
    128             <!-- the domain is CMD element RDF class -->
     152            <!-- the domain is the CMD element RDF class -->
    129153            <rdfs:domain rdf:resource="{$context}"/>
    130154            <xsl:choose>
    131                 <!-- if the value scheme is an enumeration the range consists of a superclass for the specific value classes -->
     155                <!-- if the value scheme is an enumeration the range is the labels -->
    132156                <xsl:when test="exists(ValueScheme/enumeration)">
    133                     <rdfs:range rdf:resource="{concat($id,'ValueScheme')}"/>
     157                    <rdfs:range rdf:resource="&xsd;string"/>
    134158                </xsl:when>
    135159                <!-- if the value scheme is an XSD datatype the range becomes the equivalent RDF XSD datatype -->
     
    143167            </xsl:choose>
    144168        </rdf:Property>
     169        <!-- if there is an value enumeration also have a hasAttributeEntity property -->
     170        <xsl:if test="exists(ValueScheme/enumeration)">
     171            <rdf:Property rdf:about="{$has}Entity">
     172                <rdfs:subPropertyOf rdf:resource="&cmdm;hasAttributeEntity"/>
     173                <!-- the domain is the CMD element RDF class -->
     174                <rdfs:domain rdf:resource="{$context}"/>
     175                <!-- the range consists of a superclass for the specific value classes -->
     176                <rdfs:range rdf:resource="{$id}Value"/>
     177            </rdf:Property>
     178        </xsl:if>
    145179        <!-- continue with the values -->
    146180        <xsl:apply-templates>
Note: See TracChangeset for help on using the changeset viewer.