Lingua-NATools

 view release on metacpan or  search on metacpan

lib/Lingua/NATools/Client.pm  view on Meta::CPAN

  use Lingua::NATools::Client;

  $client = Lingua::NATools::Client->new();

=head1 DESCRIPTION

Lingua::NATools::Client is a simple query API to talk with NAT copora Objects.
It can use a client-server approach (See nat-server) or directly with
local access to the filesystem.

=head1 Methods

This module includes functions to query NATools Objects. To query you
must first create a client object with the new method.

=head2 new

The new object receives an hash with configuration parameters, and
creates a client object. For instance,

  $client = Lingua::NATools::Client->new( Local => "/opt/corpora/foo" );

Known options are:


=over 4

=item PeerAddr

The IP address where the server is running on. Defaults to 127.0.0.1.

=item PeerPort

The port to be used in the connection. Defaults to 4000.

=item Local

A local directory with a NATools object. Note than not all methods
support local corpora.

=item LocalDumper

A local Data::Dumper object with a NATools PTD. Note than not all
methods support local NATools PTDs.

If the LocalDumper value is a reference to an array it is supposed to
contain two positions, with both dictionary filenames. If its value is
a string, it is supposed to be the filename with BOTH dictionaries
included.

=back

=cut

sub new {
  my $class = shift;
  my $self = { PeerAddr => '127.0.0.1',
               PeerPort => '4000',
               Proto    => 'tcp' };

  $self = bless {%$self, @_} => $class;

  $self->{local} = $self->{Local} if (exists($self->{Local}));
  $self->{localDumper} = $self->{LocalDumper} if (exists($self->{LocalDumper}));

  if (exists($self->{local})) {
    Lingua::NATools::corpus_info_open($self->{local});
		$self->{localcfg} = Lingua::NATools->load($self->{local})->{conf};
  }

  if (exists($self->{localDumper})) {
    our ($DIC1, $DIC2);

    if (ref($self->{localDumper}) eq "ARRAY") {

      die "File not found." unless -f $self->{localDumper}[0];
      $self->{d1} = do $self->{localDumper}[0];

      die "File not found." unless -f $self->{localDumper}[1];
      $self->{d2} = do $self->{localDumper}[1];

    } else {

      die "File not found." unless -f $self->{localDumper};

      do $self->{localDumper};

      $self->{d1} = $DIC1;
      $self->{d2} = $DIC2;
    }
  }

  if ($self->{crp}) {
    $self->set_corpus($self->{crp});
    delete($self->{crp});
  }

  return $self;
}

=head2 iterate

This method is used to iterate through a probabilistic translation
dictionary. Pass a function reference to handle each dictionary entry.
This function will be called with a flattened hash with keywords
C<word>, C<trans> and C<count>.

Use as first argument an hash reference to configure the method
behaviour. For instance:

  $client -> iterate( {Language => 'source'},
                      sub {
                        my %param = @_;
                        print "$param{word}\n";
                      });

=cut

sub iterate {
  local $/ = "\n";
  my $self = shift;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.416 second using v1.00-cache-2.02-grep-82fe00e-cpan-dad7e4baca0 )