<?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, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA. -->
<!--	This style-sheet "improve-hungarian-dictionary.xsl" is licensed under the GPLv3.
	    Read the full license text: http://script.blau.in/etc/GPL_License -->
<!--    201004 -->


<xsl:template match="lexicon"><xsl:text>
</xsl:text><!-- 201004 --><xsl:comment>    Ralf's Hungarian dictionary (version 0.1.1; April 24, 2010)
        You can import this dictionary into 'simon'. More info: 
        http://spirit.blau.in/simon/tag/node22/ </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="hu">

<xsl:for-each-group select="lexeme" group-by="grapheme">
 <xsl:sort select="grapheme" order="ascending"/>
 <xsl:call-template name="create-hungarian-lexeme-element"/>
</xsl:for-each-group><xsl:text>
</xsl:text>
</lexicon>
</xsl:template>

<xsl:template name="create-hungarian-lexeme-element">
 <xsl:variable name="current-latin-lexeme">  
<!-- <xsl:choose>
   <xsl:when test="ends-with(grapheme, 'que')"/>
   <xsl:when test="ends-with(grapheme, 've')"/>
   <xsl:when test="ends-with(grapheme, 'ne')"/>
   <xsl:otherwise>-->
 <xsl:text>
 </xsl:text>
 <xsl:element name="lexeme">
  <xsl:call-template name="create-hungarian-grapheme-element"/>
  <xsl:call-template name="create-hungarian-ipa-phoneme-element"/><xsl:text>
 </xsl:text>
 </xsl:element>
 <!--</xsl:otherwise>
 </xsl:choose>-->
 </xsl:variable>
 <xsl:sequence select="$current-latin-lexeme"/>
</xsl:template>

<xsl:template name="create-hungarian-grapheme-element">
 <xsl:variable name="current-grapheme">   
<!-- <xsl:choose>
    <xsl:when test="contains(grapheme, ' ')"/>
    <xsl:when test="contains(grapheme, '	')"/>
    <xsl:otherwise>--><xsl:text>
  </xsl:text>
  <xsl:element name="grapheme">

     <xsl:value-of select="grapheme"/>

  </xsl:element>    
<!--</xsl:otherwise>
   </xsl:choose>-->
 </xsl:variable>
 <xsl:sequence select="$current-grapheme"/>
</xsl:template>

<xsl:template name="create-hungarian-ipa-phoneme-element">
 <xsl:variable name="hungarian-phoneme">
  <xsl:value-of select="phoneme"/>
 </xsl:variable>
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'A', 'ɒ')"/><!-- a -->
  <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'R2', 'ɐ̯')"/><!-- work-around, maybe a mistake -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'RR', 'r')"/><!--  -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'a:', 'aː')"/><!-- á -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'e:', 'eː')"/><!-- é -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'i:', 'iː')"/><!-- í -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'E', 'ɛ')"/><!-- e -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'u:', 'uː')"/><!-- ú -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'y:', 'yː')"/><!-- ű -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'y', 'y')"/><!-- ü -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'b', 'b')"/><!-- b -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'ts', 'ts')"/><!-- c -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'tS', 'tʃ')"/><!-- cs -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'f', 'f')"/><!-- f -->
<xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'g', 'g')"/><!-- g -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'h', 'h')"/><!-- h -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'i', 'i')"/><!-- i -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'j', 'j')"/><!-- j -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'k', 'k')"/><!-- k -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'l', 'l')"/><!-- l -->
<xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'Y:', 'øː')"/><!-- ő -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'Y', 'ø')"/><!-- ö -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'o:', 'oː')"/><!-- ó -->
<xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'n\^', 'ɲ')"/><!-- ny -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'S', 'ʃ')"/><!-- s -->
  <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 's2', 's')"/><!-- sz - is there a better solution? -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 's', 's')"/><!-- http://en.wikipedia.org/wiki/Hungarian_sz -->
<xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 't', 't')"/><!-- t -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'Z', 'ʒ')"/><!-- zs -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 't:', 't')"/> <!-- láttak -->
 <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'N', 'ŋ')"/>
  <xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'J', 'ɟ')"/><!-- http://en.wikipedia.org/wiki/Voiced_palatal_plosive -->
<xsl:variable name="hungarian-phoneme" select="replace($hungarian-phoneme, 'c', 'ç')"/><!-- t --><!-- the IPA phoneme is a work-around -->

<xsl:text>
   </xsl:text> <xsl:element name="phoneme"> 
  <xsl:sequence select="$hungarian-phoneme"/>
 </xsl:element>
</xsl:template>

</xsl:stylesheet>

