The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl -s

eval 'exec /usr/bin/perl -s -S $0 ${1+"$@"}'
    if 0; # not running under some shell

our ($all);

my $langa = shift;
my ($l1,$l2) = ($langa =~ m{(.*)\.\.(.*)});
die("Usage: $0 l1..l2  thesaurus\n") unless $l1 && $l2;

$l1=uc($l1);
$l2=uc($l2);

my $thesaurus= shift or die("Usage: $0 l1..l2  thesaurus\n") ;

die("thesaurus $thesaurus not found\n") unless -f $thesaurus;

use Biblio::Thesaurus;

my $obj = thesaurusLoad($thesaurus);
### open (G,">_bilingue") or die("cant create bilingue");

print "%encoding ",$obj->{encoding},"\n\n"  if defined $obj->{encoding};
binmode(STDOUT, $obj->{encoding}.":")  if defined $obj->{encoding};

$obj->downtr(
   { $l1 => sub { $p1 = $terms[0] ; },
     $l2 => sub { $p2 = $terms[0] ; },
     IOF => sub { $cl = join(",",@terms); },
#     BT => sub { $bt = join(",",@terms); },
     -eachTerm => sub { 
         if(uc($obj->baselang()) eq $l1) {$p1 =  $term; }
         if(uc($obj->baselang()) eq $l2) {$p2 =  $term; }
#         $cl ||=$bt;
         if ($p1 || $p2){
           $p1 = "[$l1-$l2 $p2]" unless $p1;
           $p2 = "[$l2-$l1 $p1]" unless $p2;
           if ($all){ print "$p1 : $p2 : $cl\n"}
           else     { print "$p1 : $p2 : $cl\n" unless $p1 =~ /^[\[]/ || $p2 =~ /^[\[]/ ; }
           $p1 = $p2 = $bt = $cl = ""; }   
         else {""}
     }
   });

__END__

=head1 NAME

thesaurus2biling - converts a ISO-... thesaurus in a bilingual dictionary

=head1 SYNOPSIS

 thesaurus2biling [-all] lang1..lang2 thesaurus > bilingDict

=head1 DESCRIPTION


By default the terms straring with "[" are skiped. Use "-all" option
to obtain all the terms.

=head2 Output Format

 <term lang1>:<term lang2>:<class>
 <term lang1>:<term lang2>:<class>

=head1 AUTHOR

J.Joao Almeida, jj@di.uminho.pt

=head1 SEE ALSO

perl(1).

=cut