Example

Example

# Description: SpellChecker API usage example.
# Copyright: (C) 2015 EffectiveSoft Ltd. All Rights Reserved.
# Technical support: technical-support@effective-soft.com
# This example requires LWP and JSON libraries.


use JSON;
use LWP::UserAgent;
require HTTP::Request;


# sample text
my $text = "EuropeanUnion leaders need to be bolder in how they tackle the eurozone crisis, reduce budget deficets and encourage growt, Prime Minister David Cameron said today.";

# returned data from Intellexer API
my $results = "";

# create connection to the SpellChecker API service
my $ua = LWP::UserAgent->new or die "Cannot create connection!";
# set the URL with parameters for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
my $api_url = "http://api.intellexer.com/checkTextSpelling?apikey=YourAPIKey&language=ENGLISH&errorTune=2&errorBound=3&minProbabilityTune=2&minProbabilityWeight=30";
my $req = HTTP::Request->new(POST => $api_url);
$req->header('content-type' => 'application/octet-stream');
$req->content($text);
# perform the request
my $resp = $ua->request($req);
# error checking
if ($resp->is_success) 
{
	$results = $resp->decoded_content;
	# parse JSON results
	my $json_results = decode_json($results);
	# print source and processed sentences
	my @src_sent = @{$json_results->{'sourceSentences'}};
	my @proc_sent = @{$json_results->{'processedSentences'}};
	my $size = @src_sent;
	for (my $i = 0; $i < $size; $i++)
	{
		print "Source:\t", $src_sent[$i], "\n";
		print "Corrected:\t", $proc_sent[$i], "\n";
	}
	# print list of corrections
	print "\nList of corrections:\n";
	my @corrections = @{$json_results->{'corrections'}};
	foreach my $corr (@corrections)
	{
		print "\t", $corr->{"v"}[0]->{"t"}, "\n";
	}
}
else 
{
	print "HTTP POST error code: ", $resp->code, "\t", "HTTP POST error message: ", $resp->message, "\n";
}

Output

Source:	EuropeanUnion leaders need to be bolder in how they tackle the eurozone crisis , reduce budget deficets and encourage growt , Prime Minister David Cameron said today . 
Corrected:	European Union leaders need to be bolder in how they tackle the eurozone crisis, reduce budget deficits and encourage growth, Prime Minister David Cameron said today.

List of corrections:
	European Union
	deficits
	growth