<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 	20100407 french -->
<!--    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, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA. -->
<!--	This style-sheet "improve-french-dictionary.xsl" is licensed under the GPLv3.
	    Read the full license text: http://script.blau.in/etc/GPL_License -->

<!-- 20100406 -->
<xsl:template name="create-french-grapheme-element">
 <xsl:variable name="current-grapheme"><xsl:text>
  </xsl:text>
  <xsl:element name="grapheme">
   <xsl:value-of select="grapheme"/>
  </xsl:element>
 </xsl:variable>
 <xsl:sequence select="$current-grapheme"/>
</xsl:template>

<!-- use (1) create-phoneme-fast # OR (2) create-phoneme-espeaktoipa OR (3) create-phoneme 
<xsl:template name="create-phoneme-fast">
 <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><xsl:element name="phoneme">
  <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
  <xsl:sequence select="$sierra"/></xsl:element>
 </xsl:for-each>
</xsl:template>-->

<!-- (1*) create-phoneme-variable-outside 
<xsl:template name="create-phoneme-variable-outside">
 <xsl:variable name="sierra">
  <xsl:for-each select="phoneme"><xsl:text> 
1-outside   </xsl:text>
   <xsl:element name="phoneme">
    <xsl:value-of select="."/>
   </xsl:element>
  </xsl:for-each>
 </xsl:variable>
 <xsl:sequence select="$sierra"/>
</xsl:template>-->


<!-- 20100407 -->
<xsl:template name="create-french-phoneme">
 <xsl:variable name="sierra-outside">
  <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text>
   <xsl:element name="phoneme">
    <xsl:variable name="sierra">
     <xsl:value-of select="."/>
    </xsl:variable>
<!--
<xsl:variable name="sierra" select="replace($sierra, 'a2', 'a')"/>
<xsl:variable name="sierra" select="replace($sierra, 'R', 'ʀ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'A~', 'ɑ̃')"/>
<xsl:variable name="sierra" select="replace($sierra, 'E~', 'ɛ̃')"/>
<xsl:variable name="sierra" select="replace($sierra, 'E2', 'ɛ')"/>

<xsl:variable name="sierra" select="replace($sierra, 'o2', 'ɔ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'O~', 'ɔ̃')"/>
<xsl:variable name="sierra" select="replace($sierra, 'O2', 'o')"/>
<xsl:variable name="sierra" select="replace($sierra, 'W~', 'œ̃')"/>
<xsl:variable name="sierra" select="replace($sierra, 'W:', 'œ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'W2', 'œ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'W', 'ø')"/>
<xsl:variable name="sierra" select="replace($sierra, 'w\^', 'ɥ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'n\^', 'ɲ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'Y:', 'ø')"/>
<xsl:variable name="sierra" select="replace($sierra, 'Y','œ')"/> 
<xsl:variable name="sierra" select="replace($sierra, '_\^_en ', '')"/>
<xsl:variable name="sierra" select="replace($sierra, '_\^_fr ', '')"/>

 20091018 convert eSpeak to SAMPA
<xsl:variable name="sierra" select="replace($sierra, '3', 'ɐ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'A', 'a')"/>
<xsl:variable name="sierra" select="replace($sierra, 'V', 'a')"/>  --><!--english words with a 
<xsl:variable name="sierra" select="replace($sierra, '_!', 'Q')"/>
<xsl:variable name="sierra" select="replace($sierra, '_\|', 'Q')"/>
<xsl:variable name="sierra" select="replace($sierra, 'pF', 'pf')"/>-->
<!--<xsl:variable name="sierra" select="replace($sierra, 'W', 'œ')"/>

<xsl:variable name="sierra" select="replace($sierra, '@2', 'ə')"/>
<xsl:variable name="sierra" select="replace($sierra, '@-', '')"/>
<xsl:variable name="sierra" select="replace($sierra, ',', '')"/>
<xsl:variable name="sierra" select="replace($sierra, ';', '')"/>
<xsl:variable name="sierra" select="replace($sierra, '_:_:', '')"/>
<xsl:variable name="sierra" select="replace($sierra, '\*', 'ʀ')"/>-->
<!-- convert SAMPA to IPA 
<xsl:variable name="sierra" select="replace($sierra, 'aU_', 'aʊ̯')"/> 
<xsl:variable name="sierra" select="replace($sierra, 'aI_', 'aɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'EI_', 'ɛɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'aɪ̯_', 'aɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ɛɪ_', 'ɛɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ɔɪ_', 'ɔɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'aʊ̯_', 'aʊ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'au̯', 'aʊ̯')"/> 
<xsl:variable name="sierra" select="replace($sierra, 'aU', 'aʊ̯')"/> 
<xsl:variable name="sierra" select="replace($sierra, 'aI', 'aɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ɔY', 'ɔɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ai̯', 'aɪ̯')"/>
<xsl:variable name="sierra" select="replace($sierra, 'OI_', 'ɔɪ̯')"/>

<xsl:variable name="sierra" select="replace($sierra, 'n=', 'n̩')"/>
<xsl:variable name="sierra" select="replace($sierra, 'm=', 'm̩')"/>
<xsl:variable name="sierra" select="replace($sierra, 'N=', 'ŋ̩')"/>

<xsl:variable name="sierra" select="replace($sierra, 'S', 'ʃ')"/>
<xsl:variable name="sierra" select="replace($sierra, 't2', 't')"/>
<xsl:variable name="sierra" select="replace($sierra, 'T', 'θ')"/>
<xsl:variable name="sierra" select="replace($sierra, '@', 'ə')"/>
<xsl:variable name="sierra" select="replace($sierra, 'N', 'ŋ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'Q', 'ʔ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'E', 'ɛ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'O', 'ɔ')"/>
<xsl:variable name="sierra" select="replace($sierra, '0', 'ɔ')"/> --><!--for english words-->
<!--<xsl:variable name="sierra" select="replace($sierra, 'C', 'ç')"/>
<xsl:variable name="sierra" select="replace($sierra, 'I2', 'ɪ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'I', 'ɪ')"/>
<xsl:variable name="sierra" select="replace($sierra, '9', 'œ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'U', 'ʊ')"/>
<xsl:variable name="sierra" select="replace($sierra, '6', 'ɐ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'r', 'ʀ')"/>
<xsl:variable name="sierra" select="replace($sierra, 'z2', 'z')"/>
<xsl:variable name="sierra" select="replace($sierra, 'Z', 'ʒ')"/>
 normalize space 
<xsl:variable name="sierra" select="normalize-space($sierra)"/>
<xsl:variable name="sierra" select="replace($sierra, ' ', '')"/>-->
<!-- convert more SAMPA characters to IPA -->
<!--
<xsl:variable name="sierra" select="replace($sierra, 'l̩', 'l')"/>  this is a workaround to be simon compatible 
<xsl:variable name="sierra" select="replace($sierra, 'a:', 'aː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'e:', 'eː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'i:', 'iː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'o:', 'oː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'u:', 'uː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'ɛ:', 'ɛː')"/>
<xsl:variable name="sierra" select="replace($sierra, 'y:', 'yː')"/>
<xsl:variable name="sierra" select="replace($sierra, '2:', 'øː')"/>-->
 <xsl:sequence select="$sierra"/>

   </xsl:element>
  </xsl:for-each>
 </xsl:variable>
 <xsl:sequence select="$sierra-outside"/>
</xsl:template>

<!-- 20100407 -->
<xsl:template name="create-french-lexeme">
 <xsl:text>
 </xsl:text>
 <xsl:element name="lexeme">
   <xsl:call-template name="create-french-role-attribute"/>
   <xsl:call-template name="create-french-grapheme-element"/>
   <xsl:call-template name="create-french-phoneme"/>
 <xsl:text>
 </xsl:text></xsl:element>
</xsl:template>

<!-- 20100409 -->
<xsl:template name="create-french-role-attribute">
 <xsl:variable name="french-terminal">
  <xsl:choose>
   <xsl:when test="ends-with(grapheme, 'âmes')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'aient')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'ais')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'ait')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'aison')">
    <xsl:value-of>nom</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'tion')">
    <xsl:value-of>nom</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'ance')">
    <xsl:value-of>nom</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'tude')">
    <xsl:value-of>nom</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'ances')">
    <xsl:value-of>nom</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'assent')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'asses')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'assiez')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'assions')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'erai')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'eras')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'erez')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'eriez')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'erions')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'erons')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'eront')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'âtes')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:when test="ends-with(grapheme, 'èrent')">
    <xsl:value-of>verbe</xsl:value-of>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="@role"></xsl:value-of>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>
  <xsl:attribute name="role">
   <xsl:sequence select="$french-terminal"/>
  </xsl:attribute> 
</xsl:template>

<!-- 20100407 -->
<xsl:template name="create-french-grapheme">

</xsl:template>

<!-- (8*) dont use --><!--
<xsl:template name="test-grapheme-outside">
 <xsl:call-template name="grapheme-outside"/>
 <xsl:for-each select="phoneme">
 <xsl:call-template name="changephonemes">  call 10 
  <xsl:with-param name="testsierra" select="."/>
 </xsl:call-template>
 </xsl:for-each>  
</xsl:template>-->

<!-- (10) dont use
<xsl:template name="changephonemes">
 <xsl:param name="testsierra"></xsl:param>
<xsl:value-of select="grapheme"/>grapheme
<xsl:value-of select="parent::grapheme"/>parentgrapheme
   <xsl:variable name="sierra">
     <xsl:choose>
     <xsl:when test="ends-with(grapheme, 'verkehr')">
      <xsl:element name="phoneme">
       <xsl:variable name="sierra"><xsl:sequence select="$testsierra"/></xsl:variable>
       <xsl:variable name="sierra" select="replace($sierra, 'vɐkeːʀ', 'fɐkeːɐ̯')"/>
       <xsl:variable name="sierra" select="replace($sierra, 'fɐkeːʀ', 'fɐkeːɐ̯')"/>
       <xsl:sequence select="$sierra"/>
      </xsl:element>
     </xsl:when>
     <xsl:otherwise>
      <xsl:sequence select="$testsierra"/>10-otherwise
     </xsl:otherwise>
     </xsl:choose>
  </xsl:variable>
 <xsl:sequence select="$sierra"/>10-outside
</xsl:template>-->

<!-- (9) -->
<xsl:template match="lexicon"><xsl:text>
</xsl:text><!-- 20100409 --><xsl:comment>    Ralf's French dictionary (version 0.1.3; April 09, 2010)
        This PLS dictionary contains more than 300.000 French words.
        You can import this dictionary into 'simon'. 
        Currently, there are problems with the French phonemes:
        http://spirit.blau.in/simon/2010/04/06/what-happens-with-french-phonemes/
        I hope that these problems will be fixed. </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, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA. </xsl:comment><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>
<lexicon version="1.0" alphabet="ipa" xml:lang="fr-FR">

<xsl:for-each-group select="lexeme" group-by="grapheme">
<xsl:sort select="grapheme" order="ascending"/>


     <xsl:call-template name="create-french-lexeme">

     </xsl:call-template>

</xsl:for-each-group><xsl:text>
</xsl:text>
</lexicon>
</xsl:template>

</xsl:stylesheet>

