Sentiment text with Reseta
<?php
//die('El silencio es Oro/The silence is Gold');
echo dirname(__FILE__) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/vendor/autoload.php';
use rosette\api\Api;
use rosette\api\DocumentParameters;
use rosette\api\RosetteException;
$options = getopt(null, array('key:', 'url::'));
$options['key']='XXX';
$options['url']='https://api.rosette.com/rest/v1/';
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
exit();
}
$sentiment_file_data = "no me gusta el alcohol";
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
$params = new DocumentParameters();
$params->set('language', 'spa');
$content = $sentiment_file_data;
$temp = tmpfile(); // write above html content to a temp file
fwrite($temp, $content);
$params->loadDocumentFile(stream_get_meta_data($temp)['uri']);
try {
$result = $api->sentiment($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
} finally {
fclose($temp); // clean up the temp file
}
Comentarios
Publicar un comentario