@Generated(value="by gapic-generator") @BetaApi public class LanguageServiceClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document, encodingType);
}
Note: close() needs to be called on the languageServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of LanguageServiceSettings to create(). For example:
To customize credentials:
LanguageServiceSettings languageServiceSettings =
LanguageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
LanguageServiceClient languageServiceClient =
LanguageServiceClient.create(languageServiceSettings);
To customize the endpoint:
LanguageServiceSettings languageServiceSettings =
LanguageServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
LanguageServiceClient languageServiceClient =
LanguageServiceClient.create(languageServiceSettings);
Modifier | Constructor and Description |
---|---|
protected |
LanguageServiceClient(LanguageServiceSettings settings)
Constructs an instance of LanguageServiceClient, using the given settings.
|
protected |
LanguageServiceClient(LanguageServiceStub stub) |
Modifier and Type | Method and Description |
---|---|
com.google.cloud.language.v1.AnalyzeEntitiesResponse |
analyzeEntities(com.google.cloud.language.v1.AnalyzeEntitiesRequest request)
Finds named entities (currently proper names and common nouns) in the text along with entity
types, salience, mentions for each entity, and other properties.
|
com.google.cloud.language.v1.AnalyzeEntitiesResponse |
analyzeEntities(com.google.cloud.language.v1.Document document)
Finds named entities (currently proper names and common nouns) in the text along with entity
types, salience, mentions for each entity, and other properties.
|
com.google.cloud.language.v1.AnalyzeEntitiesResponse |
analyzeEntities(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.EncodingType encodingType)
Finds named entities (currently proper names and common nouns) in the text along with entity
types, salience, mentions for each entity, and other properties.
|
UnaryCallable<com.google.cloud.language.v1.AnalyzeEntitiesRequest,com.google.cloud.language.v1.AnalyzeEntitiesResponse> |
analyzeEntitiesCallable()
Finds named entities (currently proper names and common nouns) in the text along with entity
types, salience, mentions for each entity, and other properties.
|
com.google.cloud.language.v1.AnalyzeEntitySentimentResponse |
analyzeEntitySentiment(com.google.cloud.language.v1.AnalyzeEntitySentimentRequest request)
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and
analyzes sentiment associated with each entity and its mentions.
|
com.google.cloud.language.v1.AnalyzeEntitySentimentResponse |
analyzeEntitySentiment(com.google.cloud.language.v1.Document document)
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and
analyzes sentiment associated with each entity and its mentions.
|
com.google.cloud.language.v1.AnalyzeEntitySentimentResponse |
analyzeEntitySentiment(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.EncodingType encodingType)
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and
analyzes sentiment associated with each entity and its mentions.
|
UnaryCallable<com.google.cloud.language.v1.AnalyzeEntitySentimentRequest,com.google.cloud.language.v1.AnalyzeEntitySentimentResponse> |
analyzeEntitySentimentCallable()
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and
analyzes sentiment associated with each entity and its mentions.
|
com.google.cloud.language.v1.AnalyzeSentimentResponse |
analyzeSentiment(com.google.cloud.language.v1.AnalyzeSentimentRequest request)
Analyzes the sentiment of the provided text.
|
com.google.cloud.language.v1.AnalyzeSentimentResponse |
analyzeSentiment(com.google.cloud.language.v1.Document document)
Analyzes the sentiment of the provided text.
|
com.google.cloud.language.v1.AnalyzeSentimentResponse |
analyzeSentiment(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.EncodingType encodingType)
Analyzes the sentiment of the provided text.
|
UnaryCallable<com.google.cloud.language.v1.AnalyzeSentimentRequest,com.google.cloud.language.v1.AnalyzeSentimentResponse> |
analyzeSentimentCallable()
Analyzes the sentiment of the provided text.
|
com.google.cloud.language.v1.AnalyzeSyntaxResponse |
analyzeSyntax(com.google.cloud.language.v1.AnalyzeSyntaxRequest request)
Analyzes the syntax of the text and provides sentence boundaries and tokenization along with
part of speech tags, dependency trees, and other properties.
|
com.google.cloud.language.v1.AnalyzeSyntaxResponse |
analyzeSyntax(com.google.cloud.language.v1.Document document)
Analyzes the syntax of the text and provides sentence boundaries and tokenization along with
part of speech tags, dependency trees, and other properties.
|
com.google.cloud.language.v1.AnalyzeSyntaxResponse |
analyzeSyntax(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.EncodingType encodingType)
Analyzes the syntax of the text and provides sentence boundaries and tokenization along with
part of speech tags, dependency trees, and other properties.
|
UnaryCallable<com.google.cloud.language.v1.AnalyzeSyntaxRequest,com.google.cloud.language.v1.AnalyzeSyntaxResponse> |
analyzeSyntaxCallable()
Analyzes the syntax of the text and provides sentence boundaries and tokenization along with
part of speech tags, dependency trees, and other properties.
|
com.google.cloud.language.v1.AnnotateTextResponse |
annotateText(com.google.cloud.language.v1.AnnotateTextRequest request)
A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
analyzeSyntax provide in one call.
|
com.google.cloud.language.v1.AnnotateTextResponse |
annotateText(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.AnnotateTextRequest.Features features)
A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
analyzeSyntax provide in one call.
|
com.google.cloud.language.v1.AnnotateTextResponse |
annotateText(com.google.cloud.language.v1.Document document,
com.google.cloud.language.v1.AnnotateTextRequest.Features features,
com.google.cloud.language.v1.EncodingType encodingType)
A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
analyzeSyntax provide in one call.
|
UnaryCallable<com.google.cloud.language.v1.AnnotateTextRequest,com.google.cloud.language.v1.AnnotateTextResponse> |
annotateTextCallable()
A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
analyzeSyntax provide in one call.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
com.google.cloud.language.v1.ClassifyTextResponse |
classifyText(com.google.cloud.language.v1.ClassifyTextRequest request)
Classifies a document into categories.
|
com.google.cloud.language.v1.ClassifyTextResponse |
classifyText(com.google.cloud.language.v1.Document document)
Classifies a document into categories.
|
UnaryCallable<com.google.cloud.language.v1.ClassifyTextRequest,com.google.cloud.language.v1.ClassifyTextResponse> |
classifyTextCallable()
Classifies a document into categories.
|
void |
close() |
static LanguageServiceClient |
create()
Constructs an instance of LanguageServiceClient with default settings.
|
static LanguageServiceClient |
create(LanguageServiceSettings settings)
Constructs an instance of LanguageServiceClient, using the given settings.
|
static LanguageServiceClient |
create(LanguageServiceStub stub)
Constructs an instance of LanguageServiceClient, using the given stub for making calls.
|
LanguageServiceSettings |
getSettings() |
LanguageServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
protected LanguageServiceClient(LanguageServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected LanguageServiceClient(LanguageServiceStub stub)
public static final LanguageServiceClient create() throws IOException
IOException
public static final LanguageServiceClient create(LanguageServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final LanguageServiceClient create(LanguageServiceStub stub)
public final LanguageServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public LanguageServiceStub getStub()
public final com.google.cloud.language.v1.AnalyzeSentimentResponse analyzeSentiment(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.EncodingType encodingType)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document, encodingType);
}
document
- Input document.encodingType
- The encoding type used by the API to calculate sentence offsets.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeSentimentResponse analyzeSentiment(com.google.cloud.language.v1.Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
}
document
- Input document.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeSentimentResponse analyzeSentiment(com.google.cloud.language.v1.AnalyzeSentimentRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSentimentRequest request = AnalyzeSentimentRequest.newBuilder()
.setDocument(document)
.build();
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.AnalyzeSentimentRequest,com.google.cloud.language.v1.AnalyzeSentimentResponse> analyzeSentimentCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSentimentRequest request = AnalyzeSentimentRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<AnalyzeSentimentResponse> future = languageServiceClient.analyzeSentimentCallable().futureCall(request);
// Do something
AnalyzeSentimentResponse response = future.get();
}
public final com.google.cloud.language.v1.AnalyzeEntitiesResponse analyzeEntities(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.EncodingType encodingType)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(document, encodingType);
}
document
- Input document.encodingType
- The encoding type used by the API to calculate offsets.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeEntitiesResponse analyzeEntities(com.google.cloud.language.v1.Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(document);
}
document
- Input document.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeEntitiesResponse analyzeEntities(com.google.cloud.language.v1.AnalyzeEntitiesRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
.setDocument(document)
.build();
AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.AnalyzeEntitiesRequest,com.google.cloud.language.v1.AnalyzeEntitiesResponse> analyzeEntitiesCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<AnalyzeEntitiesResponse> future = languageServiceClient.analyzeEntitiesCallable().futureCall(request);
// Do something
AnalyzeEntitiesResponse response = future.get();
}
public final com.google.cloud.language.v1.AnalyzeEntitySentimentResponse analyzeEntitySentiment(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.EncodingType encodingType)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(document, encodingType);
}
document
- Input document.encodingType
- The encoding type used by the API to calculate offsets.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeEntitySentimentResponse analyzeEntitySentiment(com.google.cloud.language.v1.Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(document);
}
document
- Input document.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeEntitySentimentResponse analyzeEntitySentiment(com.google.cloud.language.v1.AnalyzeEntitySentimentRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()
.setDocument(document)
.build();
AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.AnalyzeEntitySentimentRequest,com.google.cloud.language.v1.AnalyzeEntitySentimentResponse> analyzeEntitySentimentCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<AnalyzeEntitySentimentResponse> future = languageServiceClient.analyzeEntitySentimentCallable().futureCall(request);
// Do something
AnalyzeEntitySentimentResponse response = future.get();
}
public final com.google.cloud.language.v1.AnalyzeSyntaxResponse analyzeSyntax(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.EncodingType encodingType)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document, encodingType);
}
document
- Input document.encodingType
- The encoding type used by the API to calculate offsets.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeSyntaxResponse analyzeSyntax(com.google.cloud.language.v1.Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document);
}
document
- Input document.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnalyzeSyntaxResponse analyzeSyntax(com.google.cloud.language.v1.AnalyzeSyntaxRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
.setDocument(document)
.build();
AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.AnalyzeSyntaxRequest,com.google.cloud.language.v1.AnalyzeSyntaxResponse> analyzeSyntaxCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<AnalyzeSyntaxResponse> future = languageServiceClient.analyzeSyntaxCallable().futureCall(request);
// Do something
AnalyzeSyntaxResponse response = future.get();
}
public final com.google.cloud.language.v1.ClassifyTextResponse classifyText(com.google.cloud.language.v1.Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
ClassifyTextResponse response = languageServiceClient.classifyText(document);
}
document
- Input document.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.ClassifyTextResponse classifyText(com.google.cloud.language.v1.ClassifyTextRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder()
.setDocument(document)
.build();
ClassifyTextResponse response = languageServiceClient.classifyText(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.ClassifyTextRequest,com.google.cloud.language.v1.ClassifyTextResponse> classifyTextCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<ClassifyTextResponse> future = languageServiceClient.classifyTextCallable().futureCall(request);
// Do something
ClassifyTextResponse response = future.get();
}
public final com.google.cloud.language.v1.AnnotateTextResponse annotateText(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.AnnotateTextRequest.Features features, com.google.cloud.language.v1.EncodingType encodingType)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextResponse response = languageServiceClient.annotateText(document, features, encodingType);
}
document
- Input document.features
- The enabled features.encodingType
- The encoding type used by the API to calculate offsets.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnnotateTextResponse annotateText(com.google.cloud.language.v1.Document document, com.google.cloud.language.v1.AnnotateTextRequest.Features features)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
AnnotateTextResponse response = languageServiceClient.annotateText(document, features);
}
document
- Input document.features
- The enabled features.ApiException
- if the remote call failspublic final com.google.cloud.language.v1.AnnotateTextResponse annotateText(com.google.cloud.language.v1.AnnotateTextRequest request)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
.setDocument(document)
.setFeatures(features)
.build();
AnnotateTextResponse response = languageServiceClient.annotateText(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.language.v1.AnnotateTextRequest,com.google.cloud.language.v1.AnnotateTextResponse> annotateTextCallable()
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
.setDocument(document)
.setFeatures(features)
.build();
ApiFuture<AnnotateTextResponse> future = languageServiceClient.annotateTextCallable().futureCall(request);
// Do something
AnnotateTextResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.