Net::Google::Spelling - simple OOP-ish interface to the Google SOAP API for spelling suggestions


Net-Google documentation Contained in the Net-Google distribution.

Index


Code Index:

NAME

Top

Net::Google::Spelling - simple OOP-ish interface to the Google SOAP API for spelling suggestions

SYNOPSIS

Top

 use Net::Google::Spelling;
 my $spelling = Net::Google::Spelling(\%args);

 $spelling->phrase("muntreal qweebec");
 print $spelling->suggest()."\n";

DESCRIPTION

Top

Provides a simple OOP-ish interface to the Google SOAP API for spelling suggestions.

This package is used by Net::Google.

PACKAGE METHODS

Top

$pkg = __PACKAGE__->new(\%args)

Valid arguments are :

The object constructor in Net::Google 0.53, and earlier, expected a GoogleSearchService object as its first argument followed by a hash reference of argument. Versions 0.6 and higher are backwards compatible.

Returns an object. Woot!

OBJECT METHODS

Top

$obj->key($string)

Get/set the Google API key for this object.

$obj->http_proxy($url)

Get/set the HTTP proxy for this object.

Returns a string.

$obj->phrase(@words)

Add one or more words to the phrase you want to spell-check.

If the first item in @words is empty, then any existing phrase data will be removed before the new data is added.

Returns a string. Returns undef if there was an error.

$obj->suggest()

Fetch the spelling suggestion from the Google servers.

Returns a string. Returns undef if there was an error.

$obj->queries_exhausted()

Returns true or false depending on whether or not the current in-memory session has exhausted the Google API 1000 query limit.

VERSION

Top

1.0

DATE

Top

$Date: 2006/01/12 03:37:31 $

AUTHOR

Top

Aaron Straup Cope

SEE ALSO

Top

Net::Google

LICENSE

Top

Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved.

This is free software, you may use it and distribute it under the same terms as Perl itself.


Net-Google documentation Contained in the Net-Google distribution.
{

use strict;

package Net::Google::Spelling;
use base qw (Net::Google::tool);

use Carp;

$Net::Google::Spelling::VERSION   = '1.0';

sub new {
  my $pkg = shift;

  my $self = {};
  bless $self,$pkg;

  if (! $self->init(@_)) {
    return undef;
  }

  return $self;
}

sub init {
  my $self    = shift;

  my $args = $self->SUPER::init("spelling",@_)
    || return 0;

  #

  if ($args->{'phrase'}) {
    defined($self->phrase( (ref($args->{'phrase'}) eq "ARRAY") ? @{$args->{'phrase'}} : $args->{'phrase'} )) || return 0;
  }
  
  return 1;
}

# Defined in Net::Google::tool

# Defined in Net::Google::tool

sub phrase {
  my $self  = shift;
  my @words = @_;

  if ((scalar(@words) > 1) && ($words[0] == "")) {
    $self->{'_phrase'} = [];
  }

  if (@words) {
    push @{$self->{'_phrase'}} , @words;
  }

  return join("",@{$self->{'_phrase'}});
}

sub suggest {
  my $self = shift;

  $self->_queries(1);

  return $self->{'_service'}->doSpellingSuggestion(
						   $self->key(),
						   $self->phrase(),
						  );
}

# Defined in Net::Google::tool

return 1;

}