Example

Example

# Description: Preformator 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 Preformator API service
my $ua = LWP::UserAgent->new or die "Cannot create connection!";
# set the URL for GET request, specify the url for information extraction and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
my $api_url = "http://api.intellexer.com/parse?apikey=YourAPIKey&url=http://www.euronews.com/2012/01/02/ailing-mubarak-back-in-court/&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 document information
	print "Document structure: ",  $json_results->{'structure'};
	my @topics = @{$json_results->{'topics'}};
	print "\nDocument topics: ";
	foreach my $topic ( @topics )
	{
		print "$topic ";
	}
	print "\nDocument language: ", $json_results->{'lang'};
	print "\nDocument plain text:\n", $json_results->{'text'};
}
else 
{
	print "HTTP POST error code: ", $resp->code, "\t", "HTTP POST error message: ", $resp->message, "\n";
}

Output

Document structure: NewsArticle
Document topics: Social.law 
Document language: English
Document plain text:
Log in
Please enter your login details
 or Join the euronews community
19/08/2015
Breaking News
ICC appeals court sends Kenya non-cooperation case back to trial chamber for review - Reuters
Blast in Northeastern Syria hits offices of Kurdish security agency, kills at least 10 - Monitor
 Twitter Google+ Reddit
02/01/12 14:07 CET
The former Egyptian president Hosni Mubarak has been back in court after a two month delay in his trial over the deaths of hundreds of anti-government protesters. The ousted leader, whose doctors claim is suffering from heart problems, arrived at the Cairo tribunal on a stretcher.
He is accused of corruption and complicity in the killings of opponents during the uprising against his rule.
A judge, who some lawyers called to be dismissed over doubts about his impartiality, has been retained. That has fuelled demonstrations outside the court by anti-Mubarak protesters.
Their anger has been heightened by the recent acquittal of five policemen on charges of killing five protesters during the revolt.
More about:
Latest world news
Wires > News
Latest programmes
Copyright � euronews 2015