PHP code example of google / cloud-natural-language
1. Go to this page and download the library: Download google/cloud-natural-language library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
google / cloud-natural-language example snippets
use Google\Cloud\Language\LanguageClient;
$language = new LanguageClient();
// Analyze a sentence.
$annotation = $language->annotateText('Greetings from Michigan!');
// Check the sentiment.
if ($annotation->sentiment() > 0) {
echo "This is a positive message.\n";
}
// Detect entities.
$entities = $annotation->entitiesByType('LOCATION');
foreach ($entities as $entity) {
echo $entity['name'] . "\n";
}
// Parse the syntax.
$tokens = $annotation->tokensByTag('NOUN');
foreach ($tokens as $token) {
echo $token['text']['content'] . "\n";
}