function __construct($apiKey)
 {
     $this->apiKey = TextRazorSettings::getApiKey();
     $this->endPoint = TextRazorSettings::getEndPoint();
     $this->secureEndPoint = TextRazorSettings::getSecureEndpoint();
     $this->enableEncryption = TextRazorSettings::getEnableEncryption();
     $this->enableCompression = TextRazorSettings::getEnableCompression();
     if (isset($apiKey)) {
         $this->apiKey = $apiKey;
     }
     if (!is_string($this->apiKey)) {
         throw new Exception('TextRazor Error: Invalid API key');
     }
     if (!function_exists('curl_version')) {
         throw new Exception('TextRazor Error: TextRazor requires cURL support to be enabled on your PHP installation');
     }
 }
Exemple #2
0
<?php

require_once 'TextRazor.php';
TextRazorSettings::setApiKey("YOUR_API_KEY_HERE");
function testAnalysis()
{
    $textrazor = new TextRazor();
    $textrazor->addExtractor('entities');
    $textrazor->addExtractor('words');
    $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/latitude");
    $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/longitude");
    $text = 'LONDON - Barclays misled shareholders and the public about one of the biggest investments in the banks history, a BBC Panorama investigation has found.';
    $response = $textrazor->analyze($text);
    if (isset($response['response']['entities'])) {
        foreach ($response['response']['entities'] as $entity) {
            print "Entity ID: " . $entity['entityId'];
            $entity_data = $entity['data'];
            if (!is_null($entity_data)) {
                print PHP_EOL;
                print "Entity Latitude: " . $entity_data["fbase:/location/location/geolocation>/location/geocode/latitude"][0];
                print PHP_EOL;
                print "Entity Longitude: " . $entity_data["fbase:/location/location/geolocation>/location/geocode/longitude"][0];
            }
            print PHP_EOL;
        }
    }
}
function testClassifier()
{
    $textrazorClassifier = new ClassifierManager();
    $classifierId = 'test_cats_php';