<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!--
    /////////////////////////////////////////////////////////////////////////////
    // This file is part of the "OPeNDAP 4 Data Server (aka Hyrax)" project.
    //
    //
    // Copyright (c) 2010 OPeNDAP, Inc.
    // Author: <NAME>  <<EMAIL>>
    //
    // This library is free software; you can redistribute it and/or
    // modify it under the terms of the GNU Lesser General Public
    // License as published by the Free Software Foundation; either
    // version 2.1 of the License, or (at your option) any later version.
    //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // Lesser General Public License for more details.
    //
    // You should have received a copy of the GNU Lesser General Public
    // License along with this library; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    //
    // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
    /////////////////////////////////////////////////////////////////////////////
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:nons="http://iridl.ldeo.columbia.edu/ontologies/xsd2owl/nonamespace#"
    version="1.0">

    <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>
    
    <xsl:template match="*" mode="xml2rdf">
        <xsl:variable name="myElementNamespace">
            <xsl:call-template name="getConvertedNamespace"/>
        </xsl:variable>       
        <xsl:variable name="myTextContent">
            <xsl:call-template name="getTextFromJustThisNode"/>
        </xsl:variable>
 
        <xsl:choose>
            <!-- Does the element have either child elements, or xml attributes? -->
            <xsl:when test="child::* or @*">
                
                <!-- That means it's an rdf:Resource -->
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <rdf:Description>
                        <xsl:if test="boolean(@rdf:about)">
                            <xsl:attribute name="rdf:about"><xsl:value-of select="@rdf:about"/></xsl:attribute>
                        </xsl:if>

                        <!-- Convert the attributes to elements -->
                        <xsl:for-each select="@*">
                            <xsl:variable name="attNamespace"><xsl:call-template name="getConvertedNamespace"/></xsl:variable>
                            <xsl:element name="{local-name()}" namespace="{$attNamespace}"><xsl:value-of select="."/></xsl:element>
                        </xsl:for-each>

                        <!-- Process the children -->
                        <xsl:apply-templates mode="xml2rdf"/>

                        <!-- Add the text content of the node wrapped in an rdf:value element -->
                        <xsl:if test="$myTextContent!=''">
                            <xsl:element name="rdf:value"><xsl:value-of select="$myTextContent"/></xsl:element>
                        </xsl:if>

                    </rdf:Description>
                    
                </xsl:element>
            </xsl:when>

            <!-- Is the element empty?? -->
            <xsl:when test="not(child::*) and not(@*) and not(text())"> 
                <!-- Then tag it as empty -->
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <xsl:attribute name="rdf:resource">http://www.w3.org/1999/02/22-rdf-syntax-ns#nil</xsl:attribute>
                </xsl:element>
            </xsl:when>
            
            <!-- Otherwise it must be a element with simple text content so we just need to copy it. 
                 But we still need to transform the namespace to end with a '#' if it doesn't already. -->
            <xsl:otherwise>
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <xsl:value-of select="."/>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
    
    <!-- Suppress all text and attribute output other than what we define for this mode -->
    <xsl:template match="@*|text()" mode="xml2rdf"/>
    
    
    
    <!-- 
        Convert namespaces to our RDF namespace scheme:
         - Assign items not in any namespace to our nonamespace namespace.
         - Add a trailing '#' to namespaces that don't already have one.
      -->
    <xsl:template name="getConvertedNamespace">
        <xsl:choose>
            <!-- If the node is not in a namespace, return our special "no namespace" namespace -->
            <xsl:when test="namespace-uri()=''">
                <xsl:value-of select="'http://iridl.ldeo.columbia.edu/ontologies/xsd2owl/nonamespace#'"/>
            </xsl:when>
            
            <xsl:otherwise>
                <xsl:choose>
                    <!-- If the namespace ends in '#', use it as is -->
                    <xsl:when test="substring(namespace-uri(),string-length(namespace-uri()))='#'">
                        <xsl:value-of select="namespace-uri()"/>
                    </xsl:when>
                    <!-- Otherwise add a '#' to the end of the namespace and use that. -->
                    <xsl:otherwise>
                        <xsl:value-of select="concat(namespace-uri(),'#')"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
    
    
    <!-- Get the text content for just the current node, no recursion. -->
    <xsl:template name="getTextFromJustThisNode">
        <xsl:for-each select="text()"><xsl:value-of select="normalize-space(.)"/></xsl:for-each>
    </xsl:template>





</xsl:stylesheet><commit_msg>olfs: Changed representation of empty nodes.<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!--
    /////////////////////////////////////////////////////////////////////////////
    // This file is part of the "OPeNDAP 4 Data Server (aka Hyrax)" project.
    //
    //
    // Copyright (c) 2010 OPeNDAP, Inc.
    // Author: <NAME>  <<EMAIL>>
    //
    // This library is free software; you can redistribute it and/or
    // modify it under the terms of the GNU Lesser General Public
    // License as published by the Free Software Foundation; either
    // version 2.1 of the License, or (at your option) any later version.
    //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // Lesser General Public License for more details.
    //
    // You should have received a copy of the GNU Lesser General Public
    // License along with this library; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    //
    // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
    /////////////////////////////////////////////////////////////////////////////
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:nons="http://iridl.ldeo.columbia.edu/ontologies/xsd2owl/nonamespace#"
    version="1.0">

    <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>
    
    <xsl:template match="*" mode="xml2rdf">
        <xsl:variable name="myElementNamespace">
            <xsl:call-template name="getConvertedNamespace"/>
        </xsl:variable>       
        <xsl:variable name="myTextContent">
            <xsl:call-template name="getTextFromJustThisNode"/>
        </xsl:variable>
 
        <xsl:choose>
            <!-- Does the element have either child elements, or xml attributes? -->
            <xsl:when test="child::* or @*">
                
                <!-- That means it's an rdf:Resource -->
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <rdf:Description>
                        <xsl:if test="@rdf:about">
                            <xsl:attribute name="rdf:about"><xsl:value-of select="@rdf:about"/></xsl:attribute>
                        </xsl:if>

                        <!-- Convert the attributes to elements -->
                        <xsl:for-each select="@*[generate-id(.) != generate-id(../@rdf:about)]">
                            <xsl:variable name="attNamespace"><xsl:call-template name="getConvertedNamespace"/></xsl:variable>
                            <xsl:element name="{local-name()}" namespace="{$attNamespace}"><xsl:value-of select="."/></xsl:element>
                        </xsl:for-each>

                        <!-- Process the children -->
                        <xsl:apply-templates mode="xml2rdf"/>

                        <!-- Add the text content of the node wrapped in an rdf:value element -->
                        <xsl:if test="$myTextContent!=''">
                            <xsl:element name="rdf:value"><xsl:value-of select="$myTextContent"/></xsl:element>
                        </xsl:if>

                    </rdf:Description>
                    
                </xsl:element>
            </xsl:when>

            <!-- Is the element empty?? -->
            <xsl:when test="not(child::*) and not(@*) and not(text())"> 
                <!-- Then tag it as empty -->
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <xsl:attribute name="rdf:resource">http://www.w3.org/1999/02/22-rdf-syntax-ns#nil</xsl:attribute>
                </xsl:element>
            </xsl:when>
            
            <!-- Otherwise it must be a element with simple text content so we just need to copy it. 
                 But we still need to transform the namespace to end with a '#' if it doesn't already. -->
            <xsl:otherwise>
                <xsl:element name="{local-name()}" namespace="{$myElementNamespace}">
                    <xsl:value-of select="."/>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
    
    <!-- Suppress all text and attribute output other than what we define for this mode -->
    <xsl:template match="@*|text()" mode="xml2rdf"/>
    
    
    
    <!-- 
        Convert namespaces to our RDF namespace scheme:
         - Assign items not in any namespace to our nonamespace namespace.
         - Add a trailing '#' to namespaces that don't already have one.
      -->
    <xsl:template name="getConvertedNamespace">
        <xsl:choose>
            <!-- If the node is not in a namespace, return our special "no namespace" namespace -->
            <xsl:when test="namespace-uri()=''">
                <xsl:value-of select="'http://iridl.ldeo.columbia.edu/ontologies/xsd2owl/nonamespace#'"/>
            </xsl:when>
            
            <xsl:otherwise>
                <xsl:choose>
                    <!-- If the namespace ends in '#', use it as is -->
                    <xsl:when test="substring(namespace-uri(),string-length(namespace-uri()))='#'">
                        <xsl:value-of select="namespace-uri()"/>
                    </xsl:when>
                    <!-- Otherwise add a '#' to the end of the namespace and use that. -->
                    <xsl:otherwise>
                        <xsl:value-of select="concat(namespace-uri(),'#')"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
    
    
    <!-- Get the text content for just the current node, no recursion. -->
    <xsl:template name="getTextFromJustThisNode">
        <xsl:for-each select="text()"><xsl:value-of select="normalize-space(.)"/></xsl:for-each>
    </xsl:template>



    <xsl:template match="/">
        <xsl:apply-templates mode="xml2rdf"/>
    </xsl:template>


</xsl:stylesheet>
{'fraction_non_alphanumeric': 0.16479738027015964, 'fraction_numerical': 0.011379451494064675, 'mean_word_length': 1.6871975362956446, 'pattern_counts': {'":': 0, '<': 188, '<?xml version=': 2, '>': 188, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 19}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '724222', 'n_tokens_mistral': 3542, 'n_tokens_neox': 3138, 'n_words': 870}