Cloud Natural Language Client - Class LanguageClient (0.32.4)

Reference documentation and code samples for the Cloud Natural Language Client class LanguageClient.

Google Cloud Natural Language provides natural language understanding technologies to developers, including sentiment analysis, entity recognition, and syntax analysis. Currently only English, Spanish, and Japanese textual context are supported. Find more information at the Google Cloud Natural Language docs.

Example:

use Google\Cloud\Language\LanguageClient;

$language = new LanguageClient();

Namespace

Google \ Cloud \ Language

Methods

__construct

Create a Language client.

Note that when creating a LanguageClient instance, setting $config.projectId is not supported. To switch between projects, you must provide credentials with access to the project.

Parameters
Name Description
config array

Configuration Options.

↳ apiEndpoint string

A hostname with optional port to use in place of the service's default endpoint.

↳ authCache CacheItemPoolInterface

A cache for storing access tokens. Defaults to a simple in memory implementation.

↳ authCacheOptions array

Cache configuration options.

↳ authHttpHandler callable

A handler used to deliver Psr7 requests specifically for authentication.

↳ credentialsFetcher FetchAuthTokenInterface

A credentials fetcher instance.

↳ httpHandler callable

A handler used to deliver Psr7 requests. Only valid for requests sent over REST.

↳ keyFile array

The contents of the service account credentials .json file retrieved from the Google Developer's Console. Ex: json_decode(file_get_contents($path), true).

↳ keyFilePath string

The full path to your service account credentials .json file retrieved from the Google Developers Console.

↳ requestTimeout float

Seconds to wait before timing out the request. Defaults to 0 with REST and 60 with gRPC.

↳ retries int

Number of retries for a failed request. Defaults to 3.

↳ scopes array

Scopes to be used for the request.

↳ quotaProject string

Specifies a user project to bill for access charges associated with the request.

analyzeEntities

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

↳ encodingType string

The text encoding type used by the API to calculate offsets. Acceptable values are "NONE", "UTF8", "UTF16" and "UTF32". Defaults to "UTF8". Please note the following behaviors for the encoding type setting: "NONE" will return a value of "-1" for offsets. "UTF8" will return byte offsets. "UTF16" will return code unit offsets. "UTF32" will return unicode character offsets.

Returns
Type Description
Google\Cloud\Language\Annotation

analyzeSentiment

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

↳ encodingType string

The text encoding type used by the API to calculate offsets. Acceptable values are "NONE", "UTF8", "UTF16" and "UTF32". Defaults to "UTF8". Please note the following behaviors for the encoding type setting: "NONE" will return a value of "-1" for offsets. "UTF8" will return byte offsets. "UTF16" will return code unit offsets. "UTF32" will return unicode character offsets.

Returns
Type Description
Google\Cloud\Language\Annotation

analyzeEntitySentiment

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

↳ encodingType string

The text encoding type used by the API to calculate offsets. Acceptable values are "NONE", "UTF8", "UTF16" and "UTF32". Defaults to "UTF8". Please note the following behaviors for the encoding type setting: "NONE" will return a value of "-1" for offsets. "UTF8" will return byte offsets. "UTF16" will return code unit offsets. "UTF32" will return unicode character offsets.

Returns
Type Description
Google\Cloud\Language\Annotation

analyzeSyntax

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

↳ encodingType string

The text encoding type used by the API to calculate offsets. Acceptable values are "NONE", "UTF8", "UTF16" and "UTF32". Defaults to "UTF8". Please note the following behaviors for the encoding type setting: "NONE" will return a value of "-1" for offsets. "UTF8" will return byte offsets. "UTF16" will return code unit offsets. "UTF32" will return unicode character offsets.

Returns
Type Description
Google\Cloud\Language\Annotation

classifyText

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

Returns
Type Description
Google\Cloud\Language\Annotation

annotateText

Parameters
Name Description
content string|Google\Cloud\Storage\StorageObject

The content to analyze. May be either a string of UTF-8 encoded content, a URI pointing to a Google Cloud Storage object in the format of gs://{bucket-name}/{object-name} or a Google\Cloud\Storage\StorageObject.

options array

Configuration options.

↳ detectGcsUri bool

When providing $content as a string, this flag determines whether or not to attempt to detect if the string represents a Google Cloud Storage URI in the format of gs://{bucket-name}/{object-name}. Defaults to true.

↳ features array

Features to apply to the request. Valid values are syntax, sentiment, entities, entitySentiment, and classify. If no features are provided the request will run with all features enabled.

↳ type string

The document type. Acceptable values are PLAIN_TEXT or HTML. Defaults to "PLAIN_TEXT".

↳ language string

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.

↳ encodingType string

The text encoding type used by the API to calculate offsets. Acceptable values are "NONE", "UTF8", "UTF16" and "UTF32". Defaults to "UTF8". Please note the following behaviors for the encoding type setting: "NONE" will return a value of "-1" for offsets. "UTF8" will return byte offsets. "UTF16" will return code unit offsets. "UTF32" will return unicode character offsets.

Returns
Type Description
Google\Cloud\Language\Annotation

Constants

VERSION

Value: '0.32.4'

FULL_CONTROL_SCOPE

Value: 'https://www.googleapis.com/auth/cloud-platform'