• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.automl.v1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.httpjson.longrunning.OperationsClient;
22 import com.google.api.gax.longrunning.OperationFuture;
23 import com.google.api.gax.rpc.OperationCallable;
24 import com.google.api.gax.rpc.UnaryCallable;
25 import com.google.cloud.automl.v1.stub.PredictionServiceStub;
26 import com.google.cloud.automl.v1.stub.PredictionServiceStubSettings;
27 import com.google.longrunning.Operation;
28 import java.io.IOException;
29 import java.util.Map;
30 import java.util.concurrent.TimeUnit;
31 import javax.annotation.Generated;
32 
33 // AUTO-GENERATED DOCUMENTATION AND CLASS.
34 /**
35  * Service Description: AutoML Prediction API.
36  *
37  * <p>On any input that is documented to expect a string parameter in snake_case or dash-case,
38  * either of those cases is accepted.
39  *
40  * <p>This class provides the ability to make remote calls to the backing service through method
41  * calls that map to API methods. Sample code to get started:
42  *
43  * <pre>{@code
44  * // This snippet has been automatically generated and should be regarded as a code template only.
45  * // It will require modifications to work:
46  * // - It may require correct/in-range values for request initialization.
47  * // - It may require specifying regional endpoints when creating the service client as shown in
48  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
49  * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
50  *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
51  *   ExamplePayload payload = ExamplePayload.newBuilder().build();
52  *   Map<String, String> params = new HashMap<>();
53  *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
54  * }
55  * }</pre>
56  *
57  * <p>Note: close() needs to be called on the PredictionServiceClient object to clean up resources
58  * such as threads. In the example above, try-with-resources is used, which automatically calls
59  * close().
60  *
61  * <p>The surface of this class includes several types of Java methods for each of the API's
62  * methods:
63  *
64  * <ol>
65  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
66  *       converted into function parameters. It may be the case that not all fields are available as
67  *       parameters, and not every API method will have a flattened method entry point.
68  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
69  *       which must be constructed before the call. Not every API method will have a request object
70  *       method.
71  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
72  *       callable object, which can be used to initiate calls to the service.
73  * </ol>
74  *
75  * <p>See the individual methods for example code.
76  *
77  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
78  * these names, this class includes a format method for each type of name, and additionally a parse
79  * method to extract the individual identifiers contained within names that are returned.
80  *
81  * <p>This class can be customized by passing in a custom instance of PredictionServiceSettings to
82  * create(). For example:
83  *
84  * <p>To customize credentials:
85  *
86  * <pre>{@code
87  * // This snippet has been automatically generated and should be regarded as a code template only.
88  * // It will require modifications to work:
89  * // - It may require correct/in-range values for request initialization.
90  * // - It may require specifying regional endpoints when creating the service client as shown in
91  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
92  * PredictionServiceSettings predictionServiceSettings =
93  *     PredictionServiceSettings.newBuilder()
94  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
95  *         .build();
96  * PredictionServiceClient predictionServiceClient =
97  *     PredictionServiceClient.create(predictionServiceSettings);
98  * }</pre>
99  *
100  * <p>To customize the endpoint:
101  *
102  * <pre>{@code
103  * // This snippet has been automatically generated and should be regarded as a code template only.
104  * // It will require modifications to work:
105  * // - It may require correct/in-range values for request initialization.
106  * // - It may require specifying regional endpoints when creating the service client as shown in
107  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
108  * PredictionServiceSettings predictionServiceSettings =
109  *     PredictionServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
110  * PredictionServiceClient predictionServiceClient =
111  *     PredictionServiceClient.create(predictionServiceSettings);
112  * }</pre>
113  *
114  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
115  * the wire:
116  *
117  * <pre>{@code
118  * // This snippet has been automatically generated and should be regarded as a code template only.
119  * // It will require modifications to work:
120  * // - It may require correct/in-range values for request initialization.
121  * // - It may require specifying regional endpoints when creating the service client as shown in
122  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
123  * PredictionServiceSettings predictionServiceSettings =
124  *     PredictionServiceSettings.newHttpJsonBuilder().build();
125  * PredictionServiceClient predictionServiceClient =
126  *     PredictionServiceClient.create(predictionServiceSettings);
127  * }</pre>
128  *
129  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
130  */
131 @Generated("by gapic-generator-java")
132 public class PredictionServiceClient implements BackgroundResource {
133   private final PredictionServiceSettings settings;
134   private final PredictionServiceStub stub;
135   private final OperationsClient httpJsonOperationsClient;
136   private final com.google.longrunning.OperationsClient operationsClient;
137 
138   /** Constructs an instance of PredictionServiceClient with default settings. */
create()139   public static final PredictionServiceClient create() throws IOException {
140     return create(PredictionServiceSettings.newBuilder().build());
141   }
142 
143   /**
144    * Constructs an instance of PredictionServiceClient, using the given settings. The channels are
145    * created based on the settings passed in, or defaults for any settings that are not set.
146    */
create(PredictionServiceSettings settings)147   public static final PredictionServiceClient create(PredictionServiceSettings settings)
148       throws IOException {
149     return new PredictionServiceClient(settings);
150   }
151 
152   /**
153    * Constructs an instance of PredictionServiceClient, using the given stub for making calls. This
154    * is for advanced usage - prefer using create(PredictionServiceSettings).
155    */
create(PredictionServiceStub stub)156   public static final PredictionServiceClient create(PredictionServiceStub stub) {
157     return new PredictionServiceClient(stub);
158   }
159 
160   /**
161    * Constructs an instance of PredictionServiceClient, using the given settings. This is protected
162    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
163    * preferred.
164    */
PredictionServiceClient(PredictionServiceSettings settings)165   protected PredictionServiceClient(PredictionServiceSettings settings) throws IOException {
166     this.settings = settings;
167     this.stub = ((PredictionServiceStubSettings) settings.getStubSettings()).createStub();
168     this.operationsClient =
169         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
170     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
171   }
172 
PredictionServiceClient(PredictionServiceStub stub)173   protected PredictionServiceClient(PredictionServiceStub stub) {
174     this.settings = null;
175     this.stub = stub;
176     this.operationsClient =
177         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
178     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
179   }
180 
getSettings()181   public final PredictionServiceSettings getSettings() {
182     return settings;
183   }
184 
getStub()185   public PredictionServiceStub getStub() {
186     return stub;
187   }
188 
189   /**
190    * Returns the OperationsClient that can be used to query the status of a long-running operation
191    * returned by another API method call.
192    */
getOperationsClient()193   public final com.google.longrunning.OperationsClient getOperationsClient() {
194     return operationsClient;
195   }
196 
197   /**
198    * Returns the OperationsClient that can be used to query the status of a long-running operation
199    * returned by another API method call.
200    */
201   @BetaApi
getHttpJsonOperationsClient()202   public final OperationsClient getHttpJsonOperationsClient() {
203     return httpJsonOperationsClient;
204   }
205 
206   // AUTO-GENERATED DOCUMENTATION AND METHOD.
207   /**
208    * Perform an online prediction. The prediction result is directly returned in the response.
209    * Available for following ML scenarios, and their expected request payloads:
210    *
211    * <p>AutoML Vision Classification
212    *
213    * <ul>
214    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
215    * </ul>
216    *
217    * <p>AutoML Vision Object Detection
218    *
219    * <ul>
220    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
221    * </ul>
222    *
223    * <p>AutoML Natural Language Classification
224    *
225    * <ul>
226    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
227    *       format with size upto 2MB.
228    * </ul>
229    *
230    * <p>AutoML Natural Language Entity Extraction
231    *
232    * <ul>
233    *   <li>A TextSnippet up to 10,000 characters, UTF-8 NFC encoded or a document in .PDF, .TIF or
234    *       .TIFF format with size upto 20MB.
235    * </ul>
236    *
237    * <p>AutoML Natural Language Sentiment Analysis
238    *
239    * <ul>
240    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
241    *       format with size upto 2MB.
242    * </ul>
243    *
244    * <p>AutoML Translation
245    *
246    * <ul>
247    *   <li>A TextSnippet up to 25,000 characters, UTF-8 encoded.
248    * </ul>
249    *
250    * <p>AutoML Tables
251    *
252    * <ul>
253    *   <li>A row with column values matching the columns of the model, up to 5MB. Not available for
254    *       FORECASTING `prediction_type`.
255    * </ul>
256    *
257    * <p>Sample code:
258    *
259    * <pre>{@code
260    * // This snippet has been automatically generated and should be regarded as a code template only.
261    * // It will require modifications to work:
262    * // - It may require correct/in-range values for request initialization.
263    * // - It may require specifying regional endpoints when creating the service client as shown in
264    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
265    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
266    *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
267    *   ExamplePayload payload = ExamplePayload.newBuilder().build();
268    *   Map<String, String> params = new HashMap<>();
269    *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
270    * }
271    * }</pre>
272    *
273    * @param name Required. Name of the model requested to serve the prediction.
274    * @param payload Required. Payload to perform a prediction on. The payload must match the problem
275    *     type that the model was trained to solve.
276    * @param params Additional domain-specific parameters, any string must be up to 25000 characters
277    *     long.
278    *     <p>AutoML Vision Classification
279    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
280    *     for an image, it will only produce results that have at least this confidence score. The
281    *     default is 0.5.
282    *     <p>AutoML Vision Object Detection
283    *     <p>`score_threshold` : (float) When Model detects objects on the image, it will only
284    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
285    *     default is 0.5.
286    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned. The
287    *     default is 100. The number of returned bounding boxes might be limited by the server.
288    *     <p>AutoML Tables
289    *     <p>`feature_importance` : (boolean) Whether
290    *     [feature_importance][google.cloud.automl.v1.TablesModelColumnInfo.feature_importance] is
291    *     populated in the returned list of
292    *     [TablesAnnotation][google.cloud.automl.v1.TablesAnnotation] objects. The default is false.
293    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
294    */
predict( ModelName name, ExamplePayload payload, Map<String, String> params)295   public final PredictResponse predict(
296       ModelName name, ExamplePayload payload, Map<String, String> params) {
297     PredictRequest request =
298         PredictRequest.newBuilder()
299             .setName(name == null ? null : name.toString())
300             .setPayload(payload)
301             .putAllParams(params)
302             .build();
303     return predict(request);
304   }
305 
306   // AUTO-GENERATED DOCUMENTATION AND METHOD.
307   /**
308    * Perform an online prediction. The prediction result is directly returned in the response.
309    * Available for following ML scenarios, and their expected request payloads:
310    *
311    * <p>AutoML Vision Classification
312    *
313    * <ul>
314    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
315    * </ul>
316    *
317    * <p>AutoML Vision Object Detection
318    *
319    * <ul>
320    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
321    * </ul>
322    *
323    * <p>AutoML Natural Language Classification
324    *
325    * <ul>
326    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
327    *       format with size upto 2MB.
328    * </ul>
329    *
330    * <p>AutoML Natural Language Entity Extraction
331    *
332    * <ul>
333    *   <li>A TextSnippet up to 10,000 characters, UTF-8 NFC encoded or a document in .PDF, .TIF or
334    *       .TIFF format with size upto 20MB.
335    * </ul>
336    *
337    * <p>AutoML Natural Language Sentiment Analysis
338    *
339    * <ul>
340    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
341    *       format with size upto 2MB.
342    * </ul>
343    *
344    * <p>AutoML Translation
345    *
346    * <ul>
347    *   <li>A TextSnippet up to 25,000 characters, UTF-8 encoded.
348    * </ul>
349    *
350    * <p>AutoML Tables
351    *
352    * <ul>
353    *   <li>A row with column values matching the columns of the model, up to 5MB. Not available for
354    *       FORECASTING `prediction_type`.
355    * </ul>
356    *
357    * <p>Sample code:
358    *
359    * <pre>{@code
360    * // This snippet has been automatically generated and should be regarded as a code template only.
361    * // It will require modifications to work:
362    * // - It may require correct/in-range values for request initialization.
363    * // - It may require specifying regional endpoints when creating the service client as shown in
364    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
365    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
366    *   String name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString();
367    *   ExamplePayload payload = ExamplePayload.newBuilder().build();
368    *   Map<String, String> params = new HashMap<>();
369    *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
370    * }
371    * }</pre>
372    *
373    * @param name Required. Name of the model requested to serve the prediction.
374    * @param payload Required. Payload to perform a prediction on. The payload must match the problem
375    *     type that the model was trained to solve.
376    * @param params Additional domain-specific parameters, any string must be up to 25000 characters
377    *     long.
378    *     <p>AutoML Vision Classification
379    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
380    *     for an image, it will only produce results that have at least this confidence score. The
381    *     default is 0.5.
382    *     <p>AutoML Vision Object Detection
383    *     <p>`score_threshold` : (float) When Model detects objects on the image, it will only
384    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
385    *     default is 0.5.
386    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned. The
387    *     default is 100. The number of returned bounding boxes might be limited by the server.
388    *     <p>AutoML Tables
389    *     <p>`feature_importance` : (boolean) Whether
390    *     [feature_importance][google.cloud.automl.v1.TablesModelColumnInfo.feature_importance] is
391    *     populated in the returned list of
392    *     [TablesAnnotation][google.cloud.automl.v1.TablesAnnotation] objects. The default is false.
393    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
394    */
predict( String name, ExamplePayload payload, Map<String, String> params)395   public final PredictResponse predict(
396       String name, ExamplePayload payload, Map<String, String> params) {
397     PredictRequest request =
398         PredictRequest.newBuilder().setName(name).setPayload(payload).putAllParams(params).build();
399     return predict(request);
400   }
401 
402   // AUTO-GENERATED DOCUMENTATION AND METHOD.
403   /**
404    * Perform an online prediction. The prediction result is directly returned in the response.
405    * Available for following ML scenarios, and their expected request payloads:
406    *
407    * <p>AutoML Vision Classification
408    *
409    * <ul>
410    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
411    * </ul>
412    *
413    * <p>AutoML Vision Object Detection
414    *
415    * <ul>
416    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
417    * </ul>
418    *
419    * <p>AutoML Natural Language Classification
420    *
421    * <ul>
422    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
423    *       format with size upto 2MB.
424    * </ul>
425    *
426    * <p>AutoML Natural Language Entity Extraction
427    *
428    * <ul>
429    *   <li>A TextSnippet up to 10,000 characters, UTF-8 NFC encoded or a document in .PDF, .TIF or
430    *       .TIFF format with size upto 20MB.
431    * </ul>
432    *
433    * <p>AutoML Natural Language Sentiment Analysis
434    *
435    * <ul>
436    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
437    *       format with size upto 2MB.
438    * </ul>
439    *
440    * <p>AutoML Translation
441    *
442    * <ul>
443    *   <li>A TextSnippet up to 25,000 characters, UTF-8 encoded.
444    * </ul>
445    *
446    * <p>AutoML Tables
447    *
448    * <ul>
449    *   <li>A row with column values matching the columns of the model, up to 5MB. Not available for
450    *       FORECASTING `prediction_type`.
451    * </ul>
452    *
453    * <p>Sample code:
454    *
455    * <pre>{@code
456    * // This snippet has been automatically generated and should be regarded as a code template only.
457    * // It will require modifications to work:
458    * // - It may require correct/in-range values for request initialization.
459    * // - It may require specifying regional endpoints when creating the service client as shown in
460    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
461    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
462    *   PredictRequest request =
463    *       PredictRequest.newBuilder()
464    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
465    *           .setPayload(ExamplePayload.newBuilder().build())
466    *           .putAllParams(new HashMap<String, String>())
467    *           .build();
468    *   PredictResponse response = predictionServiceClient.predict(request);
469    * }
470    * }</pre>
471    *
472    * @param request The request object containing all of the parameters for the API call.
473    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
474    */
predict(PredictRequest request)475   public final PredictResponse predict(PredictRequest request) {
476     return predictCallable().call(request);
477   }
478 
479   // AUTO-GENERATED DOCUMENTATION AND METHOD.
480   /**
481    * Perform an online prediction. The prediction result is directly returned in the response.
482    * Available for following ML scenarios, and their expected request payloads:
483    *
484    * <p>AutoML Vision Classification
485    *
486    * <ul>
487    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
488    * </ul>
489    *
490    * <p>AutoML Vision Object Detection
491    *
492    * <ul>
493    *   <li>An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
494    * </ul>
495    *
496    * <p>AutoML Natural Language Classification
497    *
498    * <ul>
499    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
500    *       format with size upto 2MB.
501    * </ul>
502    *
503    * <p>AutoML Natural Language Entity Extraction
504    *
505    * <ul>
506    *   <li>A TextSnippet up to 10,000 characters, UTF-8 NFC encoded or a document in .PDF, .TIF or
507    *       .TIFF format with size upto 20MB.
508    * </ul>
509    *
510    * <p>AutoML Natural Language Sentiment Analysis
511    *
512    * <ul>
513    *   <li>A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF
514    *       format with size upto 2MB.
515    * </ul>
516    *
517    * <p>AutoML Translation
518    *
519    * <ul>
520    *   <li>A TextSnippet up to 25,000 characters, UTF-8 encoded.
521    * </ul>
522    *
523    * <p>AutoML Tables
524    *
525    * <ul>
526    *   <li>A row with column values matching the columns of the model, up to 5MB. Not available for
527    *       FORECASTING `prediction_type`.
528    * </ul>
529    *
530    * <p>Sample code:
531    *
532    * <pre>{@code
533    * // This snippet has been automatically generated and should be regarded as a code template only.
534    * // It will require modifications to work:
535    * // - It may require correct/in-range values for request initialization.
536    * // - It may require specifying regional endpoints when creating the service client as shown in
537    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
538    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
539    *   PredictRequest request =
540    *       PredictRequest.newBuilder()
541    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
542    *           .setPayload(ExamplePayload.newBuilder().build())
543    *           .putAllParams(new HashMap<String, String>())
544    *           .build();
545    *   ApiFuture<PredictResponse> future =
546    *       predictionServiceClient.predictCallable().futureCall(request);
547    *   // Do something.
548    *   PredictResponse response = future.get();
549    * }
550    * }</pre>
551    */
predictCallable()552   public final UnaryCallable<PredictRequest, PredictResponse> predictCallable() {
553     return stub.predictCallable();
554   }
555 
556   // AUTO-GENERATED DOCUMENTATION AND METHOD.
557   /**
558    * Perform a batch prediction. Unlike the online
559    * [Predict][google.cloud.automl.v1.PredictionService.Predict], batch prediction result won't be
560    * immediately available in the response. Instead, a long running operation object is returned.
561    * User can poll the operation result via
562    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
563    * [BatchPredictResult][google.cloud.automl.v1.BatchPredictResult] is returned in the
564    * [response][google.longrunning.Operation.response] field. Available for following ML scenarios:
565    *
566    * <ul>
567    *   <li>AutoML Vision Classification
568    *   <li>AutoML Vision Object Detection
569    *   <li>AutoML Video Intelligence Classification
570    *   <li>AutoML Video Intelligence Object Tracking &#42; AutoML Natural Language Classification
571    *   <li>AutoML Natural Language Entity Extraction
572    *   <li>AutoML Natural Language Sentiment Analysis
573    *   <li>AutoML Tables
574    * </ul>
575    *
576    * <p>Sample code:
577    *
578    * <pre>{@code
579    * // This snippet has been automatically generated and should be regarded as a code template only.
580    * // It will require modifications to work:
581    * // - It may require correct/in-range values for request initialization.
582    * // - It may require specifying regional endpoints when creating the service client as shown in
583    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
584    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
585    *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
586    *   BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().build();
587    *   BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().build();
588    *   Map<String, String> params = new HashMap<>();
589    *   BatchPredictResult response =
590    *       predictionServiceClient.batchPredictAsync(name, inputConfig, outputConfig, params).get();
591    * }
592    * }</pre>
593    *
594    * @param name Required. Name of the model requested to serve the batch prediction.
595    * @param inputConfig Required. The input configuration for batch prediction.
596    * @param outputConfig Required. The Configuration specifying where output predictions should be
597    *     written.
598    * @param params Additional domain-specific parameters for the predictions, any string must be up
599    *     to 25000 characters long.
600    *     <p>AutoML Natural Language Classification
601    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
602    *     for a text snippet, it will only produce results that have at least this confidence score.
603    *     The default is 0.5.
604    *     <p>AutoML Vision Classification
605    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
606    *     for an image, it will only produce results that have at least this confidence score. The
607    *     default is 0.5.
608    *     <p>AutoML Vision Object Detection
609    *     <p>`score_threshold` : (float) When Model detects objects on the image, it will only
610    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
611    *     default is 0.5.
612    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned per
613    *     image. The default is 100, the number of bounding boxes returned might be limited by the
614    *     server. AutoML Video Intelligence Classification
615    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
616    *     for a video, it will only produce results that have at least this confidence score. The
617    *     default is 0.5.
618    *     <p>`segment_classification` : (boolean) Set to true to request segment-level
619    *     classification. AutoML Video Intelligence returns labels and their confidence scores for
620    *     the entire segment of the video that user specified in the request configuration. The
621    *     default is true.
622    *     <p>`shot_classification` : (boolean) Set to true to request shot-level classification.
623    *     AutoML Video Intelligence determines the boundaries for each camera shot in the entire
624    *     segment of the video that user specified in the request configuration. AutoML Video
625    *     Intelligence then returns labels and their confidence scores for each detected shot, along
626    *     with the start and end time of the shot. The default is false.
627    *     <p>WARNING: Model evaluation is not done for this classification type, the quality of it
628    *     depends on training data, but there are no metrics provided to describe that quality.
629    *     <p>`1s_interval_classification` : (boolean) Set to true to request classification for a
630    *     video at one-second intervals. AutoML Video Intelligence returns labels and their
631    *     confidence scores for each second of the entire segment of the video that user specified in
632    *     the request configuration. The default is false.
633    *     <p>WARNING: Model evaluation is not done for this classification type, the quality of it
634    *     depends on training data, but there are no metrics provided to describe that quality.
635    *     <p>AutoML Video Intelligence Object Tracking
636    *     <p>`score_threshold` : (float) When Model detects objects on video frames, it will only
637    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
638    *     default is 0.5.
639    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned per
640    *     image. The default is 100, the number of bounding boxes returned might be limited by the
641    *     server.
642    *     <p>`min_bounding_box_size` : (float) Only bounding boxes with shortest edge at least that
643    *     long as a relative value of video frame size are returned. Value in 0 to 1 range. Default
644    *     is 0.
645    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
646    */
batchPredictAsync( ModelName name, BatchPredictInputConfig inputConfig, BatchPredictOutputConfig outputConfig, Map<String, String> params)647   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
648       ModelName name,
649       BatchPredictInputConfig inputConfig,
650       BatchPredictOutputConfig outputConfig,
651       Map<String, String> params) {
652     BatchPredictRequest request =
653         BatchPredictRequest.newBuilder()
654             .setName(name == null ? null : name.toString())
655             .setInputConfig(inputConfig)
656             .setOutputConfig(outputConfig)
657             .putAllParams(params)
658             .build();
659     return batchPredictAsync(request);
660   }
661 
662   // AUTO-GENERATED DOCUMENTATION AND METHOD.
663   /**
664    * Perform a batch prediction. Unlike the online
665    * [Predict][google.cloud.automl.v1.PredictionService.Predict], batch prediction result won't be
666    * immediately available in the response. Instead, a long running operation object is returned.
667    * User can poll the operation result via
668    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
669    * [BatchPredictResult][google.cloud.automl.v1.BatchPredictResult] is returned in the
670    * [response][google.longrunning.Operation.response] field. Available for following ML scenarios:
671    *
672    * <ul>
673    *   <li>AutoML Vision Classification
674    *   <li>AutoML Vision Object Detection
675    *   <li>AutoML Video Intelligence Classification
676    *   <li>AutoML Video Intelligence Object Tracking &#42; AutoML Natural Language Classification
677    *   <li>AutoML Natural Language Entity Extraction
678    *   <li>AutoML Natural Language Sentiment Analysis
679    *   <li>AutoML Tables
680    * </ul>
681    *
682    * <p>Sample code:
683    *
684    * <pre>{@code
685    * // This snippet has been automatically generated and should be regarded as a code template only.
686    * // It will require modifications to work:
687    * // - It may require correct/in-range values for request initialization.
688    * // - It may require specifying regional endpoints when creating the service client as shown in
689    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
690    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
691    *   String name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString();
692    *   BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().build();
693    *   BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().build();
694    *   Map<String, String> params = new HashMap<>();
695    *   BatchPredictResult response =
696    *       predictionServiceClient.batchPredictAsync(name, inputConfig, outputConfig, params).get();
697    * }
698    * }</pre>
699    *
700    * @param name Required. Name of the model requested to serve the batch prediction.
701    * @param inputConfig Required. The input configuration for batch prediction.
702    * @param outputConfig Required. The Configuration specifying where output predictions should be
703    *     written.
704    * @param params Additional domain-specific parameters for the predictions, any string must be up
705    *     to 25000 characters long.
706    *     <p>AutoML Natural Language Classification
707    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
708    *     for a text snippet, it will only produce results that have at least this confidence score.
709    *     The default is 0.5.
710    *     <p>AutoML Vision Classification
711    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
712    *     for an image, it will only produce results that have at least this confidence score. The
713    *     default is 0.5.
714    *     <p>AutoML Vision Object Detection
715    *     <p>`score_threshold` : (float) When Model detects objects on the image, it will only
716    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
717    *     default is 0.5.
718    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned per
719    *     image. The default is 100, the number of bounding boxes returned might be limited by the
720    *     server. AutoML Video Intelligence Classification
721    *     <p>`score_threshold` : (float) A value from 0.0 to 1.0. When the model makes predictions
722    *     for a video, it will only produce results that have at least this confidence score. The
723    *     default is 0.5.
724    *     <p>`segment_classification` : (boolean) Set to true to request segment-level
725    *     classification. AutoML Video Intelligence returns labels and their confidence scores for
726    *     the entire segment of the video that user specified in the request configuration. The
727    *     default is true.
728    *     <p>`shot_classification` : (boolean) Set to true to request shot-level classification.
729    *     AutoML Video Intelligence determines the boundaries for each camera shot in the entire
730    *     segment of the video that user specified in the request configuration. AutoML Video
731    *     Intelligence then returns labels and their confidence scores for each detected shot, along
732    *     with the start and end time of the shot. The default is false.
733    *     <p>WARNING: Model evaluation is not done for this classification type, the quality of it
734    *     depends on training data, but there are no metrics provided to describe that quality.
735    *     <p>`1s_interval_classification` : (boolean) Set to true to request classification for a
736    *     video at one-second intervals. AutoML Video Intelligence returns labels and their
737    *     confidence scores for each second of the entire segment of the video that user specified in
738    *     the request configuration. The default is false.
739    *     <p>WARNING: Model evaluation is not done for this classification type, the quality of it
740    *     depends on training data, but there are no metrics provided to describe that quality.
741    *     <p>AutoML Video Intelligence Object Tracking
742    *     <p>`score_threshold` : (float) When Model detects objects on video frames, it will only
743    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
744    *     default is 0.5.
745    *     <p>`max_bounding_box_count` : (int64) The maximum number of bounding boxes returned per
746    *     image. The default is 100, the number of bounding boxes returned might be limited by the
747    *     server.
748    *     <p>`min_bounding_box_size` : (float) Only bounding boxes with shortest edge at least that
749    *     long as a relative value of video frame size are returned. Value in 0 to 1 range. Default
750    *     is 0.
751    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
752    */
batchPredictAsync( String name, BatchPredictInputConfig inputConfig, BatchPredictOutputConfig outputConfig, Map<String, String> params)753   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
754       String name,
755       BatchPredictInputConfig inputConfig,
756       BatchPredictOutputConfig outputConfig,
757       Map<String, String> params) {
758     BatchPredictRequest request =
759         BatchPredictRequest.newBuilder()
760             .setName(name)
761             .setInputConfig(inputConfig)
762             .setOutputConfig(outputConfig)
763             .putAllParams(params)
764             .build();
765     return batchPredictAsync(request);
766   }
767 
768   // AUTO-GENERATED DOCUMENTATION AND METHOD.
769   /**
770    * Perform a batch prediction. Unlike the online
771    * [Predict][google.cloud.automl.v1.PredictionService.Predict], batch prediction result won't be
772    * immediately available in the response. Instead, a long running operation object is returned.
773    * User can poll the operation result via
774    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
775    * [BatchPredictResult][google.cloud.automl.v1.BatchPredictResult] is returned in the
776    * [response][google.longrunning.Operation.response] field. Available for following ML scenarios:
777    *
778    * <ul>
779    *   <li>AutoML Vision Classification
780    *   <li>AutoML Vision Object Detection
781    *   <li>AutoML Video Intelligence Classification
782    *   <li>AutoML Video Intelligence Object Tracking &#42; AutoML Natural Language Classification
783    *   <li>AutoML Natural Language Entity Extraction
784    *   <li>AutoML Natural Language Sentiment Analysis
785    *   <li>AutoML Tables
786    * </ul>
787    *
788    * <p>Sample code:
789    *
790    * <pre>{@code
791    * // This snippet has been automatically generated and should be regarded as a code template only.
792    * // It will require modifications to work:
793    * // - It may require correct/in-range values for request initialization.
794    * // - It may require specifying regional endpoints when creating the service client as shown in
795    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
796    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
797    *   BatchPredictRequest request =
798    *       BatchPredictRequest.newBuilder()
799    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
800    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
801    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
802    *           .putAllParams(new HashMap<String, String>())
803    *           .build();
804    *   BatchPredictResult response = predictionServiceClient.batchPredictAsync(request).get();
805    * }
806    * }</pre>
807    *
808    * @param request The request object containing all of the parameters for the API call.
809    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
810    */
batchPredictAsync( BatchPredictRequest request)811   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
812       BatchPredictRequest request) {
813     return batchPredictOperationCallable().futureCall(request);
814   }
815 
816   // AUTO-GENERATED DOCUMENTATION AND METHOD.
817   /**
818    * Perform a batch prediction. Unlike the online
819    * [Predict][google.cloud.automl.v1.PredictionService.Predict], batch prediction result won't be
820    * immediately available in the response. Instead, a long running operation object is returned.
821    * User can poll the operation result via
822    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
823    * [BatchPredictResult][google.cloud.automl.v1.BatchPredictResult] is returned in the
824    * [response][google.longrunning.Operation.response] field. Available for following ML scenarios:
825    *
826    * <ul>
827    *   <li>AutoML Vision Classification
828    *   <li>AutoML Vision Object Detection
829    *   <li>AutoML Video Intelligence Classification
830    *   <li>AutoML Video Intelligence Object Tracking &#42; AutoML Natural Language Classification
831    *   <li>AutoML Natural Language Entity Extraction
832    *   <li>AutoML Natural Language Sentiment Analysis
833    *   <li>AutoML Tables
834    * </ul>
835    *
836    * <p>Sample code:
837    *
838    * <pre>{@code
839    * // This snippet has been automatically generated and should be regarded as a code template only.
840    * // It will require modifications to work:
841    * // - It may require correct/in-range values for request initialization.
842    * // - It may require specifying regional endpoints when creating the service client as shown in
843    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
844    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
845    *   BatchPredictRequest request =
846    *       BatchPredictRequest.newBuilder()
847    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
848    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
849    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
850    *           .putAllParams(new HashMap<String, String>())
851    *           .build();
852    *   OperationFuture<BatchPredictResult, OperationMetadata> future =
853    *       predictionServiceClient.batchPredictOperationCallable().futureCall(request);
854    *   // Do something.
855    *   BatchPredictResult response = future.get();
856    * }
857    * }</pre>
858    */
859   public final OperationCallable<BatchPredictRequest, BatchPredictResult, OperationMetadata>
batchPredictOperationCallable()860       batchPredictOperationCallable() {
861     return stub.batchPredictOperationCallable();
862   }
863 
864   // AUTO-GENERATED DOCUMENTATION AND METHOD.
865   /**
866    * Perform a batch prediction. Unlike the online
867    * [Predict][google.cloud.automl.v1.PredictionService.Predict], batch prediction result won't be
868    * immediately available in the response. Instead, a long running operation object is returned.
869    * User can poll the operation result via
870    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
871    * [BatchPredictResult][google.cloud.automl.v1.BatchPredictResult] is returned in the
872    * [response][google.longrunning.Operation.response] field. Available for following ML scenarios:
873    *
874    * <ul>
875    *   <li>AutoML Vision Classification
876    *   <li>AutoML Vision Object Detection
877    *   <li>AutoML Video Intelligence Classification
878    *   <li>AutoML Video Intelligence Object Tracking &#42; AutoML Natural Language Classification
879    *   <li>AutoML Natural Language Entity Extraction
880    *   <li>AutoML Natural Language Sentiment Analysis
881    *   <li>AutoML Tables
882    * </ul>
883    *
884    * <p>Sample code:
885    *
886    * <pre>{@code
887    * // This snippet has been automatically generated and should be regarded as a code template only.
888    * // It will require modifications to work:
889    * // - It may require correct/in-range values for request initialization.
890    * // - It may require specifying regional endpoints when creating the service client as shown in
891    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
892    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
893    *   BatchPredictRequest request =
894    *       BatchPredictRequest.newBuilder()
895    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
896    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
897    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
898    *           .putAllParams(new HashMap<String, String>())
899    *           .build();
900    *   ApiFuture<Operation> future =
901    *       predictionServiceClient.batchPredictCallable().futureCall(request);
902    *   // Do something.
903    *   Operation response = future.get();
904    * }
905    * }</pre>
906    */
batchPredictCallable()907   public final UnaryCallable<BatchPredictRequest, Operation> batchPredictCallable() {
908     return stub.batchPredictCallable();
909   }
910 
911   @Override
close()912   public final void close() {
913     stub.close();
914   }
915 
916   @Override
shutdown()917   public void shutdown() {
918     stub.shutdown();
919   }
920 
921   @Override
isShutdown()922   public boolean isShutdown() {
923     return stub.isShutdown();
924   }
925 
926   @Override
isTerminated()927   public boolean isTerminated() {
928     return stub.isTerminated();
929   }
930 
931   @Override
shutdownNow()932   public void shutdownNow() {
933     stub.shutdownNow();
934   }
935 
936   @Override
awaitTermination(long duration, TimeUnit unit)937   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
938     return stub.awaitTermination(duration, unit);
939   }
940 }
941