-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlanguage.php
More file actions
28 lines (25 loc) · 859 Bytes
/
language.php
File metadata and controls
28 lines (25 loc) · 859 Bytes
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
<?php
/**
* Example code to call Analytics API to detect possible languages for a piece of text.
**/
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use rosette\api\Api;
use rosette\api\DocumentParameters;
use rosette\api\RosetteException;
$options = getopt('', array('key:', 'url::'));
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
exit();
}
$language_data = "Por favor Señorita, says the man.";
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
$params = new DocumentParameters();
$content = $language_data;
$params->set('content', $content);
$api->setCustomHeader('X-RosetteAPI-App', 'php-app');
try {
$result = $api->language($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
}