PHP Class Google\Cloud\NaturalLanguage\Annotation

This class is created internally by {@see \Google\Cloud\NaturalLanguage\NaturalLanguageClient} and is used to represent various document analyzation results. It should not be instantiated externally. Annotations are returned by {@see \Google\Cloud\NaturalLanguage\NaturalLanguageClient::analyzeEntities()}, {@see \Google\Cloud\NaturalLanguage\NaturalLanguageClient::analyzeSentiment()}, {@see \Google\Cloud\NaturalLanguage\NaturalLanguageClient::analyzeSyntax()} and {@see \Google\Cloud\NaturalLanguage\NaturalLanguageClient::annotateText()}.
Inheritance: use trait Google\Cloud\CallTrait
Afficher le fichier Open project: GoogleCloudPlatform/gcloud-php

Méthodes publiques

Méthode Description
__construct ( array $info = [] ) Create an annotation.
entitiesByType ( $type ) : array | null Returns an array of entities filtered by the given type.
info ( ) : array Returns the full response from the API.
sentiment ( ) : array | null Returns the sentiment of the document.
tokensByLabel ( $label ) : array | null Returns an array of tokens filtered by the given label.
tokensByTag ( $tag ) : array | null Returns an array of tokens filtered by the given tag.

Private Methods

Méthode Description
filter ( array $items, array $path, string $type ) : array | null Filters an array of items based on the provided type.

Method Details

__construct() public méthode

Create an annotation.
public __construct ( array $info = [] )
$info array [optional] The annotation's metadata.

entitiesByType() public méthode

Example: $entities = $annotation->entitiesByType('PERSON'); foreach ($entities as $entity) { echo $entity['name']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/Entity#type Entity types documentation
public entitiesByType ( $type ) : array | null
Résultat array | null

info() public méthode

Example: $info = $annotation->info();
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#response-body Annotate Text documentation
public info ( ) : array
Résultat array

sentiment() public méthode

Example: $sentiment = $annotation->sentiment(); if ($sentiment['score'] > 0) { echo 'This is a positive message.'; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/Sentiment Sentiment type documentation
public sentiment ( ) : array | null
Résultat array | null

tokensByLabel() public méthode

Example: $tokens = $annotation->tokensByLabel('P'); foreach ($tokens as $token) { echo $token['lemma']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#label Token labels documentation
public tokensByLabel ( $label ) : array | null
Résultat array | null

tokensByTag() public méthode

Example: $tokens = $annotation->tokensByTag('NOUN'); foreach ($tokens as $token) { echo $token['lemma']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#tag Token tags documentation
public tokensByTag ( $tag ) : array | null
Résultat array | null