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
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Public Methods

Method 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

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

Method Details

__construct() public method

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

entitiesByType() public method

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
return array | null

info() public method

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
return array

sentiment() public method

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
return array | null

tokensByLabel() public method

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
return array | null

tokensByTag() public method

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
return array | null