Search in sources :

Example 1 with DatasetName

use of com.google.cloud.automl.v1.DatasetName in project java-automl by googleapis.

the class ImportDataset method importDataset.

// Import a dataset
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    Duration totalTimeout = Duration.ofMinutes(45);
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build();
    AutoMlSettings.Builder builder = AutoMlSettings.newBuilder();
    builder.importDataSettings().setRetrySettings(retrySettings).build();
    AutoMlSettings settings = builder.build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create(settings)) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        // Get multiple Google Cloud Storage URIs to import data from
        GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
        // Import data from the input URI
        InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
        System.out.println("Processing import...");
        // Start the import job
        OperationFuture<Empty, OperationMetadata> operation = client.importDataAsync(datasetFullId, inputConfig);
        System.out.format("Operation name: %s%n", operation.getName());
        // If you want to wait for the operation to finish, adjust the timeout appropriately. The
        // operation will still run if you choose not to wait for it to complete. You can check the
        // status of your operation using the operation's name.
        Empty response = operation.get(45, TimeUnit.MINUTES);
        System.out.format("Dataset imported. %s%n", response);
    } catch (TimeoutException e) {
        System.out.println("The operation's polling period was not long enough.");
        System.out.println("You can use the Operation's name to get the current status.");
        System.out.println("The import job is still running and will complete as expected.");
        throw e;
    }
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1beta1.GcsSource) DatasetName(com.google.cloud.automl.v1beta1.DatasetName) Duration(org.threeten.bp.Duration) InputConfig(com.google.cloud.automl.v1beta1.InputConfig) AutoMlSettings(com.google.cloud.automl.v1beta1.AutoMlSettings) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with DatasetName

use of com.google.cloud.automl.v1.DatasetName in project java-automl by googleapis.

the class TablesImportDataset method importDataset.

// Import a dataset via BigQuery or Google Cloud Storage
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        InputConfig.Builder inputConfigBuilder = InputConfig.newBuilder();
        // Determine which source type was used for the input path (BigQuery or GCS)
        if (path.startsWith("bq")) {
            // Get training data file to be imported from a BigQuery source.
            BigQuerySource.Builder bigQuerySource = BigQuerySource.newBuilder();
            bigQuerySource.setInputUri(path);
            inputConfigBuilder.setBigquerySource(bigQuerySource);
        } else {
            // Get multiple Google Cloud Storage URIs to import data from
            GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
            inputConfigBuilder.setGcsSource(gcsSource);
        }
        // Import data from the input URI
        System.out.println("Processing import...");
        Empty response = client.importDataAsync(datasetFullId, inputConfigBuilder.build()).get();
        System.out.format("Dataset imported. %s%n", response);
    }
}
Also used : Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1beta1.GcsSource) DatasetName(com.google.cloud.automl.v1beta1.DatasetName) InputConfig(com.google.cloud.automl.v1beta1.InputConfig) BigQuerySource(com.google.cloud.automl.v1beta1.BigQuerySource) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 3 with DatasetName

use of com.google.cloud.automl.v1.DatasetName in project java-automl by googleapis.

the class DeleteDataset method deleteDataset.

// Delete a dataset
static void deleteDataset(String projectId, String datasetId) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        Empty response = client.deleteDatasetAsync(datasetFullId).get();
        System.out.format("Dataset deleted. %s\n", response);
    }
}
Also used : Empty(com.google.protobuf.Empty) DatasetName(com.google.cloud.automl.v1.DatasetName) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 4 with DatasetName

use of com.google.cloud.automl.v1.DatasetName in project java-automl by googleapis.

the class ImportDataset method importDataset.

// Import a dataset
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        // Get multiple Google Cloud Storage URIs to import data from
        GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
        // Import data from the input URI
        InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
        System.out.println("Processing import...");
        // Start the import job
        OperationFuture<Empty, OperationMetadata> operation = client.importDataAsync(datasetFullId, inputConfig);
        System.out.format("Operation name: %s%n", operation.getName());
        // If you want to wait for the operation to finish, adjust the timeout appropriately. The
        // operation will still run if you choose not to wait for it to complete. You can check the
        // status of your operation using the operation's name.
        Empty response = operation.get(45, TimeUnit.MINUTES);
        System.out.format("Dataset imported. %s%n", response);
    } catch (TimeoutException e) {
        System.out.println("The operation's polling period was not long enough.");
        System.out.println("You can use the Operation's name to get the current status.");
        System.out.println("The import job is still running and will complete as expected.");
        throw e;
    }
}
Also used : Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1.GcsSource) DatasetName(com.google.cloud.automl.v1.DatasetName) InputConfig(com.google.cloud.automl.v1.InputConfig) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with DatasetName

use of com.google.cloud.automl.v1.DatasetName in project java-automl by googleapis.

the class DatasetApi method importData.

// [START automl_translate_import_data]
/**
 * Import sentence pairs to the dataset.
 *
 * @param projectId the Google Cloud Project ID.
 * @param computeRegion the Region name. (e.g., "us-central1").
 * @param datasetId the Id of the dataset.
 * @param path the remote Path of the training data csv file.
 */
public static void importData(String projectId, String computeRegion, String datasetId, String path) throws IOException, InterruptedException, ExecutionException {
    // Instantiates a client
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        // Get multiple Google Cloud Storage URIs to import data from
        String[] inputUris = path.split(",");
        for (String inputUri : inputUris) {
            gcsSource.addInputUris(inputUri);
        }
        // Import data from the input URI
        InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
        System.out.println("Processing import...");
        Empty response = client.importDataAsync(datasetFullId, inputConfig).get();
        System.out.println(String.format("Dataset imported. %s", response));
    }
}
Also used : Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1.GcsSource) DatasetName(com.google.cloud.automl.v1.DatasetName) InputConfig(com.google.cloud.automl.v1.InputConfig) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Aggregations

Empty (com.google.protobuf.Empty)7 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)5 DatasetName (com.google.cloud.automl.v1.DatasetName)5 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)5 DatasetName (com.google.cloud.automl.v1beta1.DatasetName)5 GcsSource (com.google.cloud.automl.v1.GcsSource)2 InputConfig (com.google.cloud.automl.v1.InputConfig)2 GcsSource (com.google.cloud.automl.v1beta1.GcsSource)2 InputConfig (com.google.cloud.automl.v1beta1.InputConfig)2 TimeoutException (java.util.concurrent.TimeoutException)2 After (org.junit.After)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 Dataset (com.google.cloud.automl.v1.Dataset)1 GcsDestination (com.google.cloud.automl.v1.GcsDestination)1 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)1 OutputConfig (com.google.cloud.automl.v1.OutputConfig)1 AutoMlSettings (com.google.cloud.automl.v1beta1.AutoMlSettings)1 BigQuerySource (com.google.cloud.automl.v1beta1.BigQuerySource)1 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)1 Duration (org.threeten.bp.Duration)1