Constructor

LanguageServiceClient

new LanguageServiceClient(options)

Construct an instance of LanguageServiceClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

Account email address. Required when usaing a .pem or .p12 keyFilename.

keyFilename

Optional

string

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option above is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

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

servicePath

static

The DNS address for this API service.

Methods

analyzeEntities

analyzeEntities(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

encodingType

Optional

number

The encoding type used by the API to calculate offsets.

The number should be among the values of EncodingType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AnalyzeEntitiesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AnalyzeEntitiesResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
client.analyzeEntities({document: document})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

analyzeEntitySentiment

analyzeEntitySentiment(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

encodingType

Optional

number

The encoding type used by the API to calculate offsets.

The number should be among the values of EncodingType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AnalyzeEntitySentimentResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AnalyzeEntitySentimentResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
client.analyzeEntitySentiment({document: document})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

analyzeSentiment

analyzeSentiment(request, options, callback) returns Promise

Analyzes the sentiment of the provided text.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

encodingType

Optional

number

The encoding type used by the API to calculate sentence offsets.

The number should be among the values of EncodingType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AnalyzeSentimentResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AnalyzeSentimentResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
client.analyzeSentiment({document: document})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

analyzeSyntax

analyzeSyntax(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

encodingType

Optional

number

The encoding type used by the API to calculate offsets.

The number should be among the values of EncodingType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AnalyzeSyntaxResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AnalyzeSyntaxResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
client.analyzeSyntax({document: document})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

annotateText

annotateText(request, options, callback) returns Promise

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

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

features

Object

The enabled features.

This object should have the same structure as Features

encodingType

Optional

number

The encoding type used by the API to calculate offsets.

The number should be among the values of EncodingType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AnnotateTextResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AnnotateTextResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
var features = {};
var request = {
  document: document,
  features: features,
};
client.annotateText(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

classifyText

classifyText(request, options, callback) returns Promise

Classifies a document into categories.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

document

Object

Input document.

This object should have the same structure as Document

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ClassifyTextResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing ClassifyTextResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const language = require('@google-cloud/language');

var client = new language.v1.LanguageServiceClient({
  // optional auth parameters.
});

var document = {};
client.classifyText({document: document})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.