Example

Example

// Description: Multi-Document 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;
}

// print related facts tree
void printTree(Json::Value node, int height)
{
	for(unsigned int i = 0; i < height; ++i) std::cout << "\t";
	std::cout << node["text"].asString() << "\n";
	node = node["children"];
	height++;
	for (unsigned int j = 0; j < node.size(); ++j)
	{
		printTree(node[j], height);
	}
}

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

	// list of urls for information extraction
	char pszUrls[] = "[\"http://www.infoplease.com/biography/var/barackobama.html\",\
		\"http://millercenter.org/president/biography/obama-life-in-brief\"]";

	// 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;
	}
	struct curl_slist *headerlist = NULL;
	if(curl) 
	{
		// set the URL for POST 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/multiUrlSummary?apikey=YourAPIKey&summaryRestriction=10&returnedTopicsCount=1&relatedFactsRequest=\"Obama\"&maxRelatedFactsConcepts=20&maxRelatedFactsSentences=5");
		// 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);
		// specify the POST data
		headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, pszUrls);
		// 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 multi-document summary
				const Json::Value summary = root["items"];
				std::cout << "Multi-Document summary: \n";
				for (unsigned int j = 0; j < summary.size(); ++j)
					std::cout << summary[j]["text"].asString() << "\n";
				// print facts related to the user query
				printTree(root["relatedFactsTree"], 0);

			}
			else
			{
				std::cerr << "JSON parsing error\n";
				return EXIT_FAILURE;
			}
		}
		//cleanup
		curl_easy_cleanup(curl);
	}
	//global cleanup
	curl_global_cleanup();
	return 0;
}

Output

Multi-Document summary: 
Barack Obama - Read this biography of Barack Obama, the 44th president of the United States and the winner of the 2009 Nobel Peace Prize.
The Miller Center is able to work to expand understanding of the presidency, policy, and political history only thanks to contributions from groups and individuals who support our mission.
Barack Obama was inaugurated as the 44th President of the United States-becoming the first African American to serve in that office-on January 20, 2009.
Leaving the state to attend college, he earned degrees from Columbia University and Harvard Law School.
Obama worked as a community organizer in Chicago, where he met and married Michelle LaVaughn Robinson in 1992.
When President Obama took office, he faced very significant challenges.
The economy was officially in a recession, and the outgoing administration of George W. Bush had begun to implement a controversial "bail-out" package to try to help struggling financial institutions.
Still the President spent significant time and political effort negotiating, for the most part unsuccessfully, with Congressional Republicans about taxes, budgets, and the deficit.
Although the initial impact of sequestration was limited, Obama warned about its long-term effects on the economy.
Agreement between the President and Congressional Republicans to craft a budget plan to end sequestration seemed unlikely to materialize quickly.

Related Facts
	miller center
		The Miller Center is able to work to expand understanding of the presidency, policy, and political history only thanks to contributions from groups and individuals who support our mission.
	united state
		In foreign affairs, the United States still had troops deployed in Iraq and Afghanistan, and warfare had broken out between Israel and Hamas in the Gaza Strip, illustrating the ongoing instability of the Middle East.
	george bush
		The economy was officially in a recession, and the outgoing administration of George W. Bush had begun to implement a controversial "bail-out" package to try to help struggling financial institutions.
	state senate
		Obama was elected to the Illinois state senate in 1996 and served there for eight years.
	keynote speech
		The title of the latter book was also the title of his 2004 keynote speech, and both books won Grammys for best spoken word album.
	democratic convention
		He named Delaware senator Joe Biden to be his running mate at the Democratic Convention that August, and they defeated Republican nominees John McCain and Sarah Palin in the November general election.
	foreign policy
		Biden was widely considered a smart pick for the experience and foreign policy expertise he brought to the ticket.
	bringing peace
		His 2008 Grammy for The Audacity of Hope beat books by two former presidents: Bill Clinton 's Giving: How Each of Us Can Change the World and Jimmy Carter 's Sunday Mornings in Plains: Bringing Peace to a Changing World .
	congressional republican
		Still the President spent significant time and political effort negotiating, for the most part unsuccessfully, with Congressional Republicans about taxes, budgets, and the deficit.
		Agreement between the President and Congressional Republicans to craft a budget plan to end sequestration seemed unlikely to materialize quickly.
	constitutional law
		He also taught constitutional law for 12 years at the University of Chicago.
	columbia university
		He earned an undergraduate degree from Columbia University in 1983 and a law degree from Harvard in 1991.
		Leaving the state to attend college, he earned degrees from Columbia University and Harvard Law School.
	immigration reform
		After winning reelection in 2012, Obama began his second term focused on immigration reform and gun control.
	former lady
		Obama ran for president in 2008, defeating a Democratic primary field that included New York Sen. Hillary Clinton , the former First Lady.
	campaign trail
		Although previously opponents for the Democratic nomination, Senators Obama and Biden had a healthy friendship and respect on the campaign trail.
	significant challenge
		When President Obama took office, he faced very significant challenges.
	long-term effect
		Although the initial impact of sequestration was limited, Obama warned about its long-term effects on the economy.
	international diplomacy
		Obama was awarded the Nobel Peace Prize in 2009, for "his extraordinary efforts to strengthen international diplomacy and cooperation between peoples."
	community organizer
		Obama worked as a community organizer in Chicago, where he met and married Michelle LaVaughn Robinson in 1992.
	barack obama
		Barack Obama has spoken often of his multicultural background: his father was from Kenya, his mother from Kansas, and they met at the University of Hawaii.
		Barack Obama shot to national fame after delivering a stirring keynote speech in support of John Kerry at the 2004 Democratic national convention.
		Barack Obama published the personal memoir Dreams from My Father in 1995, and published a second book, The Audacity of Hope , in 2006.
		Barack Obama - Read this biography of Barack Obama, the 44th president of the United States and the winner of the 2009 Nobel Peace Prize.
		Barack Obama was inaugurated as the 44th President of the United States-becoming the first African American to serve in that office-on January 20, 2009.
	barnhill galland
		He then joined the Chicago law firm of Miner, Barnhill & Galland, which specialized in civil rights legislation.