Provides text analysis operations such as sentiment analysis and entity recognition. v1
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
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.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.
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').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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
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.
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').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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
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.
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.
*/
// 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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
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 |
Name |
Description |
request |
IAnalyzeSyntaxRequest
The request object that will be sent.
|
options |
CallOptions
Call options. See CallOptions for more details.
|
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').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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
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 |
Name |
Description |
request |
IAnnotateTextRequest
The request object that will be sent.
|
options |
CallOptions
Call options. See CallOptions for more details.
|
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').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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
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 |
Name |
Description |
request |
IClassifyTextRequest
The request object that will be sent.
|
options |
CallOptions
Call options. See CallOptions for more details.
|
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').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;
Returns |
Type |
Description |
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;
Returns |
Type |
Description |
void |
|
close()
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.v1.IModerateTextRequest, options?: CallOptions): Promise<[
protos.google.cloud.language.v1.IModerateTextResponse,
protos.google.cloud.language.v1.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.
|
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').v1;
// 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.v1.IModerateTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.language.v1.IModerateTextResponse, protos.google.cloud.language.v1.IModerateTextRequest | null | undefined, {} | null | undefined>): void;
Returns |
Type |
Description |
void |
|
moderateText(request, callback)
moderateText(request: protos.google.cloud.language.v1.IModerateTextRequest, callback: Callback<protos.google.cloud.language.v1.IModerateTextResponse, protos.google.cloud.language.v1.IModerateTextRequest | null | undefined, {} | null | undefined>): void;
Returns |
Type |
Description |
void |
|