1use Getopt::Long;
2
3$rc = GetOptions("pht=s" => \$phtfile,
4		 "ok=s" => \$okfile,
5		 "i=s" => \$okfile,
6		 "otxt=s" => \$otxt,
7		 "o=s" => \$otxt,
8		 "showerrs" => \$showerrs);
9
10if(defined $phtfile) {
11    load_phtfile( $phtfile);
12}
13
14sub load_phtfile
15{
16    my $phtfile = shift(@_);
17    $lphhash{"&"}++;
18    $lph_for_sph{"&"} = "&";
19    open(PHT, "<$phtfile") || die "error opening phtfile $phtfile\n";
20    print STDERR "using phtfile $phtfile\n";
21    <PHT>;  # header
22    while(<PHT>) {
23	s/\s+$//g;
24	($trash,$lph,$sph,$num_states) = split(/\s+/);
25	$lph_for_sph{$sph} = $lph;
26	$lphhash{$lph}++;
27    }
28    close(PHT);
29}
30
31open(HH, "<$okfile") || die "error opening okfile $okfile\n";
32open(OO, ">$otxt") || die "error opening output dict $otxt\n";
33while(<HH>) {
34    s/\s+$//;
35    if(/^LANG\s*=\s*(\S+)/) { # LANG = EN-US
36	my $language = lc($1);
37	my $language_header_line = $_;
38	$language =~ s/\-/\./g;
39	if(!defined $phtfile) {
40	    die "Error: ESRSDK is not defined\n" if(!defined $ENV{ESRSDK});
41	    $phtfile = "$ENV{ESRSDK}/config/$language/models/generic.pht";
42	    load_phtfile( $phtfile);
43	}
44	print OO "$language_header_line\n";
45	next;
46    }
47    ($word, $pron) = split(/\s+/);
48    @sphlist = split(/ */, $pron);
49    @lphlist = ();
50    $nerrs = 0;
51    foreach $sph (@sphlist) {
52	$lph = $lph_for_sph{$sph};
53	if(!defined $lph) {
54	    warn "error: unknown sph $sph in $word $pron\n" ;
55	    $lph = "($sph)";
56	    $nerrs++;
57	}
58	push(@lphlist, $lph);
59    }
60    next if($nerrs && !$showerrs) ;
61    print OO "$word \t @lphlist\n";
62}
63close(HH);
64close(OO);
65