mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
5e2731619c
server build probably broken
38 lines
763 B
Perl
38 lines
763 B
Perl
package LMClient;
|
|
|
|
use IO::Socket;
|
|
|
|
sub new {
|
|
my ($class, $cstr) = @_;
|
|
my $self = {};
|
|
$cstr =~ s/^!//;
|
|
my ($host, $port) = split /\:/, $cstr;
|
|
die "Please specify connection string as host:port" unless ($host && $port);
|
|
|
|
$self->{'SOCK'} = new IO::Socket::INET(
|
|
PeerAddr => $host,
|
|
PeerPort => $port,
|
|
Proto => 'tcp') or die "Couldn't create connection to $host:$port -- is memcached running?\n";
|
|
|
|
bless $self, $class;
|
|
return $self;
|
|
}
|
|
|
|
sub word_prob {
|
|
my ($self, $word, $context) = @_;
|
|
my @cwords = reverse split /\s+/, $context;
|
|
my $qstr = "prob $word @cwords";
|
|
my $s = $self->{'SOCK'};
|
|
print $s "$qstr\r\n";
|
|
my $r = <$s>;
|
|
my $x= unpack "f", $r;
|
|
return $x;
|
|
}
|
|
|
|
sub close {
|
|
my ($self) = @_;
|
|
close $self->{'SOCK'};
|
|
}
|
|
|
|
1;
|