Intellexer-API

 view release on metacpan or  search on metacpan

lib/Intellexer/API.pm  view on Meta::CPAN

    );
}

sub parse($self, $url, %params){
    my $uri_obj = $self->_build_url(
        'parse?',
        'url'=> $url,
        %params,
        );
    return $self->_react( $ua->get($uri_obj) );
}

sub parseFileContent($self, $file){
    my $size = -s $file;
    my $uri_obj= $self->_build_url(
        'parseFileContent?',
        'filename' => path($file)->basename,
    );

    return $self->_react(
        $ua->post(
            $uri_obj,
            Content_Type => 'multipart/form-data',
            Content => [path($file)->basename => [$file,] ],
        )
    );
}

## Language Recognizer
sub recognizeLanguage($self, $text){
    my $uri_obj = $self->_build_url(
        'recognizeLanguage?',
    );

    return $self->_react(
        $ua->post(
            $uri_obj,
            Content => $text,
        )
    );
}

## SpellChecker
sub checkTextSpelling($self, $text, %params){
    my $uri_obj = $self->_build_url(
        'checkTextSpelling?',
        %params,
    );

    return $self->_react(
        $ua->post(
            $uri_obj,
            Content => $text,
        )
    );
}

## Support functions

# build a URI object with necessary form data
sub _build_url( $self, $endpoint, %form){
    my $url = URI->new( $self->{base}.$endpoint);
    $form{'apikey'} = $self->{api_key};
    $url->query_form(\%form);
    return $url->as_string;
    #return $url;
}

sub _react($self, $response){
    if ($response->is_success) {
        return $json->decode($response->decoded_content);
    }
    else {
        croak $response->status_line."\n".$response->content;
    }
}


1;

# ABSTRACT: Perl API client for the Intellexer, a webservice that, "enables developers to embed Intellexer semantics products using XML or JSON."

__END__


=head1 NAME

Intellexer::API - API client for Intellexer

Perl API client for  L<Intellexer|https://www.intellexer.com/>, a webservice that, "enables developers to embed Intellexer semantics products using XML or JSON."

=head1 SYNOPSIS

  my $api_key = q{...get this from intellexer.com};
  my $api = Intellexer::API->new($api_key);
  my $response = $api->checkTextSpelling(
      $sample_text,
      'language' => 'ENGLISH',
      'errorTune' => '2',
      'errorBound' => '3',
      'minProbabilityTune' => '2',
      'minProbabilityWeight' => '30',
      'separateLines' => 'true'
  );
  say $json->encode($response);

=head1 DESCRIPTION

An interface to the L<Intellexer|https://www.intellexer.com/> API. This module provides perl methods to all the methods available in the Intellexer API using the same names. This will make it easy for those who want to look for more documentation on ...

=head2 Methods

=head3 Topic Modeling

Automatically extract topics from text.

=head4 C<getTopicsFromUrl($url)>

Accepts a single argument that is a valid URL to a document or webpage.

    my $response = $api->getTopicsFromUrl( 'https://perldoc.perl.org/perlsub' );



( run in 2.440 seconds using v1.01-cache-2.11-cpan-524268b4103 )