Example

Example

# Description: Summarizer 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 Summarizer API service
my $ua = LWP::UserAgent->new or die "Cannot create connection!";
# set the URL for GET request, specify url, summarization parameters and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
my $api_url = "http://api.intellexer.com/summarize?apikey=YourAPIKey&url=http://www.infoplease.com/biography/var/barackobama.html&summaryRestriction=7&returnedTopicsCount=2";
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 summary: \n";
	my @items = @{$json_results->{'items'}};
	foreach my $item ( @items )
	{
		print $item->{'text'}, "\n";
	}
}
else 
{
	print "HTTP POST error code: ", $resp->code, "\t", "HTTP POST error message: ", $resp->message, "\n";
}

Output

Document structure: NewsArticle
Document topics: Social.politics 
Document summary: 
Barack Obama is the 44th president of the United States and the first African-American president in American history.
Barack Obama was elected to the Illinois Senate in 1996, and then to the U.S. Senate in 2004, beating Republican candidate Alan Keyes .
Obama ran for president in 2008, defeating a Democratic primary field that included New York Sen. Hillary Clinton , the former First Lady.
Obama's Senate website described him as "the first African American president of the Harvard Law Review" and "the third African American since Reconstruction to be elected to the U.S. Senate."
Two other African-Americans were chosen by state senates to become U.S. Senators: Hiram Revels (1870-71, from Mississippi) and Blanche Bruce  (1875-81, also from
Barack Obama  - Read this biography of Barack Obama, the 44th president of the United States and the winner of the 2009 Nobel Peace Prize.
Cabinet Members Under President Barack Obama  - Cabinet Members Under President Barack Obama The following are the members of President Barack ...