Class v1.LanguageServiceClient (4.3.2)

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

Package

@google-cloud/language

Constructors

(constructor)(opts)

constructor(opts?: ClientOptions);

Construct an instance of LanguageServiceClient.

Parameter
NameDescription
opts ClientOptions

Properties

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

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.

warn

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

Methods

analyzeEntities(request, options)

analyzeEntities(request?: protos.google.cloud.language.v1.IAnalyzeEntitiesRequest, options?: CallOptions): Promise<[protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.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
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitiesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  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').v1;

  // 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.v1.IAnalyzeEntitiesRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitiesRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeEntities(request, callback)

analyzeEntities(request: protos.google.cloud.language.v1.IAnalyzeEntitiesRequest, callback: Callback<protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitiesRequest
callback Callback<protos.google.cloud.language.v1.IAnalyzeEntitiesResponse, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeEntitySentiment(request, options)

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

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

Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse, (protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  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').v1;

  // 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.v1.IAnalyzeEntitySentimentRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeEntitySentiment(request, callback)

analyzeEntitySentiment(request: protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest, callback: Callback<protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest
callback Callback<protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeSentiment(request, options)

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

Analyzes the sentiment of the provided text.

Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSentimentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IAnalyzeSentimentResponse, protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Input document.
   */
  // const document = {}
  /**
   *  The encoding type used by the API to calculate sentence offsets.
   */
  // const encodingType = {}

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

  // 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.v1.IAnalyzeSentimentRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IAnalyzeSentimentResponse, protos.google.cloud.language.v1.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSentimentRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IAnalyzeSentimentResponse, protos.google.cloud.language.v1.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeSentiment(request, callback)

analyzeSentiment(request: protos.google.cloud.language.v1.IAnalyzeSentimentRequest, callback: Callback<protos.google.cloud.language.v1.IAnalyzeSentimentResponse, protos.google.cloud.language.v1.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSentimentRequest
callback Callback<protos.google.cloud.language.v1.IAnalyzeSentimentResponse, protos.google.cloud.language.v1.IAnalyzeSentimentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeSyntax(request, options)

analyzeSyntax(request?: protos.google.cloud.language.v1.IAnalyzeSyntaxRequest, options?: CallOptions): Promise<[protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.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
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSyntaxRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  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').v1;

  // 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.v1.IAnalyzeSyntaxRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSyntaxRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

analyzeSyntax(request, callback)

analyzeSyntax(request: protos.google.cloud.language.v1.IAnalyzeSyntaxRequest, callback: Callback<protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnalyzeSyntaxRequest
callback Callback<protos.google.cloud.language.v1.IAnalyzeSyntaxResponse, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

annotateText(request, options)

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

A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call.

Parameters
NameDescription
request protos.google.cloud.language.v1.IAnnotateTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IAnnotateTextResponse, protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Input document.
   */
  // const document = {}
  /**
   *  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').v1;

  // 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.v1.IAnnotateTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IAnnotateTextResponse, protos.google.cloud.language.v1.IAnnotateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnnotateTextRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IAnnotateTextResponse, protos.google.cloud.language.v1.IAnnotateTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

annotateText(request, callback)

annotateText(request: protos.google.cloud.language.v1.IAnnotateTextRequest, callback: Callback<protos.google.cloud.language.v1.IAnnotateTextResponse, protos.google.cloud.language.v1.IAnnotateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IAnnotateTextRequest
callback Callback<protos.google.cloud.language.v1.IAnnotateTextResponse, protos.google.cloud.language.v1.IAnnotateTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

classifyText(request, options)

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

Classifies a document into categories.

Parameters
NameDescription
request protos.google.cloud.language.v1.IClassifyTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.language.v1.IClassifyTextResponse, protos.google.cloud.language.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Input document.
   */
  // const document = {}

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

  // 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.v1.IClassifyTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IClassifyTextResponse, protos.google.cloud.language.v1.IClassifyTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IClassifyTextRequest
options CallOptions
callback Callback<protos.google.cloud.language.v1.IClassifyTextResponse, protos.google.cloud.language.v1.IClassifyTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

classifyText(request, callback)

classifyText(request: protos.google.cloud.language.v1.IClassifyTextRequest, callback: Callback<protos.google.cloud.language.v1.IClassifyTextResponse, protos.google.cloud.language.v1.IClassifyTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.language.v1.IClassifyTextRequest
callback Callback<protos.google.cloud.language.v1.IClassifyTextResponse, protos.google.cloud.language.v1.IClassifyTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
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
TypeDescription
Promise<void>

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

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
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
TypeDescription
Promise<{ [name: string]: Function; }>

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