PHP Класс 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()}.
Наследование: use trait Google\Cloud\CallTrait
Показать файл Открыть проект

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
filter ( array $items, array $path, string $type ) : array | null Filters an array of items based on the provided type.

Описание методов

__construct() публичный Метод

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

entitiesByType() публичный Метод

Example: $entities = $annotation->entitiesByType('PERSON'); foreach ($entities as $entity) { echo $entity['name']; }
См. также: https://cloud.google.com/natural-language/reference/rest/v1beta1/Entity#type Entity types documentation
public entitiesByType ( $type ) : array | null
Результат array | null

info() публичный Метод

Example: $info = $annotation->info();
См. также: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#response-body Annotate Text documentation
public info ( ) : array
Результат array

sentiment() публичный Метод

Example: $sentiment = $annotation->sentiment(); if ($sentiment['score'] > 0) { echo 'This is a positive message.'; }
См. также: https://cloud.google.com/natural-language/reference/rest/v1beta1/Sentiment Sentiment type documentation
public sentiment ( ) : array | null
Результат array | null

tokensByLabel() публичный Метод

Example: $tokens = $annotation->tokensByLabel('P'); foreach ($tokens as $token) { echo $token['lemma']; }
См. также: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#label Token labels documentation
public tokensByLabel ( $label ) : array | null
Результат array | null

tokensByTag() публичный Метод

Example: $tokens = $annotation->tokensByTag('NOUN'); foreach ($tokens as $token) { echo $token['lemma']; }
См. также: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#tag Token tags documentation
public tokensByTag ( $tag ) : array | null
Результат array | null