Skip to content

Commit

Permalink
feat: [language] Added client library support for ModerateText in the…
Browse files Browse the repository at this point in the history
… Natural Language API (V1) (#9463)

* feat: Added client library support for ModerateText in the Natural Language API (V1Beta2)

PiperOrigin-RevId: 534975458

Source-Link: googleapis/googleapis@392db1d

Source-Link: https://github.com/googleapis/googleapis-gen/commit/df98b94b1218af16109fe3e1aef329732779c0a9
Copy-Tag: eyJwIjoiamF2YS1sYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiZGY5OGI5NGIxMjE4YWYxNjEwOWZlM2UxYWVmMzI5NzMyNzc5YzBhOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* feat: Added client library support for ModerateText in the Natural Language API (V1)

PiperOrigin-RevId: 534992604

Source-Link: googleapis/googleapis@2400fac

Source-Link: https://github.com/googleapis/googleapis-gen/commit/32caa580131b05b880fa3b802ca0c21179881733
Copy-Tag: eyJwIjoiamF2YS1sYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiMzJjYWE1ODAxMzFiMDViODgwZmEzYjgwMmNhMGMyMTE3OTg4MTczMyJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored May 26, 2023
1 parent 5c12b61 commit 14fea71
Show file tree
Hide file tree
Showing 104 changed files with 6,895 additions and 2,453 deletions.
4 changes: 2 additions & 2 deletions java-language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.12.0</version>
<version>26.15.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -227,7 +227,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-language.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-language/2.15.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-language/2.18.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,84 @@ public final UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTe
return stub.classifyTextCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Moderates a document for harmful and sensitive categories.
*
* <p>Sample code:
*
* <pre>{@code
* // 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();
* ModerateTextResponse response = languageServiceClient.moderateText(document);
* }
* }</pre>
*
* @param document Required. Input document.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ModerateTextResponse moderateText(Document document) {
ModerateTextRequest request = ModerateTextRequest.newBuilder().setDocument(document).build();
return moderateText(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Moderates a document for harmful and sensitive categories.
*
* <p>Sample code:
*
* <pre>{@code
* // 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()) {
* ModerateTextRequest request =
* ModerateTextRequest.newBuilder().setDocument(Document.newBuilder().build()).build();
* ModerateTextResponse response = languageServiceClient.moderateText(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ModerateTextResponse moderateText(ModerateTextRequest request) {
return moderateTextCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Moderates a document for harmful and sensitive categories.
*
* <p>Sample code:
*
* <pre>{@code
* // 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()) {
* ModerateTextRequest request =
* ModerateTextRequest.newBuilder().setDocument(Document.newBuilder().build()).build();
* ApiFuture<ModerateTextResponse> future =
* languageServiceClient.moderateTextCallable().futureCall(request);
* // Do something.
* ModerateTextResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable() {
return stub.moderateTextCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public UnaryCallSettings<ClassifyTextRequest, ClassifyTextResponse> classifyText
return ((LanguageServiceStubSettings) getStubSettings()).classifyTextSettings();
}

/** Returns the object with the settings used for calls to moderateText. */
public UnaryCallSettings<ModerateTextRequest, ModerateTextResponse> moderateTextSettings() {
return ((LanguageServiceStubSettings) getStubSettings()).moderateTextSettings();
}

/** Returns the object with the settings used for calls to annotateText. */
public UnaryCallSettings<AnnotateTextRequest, AnnotateTextResponse> annotateTextSettings() {
return ((LanguageServiceStubSettings) getStubSettings()).annotateTextSettings();
Expand Down Expand Up @@ -250,6 +255,12 @@ public Builder applyToAllUnaryMethods(
return getStubSettingsBuilder().classifyTextSettings();
}

/** Returns the builder for the settings used for calls to moderateText. */
public UnaryCallSettings.Builder<ModerateTextRequest, ModerateTextResponse>
moderateTextSettings() {
return getStubSettingsBuilder().moderateTextSettings();
}

/** Returns the builder for the settings used for calls to annotateText. */
public UnaryCallSettings.Builder<AnnotateTextRequest, AnnotateTextResponse>
annotateTextSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
},
"ClassifyText": {
"methods": ["classifyText", "classifyText", "classifyTextCallable"]
},
"ModerateText": {
"methods": ["moderateText", "moderateText", "moderateTextCallable"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.google.cloud.language.v1.AnnotateTextResponse;
import com.google.cloud.language.v1.ClassifyTextRequest;
import com.google.cloud.language.v1.ClassifyTextResponse;
import com.google.cloud.language.v1.ModerateTextRequest;
import com.google.cloud.language.v1.ModerateTextResponse;
import com.google.longrunning.stub.GrpcOperationsStub;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
Expand Down Expand Up @@ -105,6 +107,16 @@ public class GrpcLanguageServiceStub extends LanguageServiceStub {
ProtoUtils.marshaller(ClassifyTextResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<ModerateTextRequest, ModerateTextResponse>
moderateTextMethodDescriptor =
MethodDescriptor.<ModerateTextRequest, ModerateTextResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.language.v1.LanguageService/ModerateText")
.setRequestMarshaller(ProtoUtils.marshaller(ModerateTextRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ModerateTextResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<AnnotateTextRequest, AnnotateTextResponse>
annotateTextMethodDescriptor =
MethodDescriptor.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
Expand All @@ -123,6 +135,7 @@ public class GrpcLanguageServiceStub extends LanguageServiceStub {
analyzeEntitySentimentCallable;
private final UnaryCallable<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse> analyzeSyntaxCallable;
private final UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCallable;
private final UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable;
private final UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable;

private final BackgroundResource backgroundResources;
Expand Down Expand Up @@ -193,6 +206,10 @@ protected GrpcLanguageServiceStub(
GrpcCallSettings.<ClassifyTextRequest, ClassifyTextResponse>newBuilder()
.setMethodDescriptor(classifyTextMethodDescriptor)
.build();
GrpcCallSettings<ModerateTextRequest, ModerateTextResponse> moderateTextTransportSettings =
GrpcCallSettings.<ModerateTextRequest, ModerateTextResponse>newBuilder()
.setMethodDescriptor(moderateTextMethodDescriptor)
.build();
GrpcCallSettings<AnnotateTextRequest, AnnotateTextResponse> annotateTextTransportSettings =
GrpcCallSettings.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
.setMethodDescriptor(annotateTextMethodDescriptor)
Expand All @@ -215,6 +232,9 @@ protected GrpcLanguageServiceStub(
this.classifyTextCallable =
callableFactory.createUnaryCallable(
classifyTextTransportSettings, settings.classifyTextSettings(), clientContext);
this.moderateTextCallable =
callableFactory.createUnaryCallable(
moderateTextTransportSettings, settings.moderateTextSettings(), clientContext);
this.annotateTextCallable =
callableFactory.createUnaryCallable(
annotateTextTransportSettings, settings.annotateTextSettings(), clientContext);
Expand Down Expand Up @@ -254,6 +274,11 @@ public UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCall
return classifyTextCallable;
}

@Override
public UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable() {
return moderateTextCallable;
}

@Override
public UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable() {
return annotateTextCallable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import com.google.cloud.language.v1.AnnotateTextResponse;
import com.google.cloud.language.v1.ClassifyTextRequest;
import com.google.cloud.language.v1.ClassifyTextResponse;
import com.google.cloud.language.v1.ModerateTextRequest;
import com.google.cloud.language.v1.ModerateTextResponse;
import com.google.protobuf.TypeRegistry;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -242,6 +244,42 @@ public class HttpJsonLanguageServiceStub extends LanguageServiceStub {
.build())
.build();

private static final ApiMethodDescriptor<ModerateTextRequest, ModerateTextResponse>
moderateTextMethodDescriptor =
ApiMethodDescriptor.<ModerateTextRequest, ModerateTextResponse>newBuilder()
.setFullMethodName("google.cloud.language.v1.LanguageService/ModerateText")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.<ModerateTextRequest>newBuilder()
.setPath(
"/v1/documents:moderateText",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<ModerateTextRequest> serializer =
ProtoRestSerializer.create();
return fields;
})
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
ProtoRestSerializer<ModerateTextRequest> serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.<ModerateTextResponse>newBuilder()
.setDefaultInstance(ModerateTextResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();

private static final ApiMethodDescriptor<AnnotateTextRequest, AnnotateTextResponse>
annotateTextMethodDescriptor =
ApiMethodDescriptor.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
Expand Down Expand Up @@ -286,6 +324,7 @@ public class HttpJsonLanguageServiceStub extends LanguageServiceStub {
analyzeEntitySentimentCallable;
private final UnaryCallable<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse> analyzeSyntaxCallable;
private final UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCallable;
private final UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable;
private final UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable;

private final BackgroundResource backgroundResources;
Expand Down Expand Up @@ -360,6 +399,11 @@ protected HttpJsonLanguageServiceStub(
.setMethodDescriptor(classifyTextMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
HttpJsonCallSettings<ModerateTextRequest, ModerateTextResponse> moderateTextTransportSettings =
HttpJsonCallSettings.<ModerateTextRequest, ModerateTextResponse>newBuilder()
.setMethodDescriptor(moderateTextMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
HttpJsonCallSettings<AnnotateTextRequest, AnnotateTextResponse> annotateTextTransportSettings =
HttpJsonCallSettings.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
.setMethodDescriptor(annotateTextMethodDescriptor)
Expand All @@ -383,6 +427,9 @@ protected HttpJsonLanguageServiceStub(
this.classifyTextCallable =
callableFactory.createUnaryCallable(
classifyTextTransportSettings, settings.classifyTextSettings(), clientContext);
this.moderateTextCallable =
callableFactory.createUnaryCallable(
moderateTextTransportSettings, settings.moderateTextSettings(), clientContext);
this.annotateTextCallable =
callableFactory.createUnaryCallable(
annotateTextTransportSettings, settings.annotateTextSettings(), clientContext);
Expand All @@ -399,6 +446,7 @@ public static List<ApiMethodDescriptor> getMethodDescriptors() {
methodDescriptors.add(analyzeEntitySentimentMethodDescriptor);
methodDescriptors.add(analyzeSyntaxMethodDescriptor);
methodDescriptors.add(classifyTextMethodDescriptor);
methodDescriptors.add(moderateTextMethodDescriptor);
methodDescriptors.add(annotateTextMethodDescriptor);
return methodDescriptors;
}
Expand Down Expand Up @@ -430,6 +478,11 @@ public UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCall
return classifyTextCallable;
}

@Override
public UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable() {
return moderateTextCallable;
}

@Override
public UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable() {
return annotateTextCallable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.google.cloud.language.v1.AnnotateTextResponse;
import com.google.cloud.language.v1.ClassifyTextRequest;
import com.google.cloud.language.v1.ClassifyTextResponse;
import com.google.cloud.language.v1.ModerateTextRequest;
import com.google.cloud.language.v1.ModerateTextResponse;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
Expand Down Expand Up @@ -63,6 +65,10 @@ public UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCall
throw new UnsupportedOperationException("Not implemented: classifyTextCallable()");
}

public UnaryCallable<ModerateTextRequest, ModerateTextResponse> moderateTextCallable() {
throw new UnsupportedOperationException("Not implemented: moderateTextCallable()");
}

public UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable() {
throw new UnsupportedOperationException("Not implemented: annotateTextCallable()");
}
Expand Down
Loading

0 comments on commit 14fea71

Please sign in to comment.