#!/usr/bin/perl -s use strict; use File::Copy; our ($q, $tmx, $dmp,$langs,$log, $bidi,$clean); $langs ||= "en..pt"; my ($l1,$l2) = split(/\.\./,$langs); $log ||= "__PTDsAdd.log"; open(L,">$log") or die("cant create log file '$log'\n"); my @l=(); if ($tmx) { push ( @l,(<*.tmx>));} if ($dmp) { push ( @l,(<*.dmp>));} if (@ARGV){ push ( @l, @ARGV ); } $q = scalar (@l) unless $q; for ($q .. scalar(@l)-1){ delete $l[$_]; } my @Q=(); die("nothing to add\n") unless @l; for (1..$q) { if($l[$_-1]=~ /(.+)\.tmx$/){ print L "$_ = $l[$_-1]\n"; proc_tmx($_,$l[$_-1],$l1,$l2); push(@Q,$_); } elsif($l[$_-1]=~ /(.+)\.dmp$/){ print L "$_ = $l[$_-1]\n"; copy($l[$_-1],nam($l1,$l2,$_)); push(@Q,$_); } } my $next = $q + 1; while(scalar(@Q) > 1){ my $n1= shift(@Q); my $n2= shift(@Q); push(@Q, junta($n1,$n2,$l1,$l2)); print L $next++ , "= $n1 + $n2\n"; } system ("jj-PTDfilter ". nam($l1,$l2,$Q[0])); system ("jj-PTDfilter ". nam($l2,$l1,$Q[0])) if($bidi); close(F); sub nam{ "__$_[0]..$_[1]-$_[2].dmp"} sub junta{ my ($n1,$n2,$l1,$l2) = @_; print STDERR "==== $n1 + $n2 \n"; system("nat-ptd add ". nam($l1,$l2,$n1). " ". nam($l1,$l2,$n2). "> ". nam($l1,$l2,$next)); system("nat-ptd add ". nam($l2,$l1,$n1). " ". nam($l2,$l1,$n2). "> ". nam($l2,$l1,$next)) if $bidi; $next; } sub proc_tmx{ my ($i,$tmx,$l1,$l2)=@_; print ("\n##################id=_$i #tmx\n"); system("nat-create -langs=$l1..$l2 -id=_$i -tmx -tokenize $tmx\n") unless -f "_$i/source-target.dmp"; system ("jj-PTDfilter _$i/source-target.dmp ") unless -f "_$i/source-target-f.dmp"; move("_$i/source-target-f.dmp",nam($l1,$l2,$i)); if ($bidi){ system ("jj-PTDfilter _$i/target-source.dmp ") unless -f "_$i/target-source-f.dmp"; move("_$i/target-source-f.dmp",nam($l2,$l1,$i)); } unlink( <_$i/*> ) if $clean; system( "rmdir _$i" ) if $clean; } __END__ =head1 NAME nat-PTDsAdd - Sum collections of PTDs and TMX =head1 SYNOPSIS nat-PTDsAdd [options] file* options -tmx include the TMX included in the present directory -dmp include PTD dump files in current directory -q=max just process the first max files -langs=en..pt define the languages (for TMX files) =head1 DESCRIPTION =head1 AUTHOR J.Joao Almeida, jj@di.uminho.pt =head1 SEE ALSO perl(1). =cut