mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
Check in new version of Web translator (written in Wandlitz)
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1804 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
cf0f22dd93
commit
0feddfc436
51
web/lib/RemoteProcess.pm
Normal file
51
web/lib/RemoteProcess.pm
Normal file
@ -0,0 +1,51 @@
|
||||
# file: RemoteProcess.pm
|
||||
|
||||
# Herve Saint-Amand
|
||||
# Universitaet des Saarlandes
|
||||
# Thu May 15 08:30:19 2008
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# includes
|
||||
|
||||
package RemoteProcess;
|
||||
our @ISA = qw/Subprocess/;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use IO::Socket::INET;
|
||||
|
||||
use Subprocess;
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# constructor
|
||||
|
||||
sub new {
|
||||
my ($class, $host, $port) = @_;
|
||||
|
||||
my $self = new Subprocess;
|
||||
$self->{host} = $host;
|
||||
$self->{port} = $port;
|
||||
$self->{sock} = undef;
|
||||
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# should have the same interface as Subprocess.pm
|
||||
|
||||
sub start {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{sock} = new IO::Socket::INET (%{{
|
||||
PeerAddr => $self->{host},
|
||||
PeerPort => $self->{port},
|
||||
}}) || die "Can't connect to $self->{host}:$self->{port}";
|
||||
|
||||
$self->{child_in} = $self->{child_out} = $self->{sock};
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
1;
|
||||
|
61
web/lib/Subprocess.pm
Normal file
61
web/lib/Subprocess.pm
Normal file
@ -0,0 +1,61 @@
|
||||
# file: Subprocess.pm
|
||||
|
||||
# Herve Saint-Amand
|
||||
# Universitaet des Saarlandes
|
||||
# Wed May 14 09:55:46 2008
|
||||
|
||||
# NOTE that to use this with Philipp Koehn's tokenizer.perl I had to modify
|
||||
# that script to autoflush its streams, by adding a '$|++' to it
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# includes
|
||||
|
||||
package Subprocess;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use Encode;
|
||||
use IPC::Open2;
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# constructor
|
||||
|
||||
sub new {
|
||||
my ($class, @cmd) = @_;
|
||||
bless {
|
||||
cmd => \@cmd,
|
||||
num_done => 0,
|
||||
child_in => undef,
|
||||
child_out => undef,
|
||||
}, $class;
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
sub start {
|
||||
my ($self) = @_;
|
||||
open2 ($self->{child_out}, $self->{child_in}, @{$self->{cmd}});
|
||||
}
|
||||
|
||||
sub do_line {
|
||||
my ($self, $line) = @_;
|
||||
my ($in, $out) = ($self->{child_in}, $self->{child_out});
|
||||
|
||||
$line =~ s/\s+/ /g;
|
||||
print $in encode ('UTF-8', $line), "\n";
|
||||
$in->flush ();
|
||||
|
||||
my $ret = decode ('UTF-8', scalar <$out>);
|
||||
chomp $ret;
|
||||
|
||||
$self->{num_done}++;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub num_done { shift->{num_done} }
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user