Package com.google.cloud.language.v2 (2.28.0)

A client to Cloud Natural Language API

The interfaces provided are listed below, along with usage samples.

LanguageServiceClient

Service Description: Provides text analysis operations such as sentiment analysis and entity recognition.

Sample for LanguageServiceClient:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
   Document document = Document.newBuilder().build();
   AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
 }
 

Classes

AnalyzeEntitiesRequest

The entity analysis request message.

Protobuf type google.cloud.language.v2.AnalyzeEntitiesRequest

AnalyzeEntitiesRequest.Builder

The entity analysis request message.

Protobuf type google.cloud.language.v2.AnalyzeEntitiesRequest

AnalyzeEntitiesResponse

The entity analysis response message.

Protobuf type google.cloud.language.v2.AnalyzeEntitiesResponse

AnalyzeEntitiesResponse.Builder

The entity analysis response message.

Protobuf type google.cloud.language.v2.AnalyzeEntitiesResponse

AnalyzeSentimentRequest

The sentiment analysis request message.

Protobuf type google.cloud.language.v2.AnalyzeSentimentRequest

AnalyzeSentimentRequest.Builder

The sentiment analysis request message.

Protobuf type google.cloud.language.v2.AnalyzeSentimentRequest

AnalyzeSentimentResponse

The sentiment analysis response message.

Protobuf type google.cloud.language.v2.AnalyzeSentimentResponse

AnalyzeSentimentResponse.Builder

The sentiment analysis response message.

Protobuf type google.cloud.language.v2.AnalyzeSentimentResponse

AnnotateTextRequest

The request message for the text annotation API, which can perform multiple analysis types in one call.

Protobuf type google.cloud.language.v2.AnnotateTextRequest

AnnotateTextRequest.Builder

The request message for the text annotation API, which can perform multiple analysis types in one call.

Protobuf type google.cloud.language.v2.AnnotateTextRequest

AnnotateTextRequest.Features

All available features. Setting each one to true will enable that specific analysis for the input.

Protobuf type google.cloud.language.v2.AnnotateTextRequest.Features

AnnotateTextRequest.Features.Builder

All available features. Setting each one to true will enable that specific analysis for the input.

Protobuf type google.cloud.language.v2.AnnotateTextRequest.Features

AnnotateTextResponse

The text annotations response message.

Protobuf type google.cloud.language.v2.AnnotateTextResponse

AnnotateTextResponse.Builder

The text annotations response message.

Protobuf type google.cloud.language.v2.AnnotateTextResponse

ClassificationCategory

Represents a category returned from the text classifier.

Protobuf type google.cloud.language.v2.ClassificationCategory

ClassificationCategory.Builder

Represents a category returned from the text classifier.

Protobuf type google.cloud.language.v2.ClassificationCategory

ClassifyTextRequest

The document classification request message.

Protobuf type google.cloud.language.v2.ClassifyTextRequest

ClassifyTextRequest.Builder

The document classification request message.

Protobuf type google.cloud.language.v2.ClassifyTextRequest

ClassifyTextResponse

The document classification response message.

Protobuf type google.cloud.language.v2.ClassifyTextResponse

ClassifyTextResponse.Builder

The document classification response message.

Protobuf type google.cloud.language.v2.ClassifyTextResponse

Document

Represents the input to API methods.

Protobuf type google.cloud.language.v2.Document

Document.Builder

Represents the input to API methods.

Protobuf type google.cloud.language.v2.Document

Entity

Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as probability and mentions, with entities.

Protobuf type google.cloud.language.v2.Entity

Entity.Builder

Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as probability and mentions, with entities.

Protobuf type google.cloud.language.v2.Entity

EntityMention

Represents a mention for an entity in the text. Currently, proper noun mentions are supported.

Protobuf type google.cloud.language.v2.EntityMention

EntityMention.Builder

Represents a mention for an entity in the text. Currently, proper noun mentions are supported.

Protobuf type google.cloud.language.v2.EntityMention

LanguageServiceClient

Service Description: Provides text analysis operations such as sentiment analysis and entity recognition.

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:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 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:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

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:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 LanguageServiceSettings languageServiceSettings =
     LanguageServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 LanguageServiceClient languageServiceClient =
     LanguageServiceClient.create(languageServiceSettings);
 

To customize the endpoint:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 LanguageServiceSettings languageServiceSettings =
     LanguageServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 LanguageServiceClient languageServiceClient =
     LanguageServiceClient.create(languageServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 LanguageServiceSettings languageServiceSettings =
     LanguageServiceSettings.newHttpJsonBuilder().build();
 LanguageServiceClient languageServiceClient =
     LanguageServiceClient.create(languageServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

LanguageServiceGrpc

Provides text analysis operations such as sentiment analysis and entity recognition.

LanguageServiceGrpc.LanguageServiceBlockingStub

A stub to allow clients to do synchronous rpc calls to service LanguageService.

Provides text analysis operations such as sentiment analysis and entity recognition.

LanguageServiceGrpc.LanguageServiceFutureStub

A stub to allow clients to do ListenableFuture-style rpc calls to service LanguageService.

Provides text analysis operations such as sentiment analysis and entity recognition.

LanguageServiceGrpc.LanguageServiceImplBase

Base class for the server implementation of the service LanguageService.

Provides text analysis operations such as sentiment analysis and entity recognition.

LanguageServiceGrpc.LanguageServiceStub

A stub to allow clients to do asynchronous rpc calls to service LanguageService.

Provides text analysis operations such as sentiment analysis and entity recognition.

LanguageServiceProto

LanguageServiceSettings

Settings class to configure an instance of LanguageServiceClient.

The default instance has everything set to sensible defaults:

  • The default service address (language.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of analyzeSentiment to 30 seconds:


 // 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.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 LanguageServiceSettings.Builder languageServiceSettingsBuilder =
     LanguageServiceSettings.newBuilder();
 languageServiceSettingsBuilder
     .analyzeSentimentSettings()
     .setRetrySettings(
         languageServiceSettingsBuilder
             .analyzeSentimentSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 LanguageServiceSettings languageServiceSettings = languageServiceSettingsBuilder.build();
 

LanguageServiceSettings.Builder

Builder for LanguageServiceSettings.

ModerateTextRequest

The document moderation request message.

Protobuf type google.cloud.language.v2.ModerateTextRequest

ModerateTextRequest.Builder

The document moderation request message.

Protobuf type google.cloud.language.v2.ModerateTextRequest

ModerateTextResponse

The document moderation response message.

Protobuf type google.cloud.language.v2.ModerateTextResponse

ModerateTextResponse.Builder

The document moderation response message.

Protobuf type google.cloud.language.v2.ModerateTextResponse

Sentence

Represents a sentence in the input document.

Protobuf type google.cloud.language.v2.Sentence

Sentence.Builder

Represents a sentence in the input document.

Protobuf type google.cloud.language.v2.Sentence

Sentiment

Represents the feeling associated with the entire text or entities in the text.

Protobuf type google.cloud.language.v2.Sentiment

Sentiment.Builder

Represents the feeling associated with the entire text or entities in the text.

Protobuf type google.cloud.language.v2.Sentiment

TextSpan

Represents a text span in the input document.

Protobuf type google.cloud.language.v2.TextSpan

TextSpan.Builder

Represents a text span in the input document.

Protobuf type google.cloud.language.v2.TextSpan

Interfaces

AnalyzeEntitiesRequestOrBuilder

AnalyzeEntitiesResponseOrBuilder

AnalyzeSentimentRequestOrBuilder

AnalyzeSentimentResponseOrBuilder

AnnotateTextRequest.FeaturesOrBuilder

AnnotateTextRequestOrBuilder

AnnotateTextResponseOrBuilder

ClassificationCategoryOrBuilder

ClassifyTextRequestOrBuilder

ClassifyTextResponseOrBuilder

DocumentOrBuilder

EntityMentionOrBuilder

EntityOrBuilder

LanguageServiceGrpc.AsyncService

Provides text analysis operations such as sentiment analysis and entity recognition.

ModerateTextRequestOrBuilder

ModerateTextResponseOrBuilder

SentenceOrBuilder

SentimentOrBuilder

TextSpanOrBuilder

Enums

Document.SourceCase

Document.Type

The document types enum.

Protobuf enum google.cloud.language.v2.Document.Type

EncodingType

Represents the text encoding that the caller uses to process the output. Providing an EncodingType is recommended because the API provides the beginning offsets for various outputs, such as tokens and mentions, and languages that natively use different text encodings may access offsets differently.

Protobuf enum google.cloud.language.v2.EncodingType

Entity.Type

The type of the entity. For most entity types, the associated metadata is a Wikipedia URL (wikipedia_url) and Knowledge Graph MID (mid). The table below lists the associated fields for entities that have different metadata.

Protobuf enum google.cloud.language.v2.Entity.Type

EntityMention.Type

The supported types of mentions.

Protobuf enum google.cloud.language.v2.EntityMention.Type