Class v1beta2.LanguageServiceClient (6.5.0)

Provides text analysis operations such as sentiment analysis and entity recognition. v1beta2

Package

@google-cloud/language

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of LanguageServiceClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new LanguageServiceClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

languageServiceStub

languageServiceStub?: Promise<{
        [name: string]: Function;
    }>;

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

analyzeEntities(request, options)

analyzeEntities(request?: protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse,
        protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | undefined,
        {} | undefined
    ]>;

Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and other properties.

Parameters
Name Description
request IAnalyzeEntitiesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing AnalyzeEntitiesResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  The encoding type used by the API to calculate offsets.
   */
  // const encodingType = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callAnalyzeEntities() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.analyzeEntities(request);
    console.log(response);
  }

  callAnalyzeEntities();

analyzeEntities(request, options, callback)

analyzeEntities(request: protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeEntitiesRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeEntities(request, callback)

analyzeEntities(request: protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeEntitiesRequest
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeEntitySentiment(request, options)

analyzeEntitySentiment(request?: protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse,
        (protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | undefined),
        {} | undefined
    ]>;

Finds entities, similar to in the text and analyzes sentiment associated with each entity and its mentions.

Parameters
Name Description
request IAnalyzeEntitySentimentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse, (protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing AnalyzeEntitySentimentResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  The encoding type used by the API to calculate offsets.
   */
  // const encodingType = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callAnalyzeEntitySentiment() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.analyzeEntitySentiment(request);
    console.log(response);
  }

  callAnalyzeEntitySentiment();

analyzeEntitySentiment(request, options, callback)

analyzeEntitySentiment(request: protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeEntitySentimentRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeEntitySentiment(request, callback)

analyzeEntitySentiment(request: protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeEntitySentimentRequest
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeSentiment(request, options)

analyzeSentiment(request?: protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse,
        protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | undefined,
        {} | undefined
    ]>;

Analyzes the sentiment of the provided text.

Parameters
Name Description
request IAnalyzeSentimentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing AnalyzeSentimentResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  The encoding type used by the API to calculate sentence offsets for the
   *  sentence sentiment.
   */
  // const encodingType = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callAnalyzeSentiment() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.analyzeSentiment(request);
    console.log(response);
  }

  callAnalyzeSentiment();

analyzeSentiment(request, options, callback)

analyzeSentiment(request: protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeSentimentRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeSentiment(request, callback)

analyzeSentiment(request: protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeSentimentRequest
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeSentimentResponse, protos.google.cloud.language.v1beta2.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeSyntax(request, options)

analyzeSyntax(request?: protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse,
        protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | undefined,
        {} | undefined
    ]>;

Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.

Parameters
Name Description
request IAnalyzeSyntaxRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing AnalyzeSyntaxResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  The encoding type used by the API to calculate offsets.
   */
  // const encodingType = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callAnalyzeSyntax() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.analyzeSyntax(request);
    console.log(response);
  }

  callAnalyzeSyntax();

analyzeSyntax(request, options, callback)

analyzeSyntax(request: protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeSyntaxRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

analyzeSyntax(request, callback)

analyzeSyntax(request: protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest, callback: Callback<protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnalyzeSyntaxRequest
callback Callback<protos.google.cloud.language.v1beta2.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1beta2.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

annotateText(request, options)

annotateText(request?: protos.google.cloud.language.v1beta2.IAnnotateTextRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IAnnotateTextResponse,
        protos.google.cloud.language.v1beta2.IAnnotateTextRequest | undefined,
        {} | undefined
    ]>;

A convenience method that provides all syntax, sentiment, entity, and classification features in one call.

Parameters
Name Description
request IAnnotateTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IAnnotateTextResponse, protos.google.cloud.language.v1beta2.IAnnotateTextRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing AnnotateTextResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  Required. The enabled features.
   */
  // const features = {}
  /**
   *  The encoding type used by the API to calculate offsets.
   */
  // const encodingType = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callAnnotateText() {
    // Construct request
    const request = {
      document,
      features,
    };

    // Run request
    const response = await languageClient.annotateText(request);
    console.log(response);
  }

  callAnnotateText();

annotateText(request, options, callback)

annotateText(request: protos.google.cloud.language.v1beta2.IAnnotateTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IAnnotateTextResponse, protos.google.cloud.language.v1beta2.IAnnotateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnnotateTextRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IAnnotateTextResponse, protos.google.cloud.language.v1beta2.IAnnotateTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

annotateText(request, callback)

annotateText(request: protos.google.cloud.language.v1beta2.IAnnotateTextRequest, callback: Callback<protos.google.cloud.language.v1beta2.IAnnotateTextResponse, protos.google.cloud.language.v1beta2.IAnnotateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IAnnotateTextRequest
callback Callback<protos.google.cloud.language.v1beta2.IAnnotateTextResponse, protos.google.cloud.language.v1beta2.IAnnotateTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

classifyText(request, options)

classifyText(request?: protos.google.cloud.language.v1beta2.IClassifyTextRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IClassifyTextResponse,
        protos.google.cloud.language.v1beta2.IClassifyTextRequest | undefined,
        {} | undefined
    ]>;

Classifies a document into categories.

Parameters
Name Description
request IClassifyTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IClassifyTextResponse, protos.google.cloud.language.v1beta2.IClassifyTextRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing ClassifyTextResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}
  /**
   *  Model options to use for classification. Defaults to v1 options if not
   *  specified.
   */
  // const classificationModelOptions = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callClassifyText() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.classifyText(request);
    console.log(response);
  }

  callClassifyText();

classifyText(request, options, callback)

classifyText(request: protos.google.cloud.language.v1beta2.IClassifyTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IClassifyTextResponse, protos.google.cloud.language.v1beta2.IClassifyTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IClassifyTextRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IClassifyTextResponse, protos.google.cloud.language.v1beta2.IClassifyTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

classifyText(request, callback)

classifyText(request: protos.google.cloud.language.v1beta2.IClassifyTextRequest, callback: Callback<protos.google.cloud.language.v1beta2.IClassifyTextResponse, protos.google.cloud.language.v1beta2.IClassifyTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IClassifyTextRequest
callback Callback<protos.google.cloud.language.v1beta2.IClassifyTextResponse, protos.google.cloud.language.v1beta2.IClassifyTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
Type Description
Promise<void>

{Promise} A promise that resolves when the client is closed.

getProjectId()

getProjectId(): Promise<string>;
Returns
Type Description
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
Name Description
callback Callback<string, undefined, undefined>
Returns
Type Description
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
Type Description
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

moderateText(request, options)

moderateText(request?: protos.google.cloud.language.v1beta2.IModerateTextRequest, options?: CallOptions): Promise<[
        protos.google.cloud.language.v1beta2.IModerateTextResponse,
        protos.google.cloud.language.v1beta2.IModerateTextRequest | undefined,
        {} | undefined
    ]>;

Moderates a document for harmful and sensitive categories.

Parameters
Name Description
request IModerateTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.language.v1beta2.IModerateTextResponse, protos.google.cloud.language.v1beta2.IModerateTextRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing ModerateTextResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Input document.
   */
  // const document = {}

  // Imports the Language library
  const {LanguageServiceClient} = require('@google-cloud/language').v1beta2;

  // Instantiates a client
  const languageClient = new LanguageServiceClient();

  async function callModerateText() {
    // Construct request
    const request = {
      document,
    };

    // Run request
    const response = await languageClient.moderateText(request);
    console.log(response);
  }

  callModerateText();

moderateText(request, options, callback)

moderateText(request: protos.google.cloud.language.v1beta2.IModerateTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1beta2.IModerateTextResponse, protos.google.cloud.language.v1beta2.IModerateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IModerateTextRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1beta2.IModerateTextResponse, protos.google.cloud.language.v1beta2.IModerateTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

moderateText(request, callback)

moderateText(request: protos.google.cloud.language.v1beta2.IModerateTextRequest, callback: Callback<protos.google.cloud.language.v1beta2.IModerateTextResponse, protos.google.cloud.language.v1beta2.IModerateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IModerateTextRequest
callback Callback<protos.google.cloud.language.v1beta2.IModerateTextResponse, protos.google.cloud.language.v1beta2.IModerateTextRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void