@Generated(value="by gapic-generator") @BetaApi public class LanguageServiceClient extends Object implements com.google.api.gax.core.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();
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
}
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 |
---|---|
AnalyzeEntitiesResponse |
analyzeEntities(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.
|
AnalyzeEntitiesResponse |
analyzeEntities(Document document,
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.
|
com.google.api.gax.rpc.UnaryCallable<AnalyzeEntitiesRequest,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.
|
AnalyzeEntitySentimentResponse |
analyzeEntitySentiment(AnalyzeEntitySentimentRequest request)
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1beta2.LanguageService.AnalyzeEntities] in the text
and analyzes sentiment associated with each entity and its mentions.
|
AnalyzeEntitySentimentResponse |
analyzeEntitySentiment(Document document,
EncodingType encodingType)
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1beta2.LanguageService.AnalyzeEntities] in the text
and analyzes sentiment associated with each entity and its mentions.
|
com.google.api.gax.rpc.UnaryCallable<AnalyzeEntitySentimentRequest,AnalyzeEntitySentimentResponse> |
analyzeEntitySentimentCallable()
Finds entities, similar to
[AnalyzeEntities][google.cloud.language.v1beta2.LanguageService.AnalyzeEntities] in the text
and analyzes sentiment associated with each entity and its mentions.
|
AnalyzeSentimentResponse |
analyzeSentiment(AnalyzeSentimentRequest request)
Analyzes the sentiment of the provided text.
|
AnalyzeSentimentResponse |
analyzeSentiment(Document document)
Analyzes the sentiment of the provided text.
|
com.google.api.gax.rpc.UnaryCallable<AnalyzeSentimentRequest,AnalyzeSentimentResponse> |
analyzeSentimentCallable()
Analyzes the sentiment of the provided text.
|
AnalyzeSyntaxResponse |
analyzeSyntax(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.
|
AnalyzeSyntaxResponse |
analyzeSyntax(Document document,
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.
|
com.google.api.gax.rpc.UnaryCallable<AnalyzeSyntaxRequest,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.
|
AnnotateTextResponse |
annotateText(AnnotateTextRequest request)
A convenience method that provides all syntax, sentiment, entity, and classification features
in one call.
|
AnnotateTextResponse |
annotateText(Document document,
AnnotateTextRequest.Features features,
EncodingType encodingType)
A convenience method that provides all syntax, sentiment, entity, and classification features
in one call.
|
com.google.api.gax.rpc.UnaryCallable<AnnotateTextRequest,AnnotateTextResponse> |
annotateTextCallable()
A convenience method that provides all syntax, sentiment, entity, and classification features
in one call.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
ClassifyTextResponse |
classifyText(ClassifyTextRequest request)
Classifies a document into categories.
|
ClassifyTextResponse |
classifyText(Document document)
Classifies a document into categories.
|
com.google.api.gax.rpc.UnaryCallable<ClassifyTextRequest,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 AnalyzeSentimentResponse analyzeSentiment(Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
}
document
- Required. Input document.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AnalyzeSentimentResponse analyzeSentiment(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<AnalyzeSentimentRequest,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 AnalyzeEntitiesResponse analyzeEntities(Document document, 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
- Required. Input document.encodingType
- The encoding type used by the API to calculate offsets.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AnalyzeEntitiesResponse analyzeEntities(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<AnalyzeEntitiesRequest,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 AnalyzeEntitySentimentResponse analyzeEntitySentiment(Document document, 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
- Required. Input document.encodingType
- The encoding type used by the API to calculate offsets.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AnalyzeEntitySentimentResponse analyzeEntitySentiment(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<AnalyzeEntitySentimentRequest,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 AnalyzeSyntaxResponse analyzeSyntax(Document document, 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
- Required. Input document.encodingType
- The encoding type used by the API to calculate offsets.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AnalyzeSyntaxResponse analyzeSyntax(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<AnalyzeSyntaxRequest,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 ClassifyTextResponse classifyText(Document document)
Sample code:
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
ClassifyTextResponse response = languageServiceClient.classifyText(document);
}
document
- Required. Input document.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final ClassifyTextResponse classifyText(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ClassifyTextRequest,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 AnnotateTextResponse annotateText(Document document, AnnotateTextRequest.Features features, 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
- Required. Input document.features
- Required. The enabled features.encodingType
- The encoding type used by the API to calculate offsets.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AnnotateTextResponse annotateText(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<AnnotateTextRequest,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 com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.