forked from rosette-api/php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64_input.php
More file actions
32 lines (28 loc) · 1.15 KB
/
Copy pathbase64_input.php
File metadata and controls
32 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Example code to call Rosette API to get entities from a piece of text.
**/
require_once dirname(__FILE__) . '/vendor/autoload.php';
use rosette\api\Api;
use rosette\api\DocumentParameters;
use rosette\api\RosetteConstants;
use rosette\api\RosetteException;
$options = getopt(null, array('key:', 'url::'));
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
exit();
}
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
$params = new DocumentParameters();
$entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS";
// There are two ways to process a base65 encoded string
$content = $params->loadDocumentString(base64_encode($entities_text_data), RosetteConstants::$DataFormat['UNSPECIFIED']);
// or
// $params->set('content', $entities_text_data);
// $params->contentType = RosetteConstants::$DataFormat['UNSPECIFIED'];
try {
$result = $api->entities($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
}