| Current Path : /home/smartconb/www/armencom33/acv2026/includes/ |
| Current File : /home/smartconb/www/armencom33/acv2026/includes/function.google.api.inc.php |
<?php
/**
* User: zaven
* Date: 05.09.2018
* Time: 00:55
* Project: speech
**/
require(APPLICATION_BASE . '/vendor/php/autoload.php');
use Google\Cloud\Language\LanguageClient;
use Google\Cloud\Storage\StorageClient;
function analyze_sentiment($text, $projectId = null)
{
//if (is_null($projectId))
//$projectId = Config::get()->getMember('googleProjectId');
$language = new LanguageClient([
'keyFilePath' => Config::get()->getMember('googleAPIKeyFile'),
]);
// Call the analyzeSentiment function
$annotation = $language->analyzeSentiment($text);
// Print document and sentence sentiment information
$sentiment = $annotation->sentiment();
return $sentiment;
/*
printf('Document Sentiment:' . PHP_EOL);
printf(' Magnitude: %s' . PHP_EOL, $sentiment['magnitude']);
printf(' Score: %s' . PHP_EOL, $sentiment['score']);
printf(PHP_EOL);
foreach ($annotation->sentences() as $sentence) {
printf('Sentence: %s' . PHP_EOL, $sentence['text']['content']);
printf('Sentence Sentiment:' . PHP_EOL);
printf(' Magnitude: %s' . PHP_EOL, $sentence['sentiment']['magnitude']);
printf(' Score: %s' . PHP_EOL, $sentence['sentiment']['score']);
printf(PHP_EOL);
}
*/
}
function list_objects($bucketName)
{
$resultArray = array();
$storage = new StorageClient([
'keyFilePath' => Config::get()->getMember('googleAPIKeyFile'),
]);
$bucket = $storage->bucket($bucketName);
foreach ($bucket->objects() as $object) {
$resultArray[] = $object->name();
}
if (count($resultArray)==0)
return false;
return $resultArray;
}
function list_objects_with_prefix($bucketName, $prefix)
{
$resultArray = array();
$storage = new StorageClient([
'keyFilePath' => Config::get()->getMember('googleAPIKeyFile'),
]);
$bucket = $storage->bucket($bucketName);
$options = ['prefix' => $prefix];
foreach ($bucket->objects($options) as $object) {
$resultArray[] = $object->name();
}
if (count($resultArray)==0)
return false;
return $resultArray;
}
function stream_object($bucketName, $objectName)
{
$storage = new StorageClient([
'keyFilePath' => Config::get()->getMember('googleAPIKeyFile'),
]);
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
$stream = $object->downloadAsStream();
return $stream->getContents();
}