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 the libcurl and jsoncpp libraries.

#include <iostream>
#include "curl/curl.h"
#include "json/json.h"

using namespace std;

// libcurl write callback function
static int writer(char *data, size_t size, size_t nmemb,
				  std::string *writerData)
{
	if (writerData == NULL)
		return 0;
	writerData->append(data, size*nmemb);
	return size * nmemb;
}

int main(int argc, char* argv[])
{
	CURL *curl = NULL;
	CURLcode res;

	// returned data from Intellexer API
	std::string results;
	// libcurl connection initialization
	curl = curl_easy_init();
	if (curl == NULL)
	{
		std::cerr << "Failed to create CURL connection\n";
		return EXIT_FAILURE;
	}
	if(curl) 
	{
		// set the URL for GET request, specify url, summarization parameters and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
		curl_easy_setopt(curl, CURLOPT_URL, "http://api.intellexer.com/summarize?apikey=YourAPIKey&url=http://www.infoplease.com/biography/var/barackobama.html&summaryRestriction=7&returnedTopicsCount=1");
		// set option to the callback function
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
		// set option for writing received data
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &results);
		// perform the request
		res = curl_easy_perform(curl);
		// error checking
		if(res != CURLE_OK)
			std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << "\n";
		else
		{
			// parse JSON results
			Json::Value root;
			Json::Reader reader;
			bool isSuccess = reader.parse(results,	root, false);
			if (isSuccess)
			{
				// print document information
				const Json::Value structure = root["structure"];
				std::cout << "Document structure: " << structure.asString();
				const Json::Value topics = root["topics"];
				std::cout << "\nDocument topics: ";
				for (unsigned int i = 0; i < topics.size(); ++i)
					std::cout << topics[i].asString() << " ";
				// print document summary
				const Json::Value summary = root["items"];
				std::cout << "\nDocument summary: \n";
				for (unsigned int j = 0; j < summary.size(); ++j)
					std::cout << summary[j]["text"].asString() << "\n";
			}
			else
			{
				std::cerr << "JSON parsing error\n";
				return EXIT_FAILURE;
			}
		}
		//cleanup
		curl_easy_cleanup(curl);
	}
	//global cleanup
	curl_global_cleanup();
	return 0;
}

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 ...