Example
// Description: Preformator 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 the url for information extraction and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
curl_easy_setopt(curl, CURLOPT_URL, "http://api.intellexer.com/parse?apikey=YourAPIKey&url=http://www.euronews.com/2012/01/02/ailing-mubarak-back-in-court/&useCache=false");
// 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() << " ";
const Json::Value lang = root["lang"];
std::cout << "\nDocument language: " << lang.asString();
const Json::Value text = root["text"];
std::cout << "\nDocument plain text:\n" << text.asString();
}
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 language: English
Document plain text:
Log in
Please enter your login details
or Join the euronews community
17/08/2015
Breaking News
Turkey: PM Ahmet Davutoğlu says he will return the mandate to form a new government to President Erdoğan if necessary
Turkey: PM Ahmet Davutoğlu says the head of Nationalist MHP did not find the idea of a coalition with AKP suitable and would not vote in favour of an early election
Magnitude 4.0 earthquake hits near Piedmont, California, outside San Francisco
Turkey's Asli Cakir-Alptekin stripped of 2012 Olympic 1,500 metres gold medal for doping
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