Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client-stdin.perl « server « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7a0c136b37224718c3704a9bb66994727aae3668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env perl

#
# Sample client for mosesserver, illustrating allignment info and
# report all factors
#
use strict;
use Encode;
use XMLRPC::Lite;
use utf8;

binmode(STDIN,  ":utf8");


my $url = "http://localhost:8080/RPC2";
my $proxy = XMLRPC::Lite->proxy($url);

my $text;
while ($text = <STDIN>) {
#for (my $i = 0; $i < scalar(@doc); ++$i) {
#  my $text = $doc[$i];

  # Work-around for XMLRPC::Lite bug
  #my $encoded = SOAP::Data->type(string => Encode::encode("utf8",$text));
  my $encoded = SOAP::Data->type(string => $text);

  my %param = ("text" => $encoded, "align" => "true", "report-all-factors" => "true");
  my $result = $proxy->call("translate",\%param)->result;
  print $result->{'text'} . "\n";
  if ($result->{'align'}) {
      print "Phrase alignments: \n";
      my $aligns = $result->{'align'};
      foreach my $align (@$aligns) {
        print $align->{'tgt-start'} . "," . $align->{'src-start'} . "," 
            . $align->{'src-end'} . "\n"; 
      }
  }
}