Reference documentation and code samples for the Cloud Natural Language Client class Annotation.
Annotations represent the result of a request against the Google Cloud Natural Language API.
This class is created internally by Google\Cloud\Language\Google\Cloud\Language\LanguageClient and is used to represent various document analyzation results. It should not be instantiated externally.
Annotations are returned by Google\Cloud\Language\Google\Cloud\Language\LanguageClient::analyzeEntities(), Google\Cloud\Language\Google\Cloud\Language\LanguageClient::analyzeSentiment(), Google\Cloud\Language\Google\Cloud\Language\LanguageClient::analyzeEntitySentiment(), Google\Cloud\Language\Google\Cloud\Language\LanguageClient::analyzeSyntax() and Google\Cloud\Language\Google\Cloud\Language\LanguageClient::annotateText().
Example:
use Google\Cloud\Language\LanguageClient;
$language = new LanguageClient();
$annotation = $language->annotateText('Google Cloud Platform is a powerful tool.');
Methods
__construct
Create an annotation.
Parameter | |
---|---|
Name | Description |
info |
array
[optional] The annotation's metadata. |
info
Returns the full response from the API.
Example:
$info = $annotation->info();
Returns | |
---|---|
Type | Description |
array |
sentiment
Returns the sentiment of the document.
Example:
$sentiment = $annotation->sentiment();
if ($sentiment['score'] > 0) {
echo 'This is a positive message.';
}
Returns | |
---|---|
Type | Description |
array|null |
tokensByTag
Returns an array of tokens filtered by the given tag.
Example:
$tokens = $annotation->tokensByTag('NOUN');
foreach ($tokens as $token) {
echo $token['lemma'];
}
Parameter | |
---|---|
Name | Description |
tag |
mixed
|
Returns | |
---|---|
Type | Description |
array|null |
tokensByLabel
Returns an array of tokens filtered by the given label.
Example:
$tokens = $annotation->tokensByLabel('P');
foreach ($tokens as $token) {
echo $token['lemma'];
}
Parameter | |
---|---|
Name | Description |
label |
mixed
|
Returns | |
---|---|
Type | Description |
array|null |
entitiesByType
Returns an array of entities filtered by the given type.
Example:
$entities = $annotation->entitiesByType('PERSON');
foreach ($entities as $entity) {
echo $entity['name'];
}
Parameter | |
---|---|
Name | Description |
type |
mixed
|
Returns | |
---|---|
Type | Description |
array|null |