@Generated(value="by GAPIC v0.0.5") @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:
LanguageServiceSettings languageServiceSettings =
LanguageServiceSettings.defaultBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.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,
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.
|
com.google.api.gax.rpc.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.AnalyzeSentimentResponse |
analyzeSentiment(com.google.cloud.language.v1.Document document)
Analyzes the sentiment of the provided text.
|
com.google.api.gax.rpc.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,
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.
|
com.google.api.gax.rpc.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,
com.google.cloud.language.v1.EncodingType encodingType)
A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
analyzeSyntax provide in one call.
|
com.google.api.gax.rpc.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) |
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
IOExceptionprotected LanguageServiceClient(LanguageServiceStub stub)
public static final LanguageServiceClient create() throws IOException
IOExceptionpublic static final LanguageServiceClient create(LanguageServiceSettings settings) throws IOException
IOExceptionpublic static final LanguageServiceClient create(LanguageServiceStub stub)
public final LanguageServiceSettings getSettings()
public LanguageServiceStub getStub()
public 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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.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.com.google.api.gax.rpc.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();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
.setDocument(document)
.setEncodingType(encodingType)
.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<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();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
.setDocument(document)
.setEncodingType(encodingType)
.build();
ApiFuture<AnalyzeEntitiesResponse> future = languageServiceClient.analyzeEntitiesCallable().futureCall(request);
// Do something
AnalyzeEntitiesResponse 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.com.google.api.gax.rpc.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();
EncodingType encodingType = EncodingType.NONE;
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
.setDocument(document)
.setEncodingType(encodingType)
.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<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();
EncodingType encodingType = EncodingType.NONE;
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
.setDocument(document)
.setEncodingType(encodingType)
.build();
ApiFuture<AnalyzeSyntaxResponse> future = languageServiceClient.analyzeSyntaxCallable().futureCall(request);
// Do something
AnalyzeSyntaxResponse 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.com.google.api.gax.rpc.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();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
.setDocument(document)
.setFeatures(features)
.setEncodingType(encodingType)
.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<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();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
.setDocument(document)
.setFeatures(features)
.setEncodingType(encodingType)
.build();
ApiFuture<AnnotateTextResponse> future = languageServiceClient.annotateTextCallable().futureCall(request);
// Do something
AnnotateTextResponse response = future.get();
}
public final void close()
throws Exception
close in interface AutoCloseableExceptionpublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2017 Google. All rights reserved.