| | |
| | use strict; |
| | use Frontier::Client; |
| |
|
| | my $output_suffix = $ARGV[0]; |
| | $output_suffix = "" if (not $output_suffix); |
| |
|
| | my $port = "50015"; |
| | my $url = "http://localhost:".$port."/RPC2"; |
| | my $server = Frontier::Client->new('url' => $url, 'encoding' => 'UTF-8'); |
| | my $verbose=0; |
| |
|
| | my $translations="translations$output_suffix.out"; |
| | open TR, ">:utf8", $translations; |
| | my $sg_out="searchGraph$output_suffix.out"; |
| | open SG, ">:utf8", $sg_out; |
| |
|
| | my $i=0; |
| | while (my $text = <STDIN>) |
| | { |
| | my $date = `date`; |
| | chop($date); |
| | print "[$date] sentence $i: translate\n" if $verbose; |
| | |
| | |
| | my $core_weights = "0.0314787,-0.138354,1,0.0867223,0.0349965,0.104774,0.0607203,0.0516889,0.113694,0.0947218,0.0642702,0.0385324,0.0560749,0.0434684,0.0805031"; |
| | |
| | |
| | my $sparse_weights = ""; |
| | my %param = ("core-weights" => $core_weights, "sparse-weights" => $sparse_weights); |
| | $server->call("setWeights",(\%param)); |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | %param = ("text" => $text, "id" => $i, "sg" => "true"); |
| | my $result = $server->call("translate",(\%param)); |
| |
|
| | $date = `date`; |
| | chop($date); |
| | print "[$date] sentence $i: process translation\n" if $verbose; |
| |
|
| | |
| | my $mt_output = $result->{'text'}; |
| | $mt_output =~ s/\|\S+//g; |
| | print "sentence $i >> $translations \n"; |
| | print TR $mt_output."\n"; |
| |
|
| | |
| | print "sentence $i >> $sg_out \n"; |
| | my $sg_ref = $result->{'sg'}; |
| | foreach my $sgn (@$sg_ref) { |
| | |
| | if ($sgn->{hyp} eq 0) { |
| | print SG "$i hyp=$sgn->{'hyp'} stack=$sgn->{'stack'} forward=$sgn->{'forward'} fscore=$sgn->{'fscore'} \n"; |
| | } |
| | else { |
| | print SG "$i hyp=$sgn->{'hyp'} stack=$sgn->{'stack'} back=$sgn->{'back'} score=$sgn->{'score'} transition=$sgn->{'transition'} "; |
| | if ($sgn->{"recombined"}) { |
| | print SG "recombined=$sgn->{'recombined'} "; |
| | } |
| | print SG "forward=$sgn->{'forward'} fscore=$sgn->{'fscore'} covered=$sgn->{'cover-start'}-$sgn->{'cover-end'} "; |
| | print SG "scores=\"$sgn->{'scores'}\" src-phrase=\"$sgn->{'src-phrase'}\" tgt-phrase=\"$sgn->{'tgt-phrase'}\" \n"; |
| | } |
| | } |
| |
|
| | ++$i; |
| | } |
| |
|
| | close(SG); |
| |
|