<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. -->
<!--Author of this style sheet: Ralf Herzog
    Date of creation: May 2010 -->

<!-- June 2010 -->
<xsl:template match="lexicon"><xsl:text>
</xsl:text>
<xsl:comment>    Ralf's German dictionary (version 0.1.9.4; <xsl:value-of select="substring-before(string(current-date()), '+')"/>)
        with <xsl:value-of select="count(lexeme)"/> Standard German words. 
        Import this PLS dictionary into 'simon'. More info:
        http://spirit.blau.in/simon/tag/node16/ </xsl:comment><xsl:text>
</xsl:text>
<xsl:comment>    This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.
        
        This program 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 General Public License for more details.
        
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.  </xsl:comment><xsl:text>
</xsl:text>

<xsl:text disable-output-escaping="yes">&lt;lexicon version="1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon 
        http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
      alphabet="ipa" xml:lang="de-DE"&gt;</xsl:text>
<!--
<lexicon version="1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon 
        http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
      alphabet="ipa" xml:lang="de-DE">-->
    

  <metadata>
    <rdf:RDF
       xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:dc  = "http://purl.org/dc/elements/1.1/"><xsl:text>
       </xsl:text>

     <!-- Metadata about this PLS document -->
     <rdf:Description rdf:about=""
       dc:title="Ralf's German dictionary"
       dc:description="Pronunciation of Standard German words"
       dc:publisher="Ralf Herzog"
       dc:date="2010-05-13"
       dc:rights="GPLv3"
       dc:format="application/pls+xml">
       <dc:creator>Ralf Herzog</dc:creator><xsl:text>
</xsl:text>
     </rdf:Description>
    </rdf:RDF>
  </metadata>

<xsl:for-each-group select="lexeme" group-by="grapheme">
 <xsl:sort select="grapheme" order="ascending"/><!--  -->
 <xsl:text>
 </xsl:text>
 <xsl:element name="lexeme">
  <xsl:attribute name="role">
   <xsl:call-template name="display-value-of-role-attribute"/>
  </xsl:attribute>
  <xsl:for-each select="grapheme">
   <xsl:call-template name="create-german-grapheme-element"/>
  </xsl:for-each>
  <xsl:variable name="modified">
   <xsl:call-template name="when-grapheme-contains-then-modify-phoneme"/>
  </xsl:variable>
  <xsl:sequence select="$modified"/><xsl:text>
 </xsl:text>
 </xsl:element>
</xsl:for-each-group><xsl:text>
</xsl:text><!--
</lexicon>--><xsl:text disable-output-escaping="yes">&lt;lexicon&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:comment>	This PLS dictionary is licensed under the GPLv3.
        Read the full license text: http://script.blau.in/etc/GPL_License </xsl:comment><xsl:text>
</xsl:text>
</xsl:template>

<!-- May 2010 -->
<xsl:template name="display-value-of-role-attribute">
 <xsl:variable name="terminal">
  <xsl:value-of select="@role"/>
 </xsl:variable>
 <xsl:variable name="terminal">
 <xsl:choose>
  <xsl:when test="$terminal=''">
     <xsl:if test="ends-with(grapheme, 'gehst')">
    <xsl:text>Verb Singular Gegenwart Indikativ</xsl:text>
   </xsl:if>
   <xsl:if test="ends-with(grapheme, 'endem')">
    <xsl:text>Adjektiv Dativ Singular</xsl:text>
   </xsl:if>
   <xsl:if test="ends-with(grapheme, 'enden')">
    <xsl:text>Adjektiv Akkusativ</xsl:text>
   </xsl:if>
   <xsl:if test="ends-with(grapheme, 'endes')">
    <xsl:text>Adjektiv Neutrum</xsl:text>
   </xsl:if>
   <xsl:if test="ends-with(grapheme, 'test')">
    <xsl:text>Verb Singular Imperfekt KonjunktivII</xsl:text>
   </xsl:if>
    <!--<xsl:if test="ends-with(grapheme, 'endes')">
    <xsl:text>Adjektiv Neutrum</xsl:text>
   </xsl:if>-->
   
  </xsl:when>
  <xsl:otherwise> <!---->
   <xsl:value-of select="@role"/>
  </xsl:otherwise>
 </xsl:choose>
 </xsl:variable>
 <xsl:sequence select="$terminal"/><!---->
</xsl:template>

<!-- 20100404 
<xsl:template name="create-different-phonemes">
     <xsl:param name="iieren"></xsl:param>
     <xsl:variable name="different">
      <xsl:for-each select="phoneme">
       <xsl:value-of select="string-join((., $iieren), ' ')"/><xsl:text> </xsl:text>
      </xsl:for-each>
     </xsl:variable> 
     <xsl:variable name="different" select="tokenize(($different), ' ')"/>
     <xsl:for-each select="distinct-values($different)">
<xsl:if test="not(.='')">
<xsl:text>
   </xsl:text>
       <xsl:element name="phoneme">
        <xsl:value-of select="."/>
       </xsl:element>
</xsl:if>
     </xsl:for-each>
</xsl:template>-->

<!-- May 2010 -->
<xsl:template name="when-grapheme-contains-then-modify-phoneme">
  <xsl:choose>
      <!-- June 2010 -->
  <xsl:when test="contains(lower-case(grapheme), 'öl')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ʔœl', 'ʔøːl')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
    <!-- June 2010 -->
  <xsl:when test="contains(lower-case(grapheme), 'streit')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'stʀaɪ̯t', 'ʃtʀaɪ̯t')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
  <!-- May 2010 -->
  <xsl:when test="contains(lower-case(grapheme), 'quer')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'kvɛʀ', 'kveːʀ')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
  <!-- May 2010 -->
  <xsl:when test="contains(lower-case(grapheme), 'ungssch')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ʊŋsç', 'ʊŋsʃ')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
      <!-- May 2010 -->
  <xsl:when test="contains(lower-case(grapheme), 'zwei')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tsvaɪ̯', 't͡svaɪ̯')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
    <!-- May 2010 -->
  <xsl:when test="ends-with(lower-case(grapheme), 'z')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ts', 't͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when> 
  <!-- May 2010 -->
  <xsl:when test="starts-with(lower-case(grapheme), 'z')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ts', 't͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Holz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'hɔlts', 'hɔlt͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'holz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'hɔlts', 'hɔlt͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="ends-with(grapheme, 'ohr')">
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'oːʀ', 'oːɐ̯')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Tanz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tants', 'tant͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'tanz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tants', 'tant͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Medien')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'meːdiːn', 'meːdi̯ɛn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'medien')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'meːdiːn', 'meːdi̯ɛn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'ngeschicht')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ŋɛʃɪçt', 'ngəʃɪçt')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'befehl')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'beːfeːl', 'bəfeːl')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, '1')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tseːn', 't͡seːn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!--20100402-->
    <xsl:when test="starts-with(grapheme, 'Depot')">
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'deːpɔt', 'deːpoː')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  
  <xsl:otherwise>
    <xsl:call-template name="improve-quality-of-phonemes"/> 
  </xsl:otherwise>
  </xsl:choose>


</xsl:template>

<!-- May 2010 -->
<xsl:template name="improve-quality-of-phonemes">
 <xsl:variable name="sierra">
  <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text>
   <xsl:element name="phoneme">
    <xsl:variable name="sierra">
     <xsl:value-of select="."/>
    </xsl:variable>
    <!-- May 2010 <xsl:variable name="sierra" select="replace($sierra, '', '')"/>
    <xsl:variable name="sierra" select="replace($sierra, '', '')"/>-->
    <xsl:variable name="sierra" select="replace($sierra, 'veːʀɛndəʀʊŋ', 'fɛʀɛndəʀʊŋ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ʃʊldf', 'ʃʊltf')"/>
<xsl:variable name="sierra" select="replace($sierra, 'kʀiːgsç', 'kʀiːgsʃ')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'vɐgaːbə', 'fɐgaːbə')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'vɐkaʊ̯f', 'fɐkaʊ̯f')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'vɐkeːʀ', 'fɐkeːʀ')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'vɐtsiːɐ̯t', 'fɐt͡siːɐ̯t')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'veːʀanstaltʊŋ', 'fɛʀanʃtaltʊŋ')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'hœltsɐ', 'hœlt͡sɐ')"/>
    <xsl:variable name="sierra" select="replace($sierra, 'vɐtaɪ̯lʊŋ', 'fɐtaɪ̯lʊŋ')"/>
    <xsl:sequence select="$sierra"/>
   </xsl:element>
  </xsl:for-each>
 </xsl:variable>
 <xsl:sequence select="$sierra"/>
</xsl:template>



<!-- May 2010 -->
<xsl:template name="create-german-grapheme-element">
 <xsl:variable name="current-grapheme">
 <xsl:text>
  </xsl:text>
  <xsl:element name="grapheme">
   <xsl:value-of select="."/>
  </xsl:element>
 </xsl:variable>
 <xsl:sequence select="$current-grapheme"/>
</xsl:template>

<!-- May 2010 
<xsl:template name="create-phoneme">
 <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text>
  <element name="phoneme">
   <xsl:variable name="sierra">
    <xsl:value-of select="."/>
   </xsl:variable>
   <xsl:sequence select="$sierra"/>
  </element>
 </xsl:for-each>
</xsl:template>-->

</xsl:stylesheet>
<!--	This style-sheet is licensed under the GPLv3.
	    Read the full license text: http://script.blau.in/etc/GPL_License -->

