frhyme

guess the last phonemes of a French word
git clone https://a3nm.net/git/frhyme/
Log | Files | Refs | README

subst.pl (672B)


      1 #!/usr/bin/perl
      2 
      3 # This file fixes Lexique's pronunciation info from the home-grown
      4 # format described in
      5 # http://www.lexique.org/outils/Manuel_Lexique.htm#_Toc108519023 to a
      6 # variation of the X-SAMPA standard
      7 
      8 
      9 sub subst {
     10   my $a = shift;
     11   # substitutions to apply
     12   my @s = (
     13     ['§', '$'],
     14     ['@', '#'],
     15     ['1', '('],
     16     ['5', ')'],
     17     ['°', '@'],
     18     ['3', '@'],
     19     ['H', '8'],
     20     ['N', 'J'],
     21     ['G', 'N'],
     22   );
     23   foreach my $t (@s) {
     24     $a =~ s/${$t}[0]/${$t}[1]/g
     25   }
     26   return $a;
     27 }
     28 
     29 while (<>) {
     30   chop;
     31   if (/^([^\t]*)\t([^\t]*)(.*)$/) {
     32     my $repl = subst $2;
     33     print "$1\t$repl$3\n";
     34   } else {
     35     die "Cannot process line: $_\n";
     36   }
     37 }
     38