Provides text analysis operations such as sentiment analysis and entity recognition. v1
Package
@google-cloud/languageConstructors
(constructor)(opts, gaxInstance)
constructor
(
opts
?:
ClientOptions
,
gaxInstance
?:
typeof
gax
|
typeof
gax
.
fallback
);
Construct an instance of LanguageServiceClient.
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
.
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeEntitiesResponse
, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeEntitiesResponse
, protos.google.cloud.language.v1.IAnalyzeEntitiesRequest
| null | undefined, {} | null | undefined>
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse
, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeEntitySentimentResponse
, protos.google.cloud.language.v1.IAnalyzeEntitySentimentRequest
| null | undefined, {} | null | undefined>
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeSentimentResponse
, protos.google.cloud.language.v1.IAnalyzeSentimentRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeSentimentResponse
, protos.google.cloud.language.v1.IAnalyzeSentimentRequest
| null | undefined, {} | null | undefined>
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeSyntaxResponse
, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IAnalyzeSyntaxResponse
, protos.google.cloud.language.v1.IAnalyzeSyntaxRequest
| null | undefined, {} | null | undefined>
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IAnnotateTextResponse
, protos.google.cloud.language.v1.IAnnotateTextRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IAnnotateTextResponse
, protos.google.cloud.language.v1.IAnnotateTextRequest
| null | undefined, {} | null | undefined>
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.
request
options
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 for more details and examples.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IClassifyTextResponse
, protos.google.cloud.language.v1.IClassifyTextRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IClassifyTextResponse
, protos.google.cloud.language.v1.IClassifyTextRequest
| null | undefined, {} | null | undefined>
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.
Promise
<void>
{Promise} A promise that resolves when the client is closed.
getProjectId()
getProjectId
()
:
Promise<string>
;
Promise
<string>
getProjectId(callback)
getProjectId
(
callback
:
Callback<string
,
undefined
,
undefined
> )
:
void
;
callback
Callback
<string, undefined, undefined>
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.
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.
request
options
Promise
<[ protos.google.cloud.language.v1.IModerateTextResponse
, protos.google.cloud.language.v1.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.
/**
* 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
;
request
options
CallOptions
callback
Callback
< protos.google.cloud.language.v1.IModerateTextResponse
, protos.google.cloud.language.v1.IModerateTextRequest
| null | undefined, {} | null | undefined>
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
;
request
callback
Callback
< protos.google.cloud.language.v1.IModerateTextResponse
, protos.google.cloud.language.v1.IModerateTextRequest
| null | undefined, {} | null | undefined>
void