PHP Class Google\Cloud\NaturalLanguage\NaturalLanguageClient

Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $language = $cloud->naturalLanguage(); NaturalLanguage can be instantiated directly. use Google\Cloud\NaturalLanguage\NaturalLanguageClient; $language = new NaturalLanguageClient();
Inheritance: use trait Google\Cloud\ClientTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Protected Properties

Property Type Description
$connection Google\Cloud\NaturalLanguage\Connection\ConnectionInterface

Public Methods

Method Description
__construct ( array $config = [] ) Create a NaturalLanguage client.
analyzeEntities ( string | StorageObject $content, array $options = [] ) : Annotation Finds named entities (currently finds proper names) in the text, entity types, salience, mentions for each entity, and other properties in the document.
analyzeSentiment ( string | StorageObject $content, array $options = [] ) : Annotation Analyzes the sentiment of the provided document.
analyzeSyntax ( string | StorageObject $content, array $options = [] ) : Annotation Analyzes the document and provides a full set of text annotations.
annotateText ( string | StorageObject $content, array $options = [] ) : Annotation Analyzes the document and provides a full set of text annotations, including semantic, syntactic, and sentiment information.

Private Methods

Method Description
formatRequest ( string | StorageObject $content, array $options ) : array Formats the request for the API.
normalizeFeatures ( array $features ) : array Configures features in a way the API expects.

Method Details

__construct() public method

Create a NaturalLanguage client.
public __construct ( array $config = [] )
$config array [optional] { Configuration Options. @type string $projectId The project ID from the Google Developer's Console. @type CacheItemPoolInterface $authCache A cache for storing access tokens. **Defaults to** a simple in memory implementation. @type array $authCacheOptions Cache configuration options. @type callable $authHttpHandler A handler used to deliver Psr7 requests specifically for authentication. @type callable $httpHandler A handler used to deliver Psr7 requests. Only valid for requests sent over REST. @type string $keyFile The contents of the service account credentials .json file retrieved from the Google Developers Console. @type string $keyFilePath The full path to your service account credentials .json file retrieved from the Google Developers Console. @type int $retries Number of retries for a failed request. **Defaults to** `3`. @type array $scopes Scopes to be used for the request. }

analyzeEntities() public method

Example: $annotation = $language->analyzeEntities('Google Cloud Platform is a powerful tool.'); foreach ($annotation->entities() as $entity) { echo $entity['type']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeEntities Analyze Entities API documentation
public analyzeEntities ( string | StorageObject $content, array $options = [] ) : Annotation
$content string | Google\Cloud\Storage\StorageObject The content to analyze.
$options array [optional] { Configuration options. @type string $type The document type. Acceptable values are `PLAIN_TEXT` or `HTML`. **Defaults to** `"PLAIN_TEXT"`. @type string $language The language of the document. Both ISO (e.g., en, es) and BCP-47 (e.g., en-US, es-ES) language codes are accepted. Defaults to `"en"` (English). @type string $encodingType The text encoding type used by the API to calculate offsets. Acceptable values are `"NONE"`, `"UTF8"`, `"UTF16"` and `"UTF32"`. **Defaults to** `"UTF8"`. }
return Annotation

analyzeSentiment() public method

Example: $annotation = $language->analyzeSentiment('Google Cloud Platform is a powerful tool.'); $sentiment = $annotation->sentiment(); if ($sentiment['score'] > 0) { echo 'This is a positive message.'; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeSentiment Analyze Sentiment API documentation
public analyzeSentiment ( string | StorageObject $content, array $options = [] ) : Annotation
$content string | Google\Cloud\Storage\StorageObject The content to analyze.
$options array [optional] { Configuration options. @type string $type The document type. Acceptable values are `PLAIN_TEXT` or `HTML`. **Defaults to** `"PLAIN_TEXT"`. @type string $language The language of the document. Both ISO (e.g., en, es) and BCP-47 (e.g., en-US, es-ES) language codes are accepted. If no value is provided, the language will be detected by the service. @type string $encodingType The text encoding type used by the API to calculate offsets. Acceptable values are `"NONE"`, `"UTF8"`, `"UTF16"` and `"UTF32"`. **Defaults to** `"UTF8"`. }
return Annotation

analyzeSyntax() public method

Example: $annotation = $language->analyzeSyntax('Google Cloud Platform is a powerful tool.'); foreach ($annotation->sentences() as $sentence) { echo $sentence['text']['beginOffset']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeSyntax Analyze Syntax API documentation
public analyzeSyntax ( string | StorageObject $content, array $options = [] ) : Annotation
$content string | Google\Cloud\Storage\StorageObject The content to analyze.
$options array [optional] { Configuration options. @type string $type The document type. Acceptable values are `PLAIN_TEXT` or `HTML`. **Defaults to** `"PLAIN_TEXT"`. @type string $language The language of the document. Both ISO (e.g., en, es) and BCP-47 (e.g., en-US, es-ES) language codes are accepted. If no value is provided, the language will be detected by the service. @type string $encodingType The text encoding type used by the API to calculate offsets. Acceptable values are `"NONE"`, `"UTF8"`, `"UTF16"` and `"UTF32"`. **Defaults to** `"UTF8"`. }
return Annotation

annotateText() public method

Example: Annotate text with all features enabled. $annotation = $language->annotateText('Google Cloud Platform is a powerful tool.'); $sentiment = $annotation->sentiment(); echo $sentiment['magnitude']; Annotate text with syntax and sentiment features enabled. $annotation = $language->annotateText('Google Cloud Platform is a powerful tool.', [ 'features' => ['syntax', 'sentiment'] ]); foreach ($annotation->tokens() as $token) { echo $token['text']['beginOffset']; }
See also: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText Annotate Text API documentation
public annotateText ( string | StorageObject $content, array $options = [] ) : Annotation
$content string | Google\Cloud\Storage\StorageObject The content to annotate.
$options array [optional] { Configuration options. @type array $features Features to apply to the request. Valid values are `syntax`, `sentiment`, and `entities`. If no features are provided the request will run with all three enabled. @type string $type The document type. Acceptable values are `PLAIN_TEXT` or `HTML`. **Defaults to** `"PLAIN_TEXT"`. @type string $language The language of the document. Both ISO (e.g., en, es) and BCP-47 (e.g., en-US, es-ES) language codes are accepted. If no value is provided, the language will be detected by the service. @type string $encodingType The text encoding type used by the API to calculate offsets. Acceptable values are `"NONE"`, `"UTF8"`, `"UTF16"` and `"UTF32"`. **Defaults to** `"UTF8"`. }
return Annotation

Property Details

$connection protected_oe property

protected ConnectionInterface,Google\Cloud\NaturalLanguage\Connection $connection
return Google\Cloud\NaturalLanguage\Connection\ConnectionInterface