Search in sources :

Example 1 with ListDatasetsRequest

use of com.google.cloud.automl.v1beta1.ListDatasetsRequest in project java-automl by googleapis.

the class AutoMlClientTest method listDatasetsTest2.

@Test
public void listDatasetsTest2() throws Exception {
    Dataset responsesElement = Dataset.newBuilder().build();
    ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
    mockAutoMl.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent);
    List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDatasetsPagedResponse(com.google.cloud.automl.v1beta1.AutoMlClient.ListDatasetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with ListDatasetsRequest

use of com.google.cloud.automl.v1beta1.ListDatasetsRequest in project java-automl by googleapis.

the class AutoMlClientTest method listDatasetsTest.

@Test
public void listDatasetsTest() throws Exception {
    Dataset responsesElement = Dataset.newBuilder().build();
    ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
    mockAutoMl.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent);
    List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDatasetsPagedResponse(com.google.cloud.automl.v1beta1.AutoMlClient.ListDatasetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with ListDatasetsRequest

use of com.google.cloud.automl.v1beta1.ListDatasetsRequest in project java-automl by googleapis.

the class ListDatasets method listDatasets.

// List the datasets
static void listDatasets(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        ListDatasetsRequest request = ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build();
        // List all the datasets available in the region by applying filter.
        System.out.println("List of datasets:");
        for (Dataset dataset : client.listDatasets(request).iterateAll()) {
            // Display the dataset information
            System.out.format("%nDataset name: %s%n", dataset.getName());
            // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
            // required for other methods.
            // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
            String[] names = dataset.getName().split("/");
            String retrievedDatasetId = names[names.length - 1];
            System.out.format("Dataset id: %s%n", retrievedDatasetId);
            System.out.format("Dataset display name: %s%n", dataset.getDisplayName());
            System.out.println("Dataset create time:");
            System.out.format("\tseconds: %s%n", dataset.getCreateTime().getSeconds());
            System.out.format("\tnanos: %s%n", dataset.getCreateTime().getNanos());
            // [END automl_video_object_tracking_list_datasets_beta]
            // [END automl_tables_list_datasets]
            System.out.format("Video classification dataset metadata: %s%n", dataset.getVideoClassificationDatasetMetadata());
            // [END automl_video_classification_list_datasets_beta]
            // [START automl_video_object_tracking_list_datasets_beta]
            System.out.format("Video object tracking dataset metadata: %s%n", dataset.getVideoObjectTrackingDatasetMetadata());
            // [END automl_video_object_tracking_list_datasets_beta]
            // [START automl_tables_list_datasets]
            System.out.format("Tables dataset metadata: %s%n", dataset.getTablesDatasetMetadata());
        // [START automl_video_classification_list_datasets_beta]
        // [START automl_video_object_tracking_list_datasets_beta]
        }
    }
}
Also used : Dataset(com.google.cloud.automl.v1beta1.Dataset) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName) ListDatasetsRequest(com.google.cloud.automl.v1beta1.ListDatasetsRequest)

Example 4 with ListDatasetsRequest

use of com.google.cloud.automl.v1beta1.ListDatasetsRequest in project java-automl by googleapis.

the class ListDatasets method listDatasets.

// List the datasets
static void listDatasets(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        ListDatasetsRequest request = ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build();
        // List all the datasets available in the region by applying filter.
        System.out.println("List of datasets:");
        for (Dataset dataset : client.listDatasets(request).iterateAll()) {
            // Display the dataset information
            System.out.format("\nDataset name: %s\n", dataset.getName());
            // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
            // required for other methods.
            // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
            String[] names = dataset.getName().split("/");
            String retrievedDatasetId = names[names.length - 1];
            System.out.format("Dataset id: %s\n", retrievedDatasetId);
            System.out.format("Dataset display name: %s\n", dataset.getDisplayName());
            System.out.println("Dataset create time:");
            System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds());
            System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos());
            // [END automl_language_sentiment_analysis_list_datasets]
            // [END automl_language_text_classification_list_datasets]
            // [END automl_translate_list_datasets]
            // [END automl_vision_classification_list_datasets]
            // [END automl_vision_object_detection_list_datasets]
            System.out.format("Text extraction dataset metadata: %s\n", dataset.getTextExtractionDatasetMetadata());
            // [END automl_language_entity_extraction_list_datasets]
            // [START automl_language_sentiment_analysis_list_datasets]
            System.out.format("Text sentiment dataset metadata: %s\n", dataset.getTextSentimentDatasetMetadata());
            // [END automl_language_sentiment_analysis_list_datasets]
            // [START automl_language_text_classification_list_datasets]
            System.out.format("Text classification dataset metadata: %s\n", dataset.getTextClassificationDatasetMetadata());
            // [END automl_language_text_classification_list_datasets]
            // [START automl_translate_list_datasets]
            System.out.println("Translation dataset metadata:");
            System.out.format("\tSource language code: %s\n", dataset.getTranslationDatasetMetadata().getSourceLanguageCode());
            System.out.format("\tTarget language code: %s\n", dataset.getTranslationDatasetMetadata().getTargetLanguageCode());
            // [END automl_translate_list_datasets]
            // [START automl_vision_classification_list_datasets]
            System.out.format("Image classification dataset metadata: %s\n", dataset.getImageClassificationDatasetMetadata());
            // [END automl_vision_classification_list_datasets]
            // [START automl_vision_object_detection_list_datasets]
            System.out.format("Image object detection dataset metadata: %s\n", dataset.getImageObjectDetectionDatasetMetadata());
        // [START automl_language_entity_extraction_list_datasets]
        // [START automl_language_sentiment_analysis_list_datasets]
        // [START automl_language_text_classification_list_datasets]
        // [START automl_translate_list_datasets]
        // [START automl_vision_classification_list_datasets]
        }
    }
}
Also used : Dataset(com.google.cloud.automl.v1.Dataset) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName) ListDatasetsRequest(com.google.cloud.automl.v1.ListDatasetsRequest)

Example 5 with ListDatasetsRequest

use of com.google.cloud.automl.v1beta1.ListDatasetsRequest in project java-automl by googleapis.

the class SetEndpoint method setEndpoint.

// Change your endpoint
static void setEndpoint(String projectId) throws IOException {
    // [START automl_set_endpoint]
    AutoMlSettings settings = AutoMlSettings.newBuilder().setEndpoint("eu-automl.googleapis.com:443").build();
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    AutoMlClient client = AutoMlClient.create(settings);
    // A resource that represents Google Cloud Platform location.
    LocationName projectLocation = LocationName.of(projectId, "eu");
    // [END automl_set_endpoint]
    ListDatasetsRequest request = ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).setFilter("translation_dataset_metadata:*").build();
    // List all the datasets available
    System.out.println("List of datasets:");
    for (Dataset dataset : client.listDatasets(request).iterateAll()) {
        System.out.println(dataset);
    }
    client.close();
}
Also used : Dataset(com.google.cloud.automl.v1beta1.Dataset) AutoMlSettings(com.google.cloud.automl.v1beta1.AutoMlSettings) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName) ListDatasetsRequest(com.google.cloud.automl.v1beta1.ListDatasetsRequest)

Aggregations

AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)2 ListDatasetsPagedResponse (com.google.cloud.automl.v1beta1.AutoMlClient.ListDatasetsPagedResponse)2 Dataset (com.google.cloud.automl.v1beta1.Dataset)2 ListDatasetsRequest (com.google.cloud.automl.v1beta1.ListDatasetsRequest)2 LocationName (com.google.cloud.automl.v1beta1.LocationName)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)1 Dataset (com.google.cloud.automl.v1.Dataset)1 ListDatasetsRequest (com.google.cloud.automl.v1.ListDatasetsRequest)1 LocationName (com.google.cloud.automl.v1.LocationName)1 AutoMlSettings (com.google.cloud.automl.v1beta1.AutoMlSettings)1