Example
# Description: Comparator 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;
# returned data from Intellexer API
my $results = "";
# create connection to the Comparator API service
my $ua = LWP::UserAgent->new or die "Cannot create connection!";
# set the URL for GET request, specify comparison urls and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
my $api_url = "http://api.intellexer.com/compareUrls?apikey=YourAPIKey&url1=http://www.infoplease.com/biography/var/barackobama.html&url2=http://millercenter.org/president/biography/obama-life-in-brief&useCache=false";
my $req = HTTP::Request->new(GET => $api_url);
# 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 "Proximity between\n";
print $json_results->{'document1'}->{'title'}, " and ", $json_results->{'document2'}->{'title'}, " is ", $json_results->{'proximity'};
}
else
{
print "HTTP POST error code: ", $resp->code, "\t", "HTTP POST error message: ", $resp->message, "\n";
}
Output
Proximity between
barackobama.html.html and obama-life-in-brief.html is 0.661107356684931