Idiomatic PHP client for Cloud Natural Language.
NOTE: This repository is part of Google Cloud PHP. Any support requests, bug reports, or development contributions should be directed to that project.
Provides natural language understanding technologies to developers, including sentiment analysis, entity analysis, entity sentiment analysis, content classification, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.
To begin, install the preferred dependency manager for PHP, Composer.
Now to install just this component:
$ composer require google/cloud-language
Or to install the entire suite of components at once:
$ composer require google/cloud
Please see our Authentication guide for more information on authenticating your client. Once authenticated, you'll be ready to start making requests.
require 'vendor/autoload.php';
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";
}
This component is considered beta. As such, it should be expected to be mostly stable and we're working towards a release candidate. We will address issues and requests with a higher priority.
- Understand the official documentation.
- Take a look at in-depth usage samples.