#!/usr/bin/perl -wn
# Copyright (C) 2009-2011  Antonio Bonafonte
#            Universitat Politcnica de Catalunya, Barcelona, Spain
#
#  This script 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,
#  version 2.1 of the License.
#
#  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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

# Create 4 multiphonemes necessary for the one-to-one LTS rules: k-s, b-b, g-g, g-z
# Output: ("niques" n (u1 n i k ax s)) 
#

chomp;

if( ! m/\((".*")\s(.+)\s\((.*)\)$/ ){
    next;
}

my($word, $pos, $trn) = m/\("(.*)"\s(.+)\s\((.*)\)\)$/;

#trn: ((O1 k) 1) ((t u) 0) ((p l ax s) 0))

my $wgn = "";
 
#Already in this format
#while( my($syl) = $trn =~ /\s*\(\(([^\)]+)\)\s[01]\)/ ) 
#{
#    $wgn = $wgn . " " . $syl;
#    $trn = $'; #' (Emacs highlighting mode does not like it...)
#}
# We use this instead of the previous loop:
$wgn = $trn;

# wgn: O1 k t u p l ax s
$wgn =~ s/^\s*//;

# Necessary for one-to-one rules
$wgn =~ s/k s/k-s/g;
$wgn =~ s/g g/g-g/g;
$wgn =~ s/b b/b-b/g;
$wgn =~ s/g z/g-z/g;

print "(\"$word\" $pos ($wgn))\n";
