Example

Example

<?php

# Description: Clusterizer API usage example.
# Copyright: (C) 2016 EffectiveSoft Ltd. All Rights Reserved.
# Technical support: technical-support@effective-soft.com

header('Content-Type: text/plain');

$text = "Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs. ";

# ----------- FUNCTIONS -----------
# function for printing concept tree
function printTree($node, $height)
{
    for ($i = 0; $i < $height; $i++)
    {
        echo "\t";
    }
    echo $node['text'] . "\n";

    $children = $node['children'];
    $height++;
    foreach ($children as $child)
    {
        printTree($child, $height);
    }
}

# ----------- END FUNCTIONS -----------

# ----------- cURL -----------
# set the URL with parameters for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
$link = "http://api.intellexer.com/clusterizeText?apikey=YourAPIKey&conceptsRestriction=10&fullTextTrees=true";
$header = array('Content-type: application/octet-stream');

# curl connection initialization
$ch = curl_init();

#set cURL options
curl_setopt_array($ch, array(
    CURLOPT_URL => $link,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HEADER => false,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_POSTFIELDS => $text,
    CURLOPT_FOLLOWLOCATION => true
));

# perform the request
$results = curl_exec($ch);

# error checking
if (curl_errno($ch))
{
    echo 'CURL error: ' . curl_error($ch);
}
else
{
    # parse JSON results
    $json_results = json_decode($results, true);

    # print "Concept tree"
    echo 'Concept tree: ' . "\n";
    printTree($json_results['conceptTree'], 0);
}

curl_close($ch);
# ----------- END cURL -----------

Output

Concept tree: 

	programming
		computer programming
	executable computer program
	process
	computing problem
	original formulation