UNPKG

@google-cloud/language

Version:
307 lines (306 loc) 20.1 kB
import type * as gax from 'google-gax'; import type { Callback, CallOptions, Descriptors, ClientOptions } from 'google-gax'; import * as protos from '../../protos/protos'; /** * Provides text analysis operations such as sentiment analysis and entity * recognition. * @class * @memberof v1 */ export declare class LanguageServiceClient { private _terminated; private _opts; private _providedCustomServicePath; private _gaxModule; private _gaxGrpc; private _protos; private _defaults; private _universeDomain; private _servicePath; private _log; auth: gax.GoogleAuth; descriptors: Descriptors; warn: (code: string, message: string, warnType?: string) => void; innerApiCalls: { [name: string]: Function; }; languageServiceStub?: Promise<{ [name: string]: Function; }>; /** * Construct an instance of LanguageServiceClient. * * @param {object} [options] - The configuration object. * The options accepted by the constructor are described in detail * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). * The common options are: * @param {object} [options.credentials] - Credentials object. * @param {string} [options.credentials.client_email] * @param {string} [options.credentials.private_key] * @param {string} [options.email] - Account email address. Required when * using a .pem or .p12 keyFilename. * @param {string} [options.keyFilename] - 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 below is not necessary. * NOTE: .pem and .p12 require you to specify options.email as well. * @param {number} [options.port] - The port on which to connect to * the remote host. * @param {string} [options.projectId] - 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 * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. * Follows the structure of {@link gapicConfig}. * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. * For more information, please check the * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. * @param {gax} [gaxInstance]: 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); * ``` */ constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback); /** * 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 {Promise} A promise that resolves to an authenticated service stub. */ initialize(): Promise<{ [name: string]: Function; }>; /** * The DNS address for this API service. * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath(): string; /** * The DNS address for this API service - same as servicePath. * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint(): string; /** * The DNS address for this API service. * @returns {string} The DNS address for this service. */ get apiEndpoint(): string; get universeDomain(): string; /** * The port for this API service. * @returns {number} The default port for this service. */ static get port(): number; /** * The scopes needed to make gRPC calls for every method defined * in this service. * @returns {string[]} List of default scopes. */ static get scopes(): string[]; getProjectId(): Promise<string>; getProjectId(callback: Callback<string, undefined, undefined>): void; /** * Analyzes the sentiment of the provided text. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.EncodingType} request.encodingType * The encoding type used by the API to calculate sentence offsets. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.AnalyzeSentimentResponse|AnalyzeSentimentResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.analyze_sentiment.js</caption> * region_tag:language_v1_generated_LanguageService_AnalyzeSentiment_async */ 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 ]>; 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; 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; /** * Finds named entities (currently proper names and common nouns) in the text * along with entity types, salience, mentions for each entity, and * other properties. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.EncodingType} request.encodingType * The encoding type used by the API to calculate offsets. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.AnalyzeEntitiesResponse|AnalyzeEntitiesResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.analyze_entities.js</caption> * region_tag:language_v1_generated_LanguageService_AnalyzeEntities_async */ 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 ]>; 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; 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; /** * Finds entities, similar to * {@link protos.google.cloud.language.v1.LanguageService.AnalyzeEntities|AnalyzeEntities} * in the text and analyzes sentiment associated with each entity and its * mentions. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.EncodingType} request.encodingType * The encoding type used by the API to calculate offsets. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.AnalyzeEntitySentimentResponse|AnalyzeEntitySentimentResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.analyze_entity_sentiment.js</caption> * region_tag:language_v1_generated_LanguageService_AnalyzeEntitySentiment_async */ 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 ]>; 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; 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; /** * Analyzes the syntax of the text and provides sentence boundaries and * tokenization along with part of speech tags, dependency trees, and other * properties. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.EncodingType} request.encodingType * The encoding type used by the API to calculate offsets. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.AnalyzeSyntaxResponse|AnalyzeSyntaxResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.analyze_syntax.js</caption> * region_tag:language_v1_generated_LanguageService_AnalyzeSyntax_async */ 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 ]>; 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; 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; /** * Classifies a document into categories. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.ClassificationModelOptions} request.classificationModelOptions * Model options to use for classification. Defaults to v1 options if not * specified. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.ClassifyTextResponse|ClassifyTextResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.classify_text.js</caption> * region_tag:language_v1_generated_LanguageService_ClassifyText_async */ 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 ]>; 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; 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; /** * Moderates a document for harmful and sensitive categories. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.ModerateTextResponse|ModerateTextResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.moderate_text.js</caption> * region_tag:language_v1_generated_LanguageService_ModerateText_async */ 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 ]>; 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; 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; /** * A convenience method that provides all the features that analyzeSentiment, * analyzeEntities, and analyzeSyntax provide in one call. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.language.v1.Document} request.document * Required. Input document. * @param {google.cloud.language.v1.AnnotateTextRequest.Features} request.features * Required. The enabled features. * @param {google.cloud.language.v1.EncodingType} request.encodingType * The encoding type used by the API to calculate offsets. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.language.v1.AnnotateTextResponse|AnnotateTextResponse}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v1/language_service.annotate_text.js</caption> * region_tag:language_v1_generated_LanguageService_AnnotateText_async */ 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 ]>; 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; 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; /** * Terminate the gRPC channel and close the client. * * The client will no longer be usable and all future behavior is undefined. * @returns {Promise} A promise that resolves when the client is closed. */ close(): Promise<void>; }