Search in sources :

Example 1 with ListAnnotationSpecSetsRequest

use of com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest in project java-datalabeling by googleapis.

the class DataLabelingServiceClientTest method listAnnotationSpecSetsTest.

@Test
public void listAnnotationSpecSetsTest() throws Exception {
    AnnotationSpecSet responsesElement = AnnotationSpecSet.newBuilder().build();
    ListAnnotationSpecSetsResponse expectedResponse = ListAnnotationSpecSetsResponse.newBuilder().setNextPageToken("").addAllAnnotationSpecSets(Arrays.asList(responsesElement)).build();
    mockDataLabelingService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String filter = "filter-1274492040";
    ListAnnotationSpecSetsPagedResponse pagedListResponse = client.listAnnotationSpecSets(parent, filter);
    List<AnnotationSpecSet> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAnnotationSpecSetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAnnotationSpecSetsRequest actualRequest = ((ListAnnotationSpecSetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListAnnotationSpecSetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with ListAnnotationSpecSetsRequest

use of com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest in project java-datalabeling by googleapis.

the class CreateAnnotationSpecSetIT method tearDown.

@After
public void tearDown() {
    System.setOut(null);
    bout.reset();
    // Delete the Annotation Spec Sheet
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        ListAnnotationSpecSetsRequest listRequest = ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListAnnotationSpecSetsPagedResponse response = dataLabelingServiceClient.listAnnotationSpecSets(listRequest);
        for (AnnotationSpecSet annotationSpecSet : response.getPage().iterateAll()) {
            if (annotationSpecSet.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
                dataLabelingServiceClient.deleteAnnotationSpecSet(annotationSpecSet.getName());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ListAnnotationSpecSetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse) DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) ListAnnotationSpecSetsRequest(com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) IOException(java.io.IOException) After(org.junit.After)

Example 3 with ListAnnotationSpecSetsRequest

use of com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest in project java-datalabeling by googleapis.

the class LabelVideoIT method setUp.

@Before
public void setUp() {
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        // Create the dataset
        CreateDataset.createDataset(PROJECT_ID, datasetName);
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        // Get the Dataset
        ListDatasetsRequest datasetsRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListDatasetsPagedResponse datasetsResponse = dataLabelingServiceClient.listDatasets(datasetsRequest);
        for (Dataset returnedDataset : datasetsResponse.getPage().iterateAll()) {
            if (returnedDataset.getDisplayName().equals("LABEL_VIDEO_DATASET_NAME")) {
                dataset = returnedDataset;
            }
        }
        // Import the images
        // ImportData.importData(dataset.getName(), DATASET_GCS_SOURCE_URI);
        GcsSource gcsSource = GcsSource.newBuilder().setInputUri(DATASET_GCS_SOURCE_URI).setMimeType("text/csv").build();
        InputConfig inputConfig = InputConfig.newBuilder().setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.VIDEO).setGcsSource(gcsSource).build();
        ImportDataRequest importDataRequest = ImportDataRequest.newBuilder().setName(dataset.getName()).setInputConfig(inputConfig).build();
        ImportDataOperationResponse response = dataLabelingServiceClient.importDataAsync(importDataRequest).get();
        System.out.format("Imported items: %d\n", response.getImportCount());
        // Create the instruction
        CreateInstruction.createInstruction(PROJECT_ID, INSTRUCTION_GCS_SOURCE_URI);
        // Create the annotation spec set
        CreateAnnotationSpecSet.createAnnotationSpecSet(PROJECT_ID);
        // Get the instruction
        ListInstructionsRequest instructionsRequest = ListInstructionsRequest.newBuilder().setParent(projectName.toString()).build();
        ListInstructionsPagedResponse instructionsResponse = dataLabelingServiceClient.listInstructions(instructionsRequest);
        for (Instruction returnedInstruction : instructionsResponse.getPage().iterateAll()) {
            if (returnedInstruction.getDisplayName().equals("YOUR_INSTRUCTION_DISPLAY_NAME")) {
                instruction = returnedInstruction;
            }
        }
        // Get the annotation spec set
        ListAnnotationSpecSetsRequest annotationRequest = ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListAnnotationSpecSetsPagedResponse annotationsResponse = dataLabelingServiceClient.listAnnotationSpecSets(annotationRequest);
        for (AnnotationSpecSet returnedAnnotation : annotationsResponse.getPage().iterateAll()) {
            if (returnedAnnotation.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
                annotationSpecSet = returnedAnnotation;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ListAnnotationSpecSetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse) PrintStream(java.io.PrintStream) DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ListDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse) GcsSource(com.google.cloud.datalabeling.v1beta1.GcsSource) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) ListAnnotationSpecSetsRequest(com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) IOException(java.io.IOException) ListDatasetsRequest(com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest) ListInstructionsRequest(com.google.cloud.datalabeling.v1beta1.ListInstructionsRequest) ListInstructionsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListInstructionsPagedResponse) InputConfig(com.google.cloud.datalabeling.v1beta1.InputConfig) ImportDataRequest(com.google.cloud.datalabeling.v1beta1.ImportDataRequest) ImportDataOperationResponse(com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse) Before(org.junit.Before)

Example 4 with ListAnnotationSpecSetsRequest

use of com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest in project java-datalabeling by googleapis.

the class LabelImageIT method setUp.

@Before
public void setUp() {
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        // Create the dataset
        CreateDataset.createDataset(PROJECT_ID, datsetName);
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        // Get the Dataset
        ListDatasetsRequest datasetsRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListDatasetsPagedResponse datasetsResponse = dataLabelingServiceClient.listDatasets(datasetsRequest);
        for (Dataset returnedDataset : datasetsResponse.getPage().iterateAll()) {
            if (returnedDataset.getDisplayName().equals("LABEL_IMAGE_DATASET_NAME")) {
                dataset = returnedDataset;
            }
        }
        // Import the images
        ImportData.importData(dataset.getName(), DATASET_GCS_SOURCE_URI);
        // Create the instruction
        CreateInstruction.createInstruction(PROJECT_ID, INSTRUCTION_GCS_SOURCE_URI);
        // Create the annotation spec set
        CreateAnnotationSpecSet.createAnnotationSpecSet(PROJECT_ID);
        // Get the instruction
        ListInstructionsRequest instructionsRequest = ListInstructionsRequest.newBuilder().setParent(projectName.toString()).build();
        ListInstructionsPagedResponse instructionsResponse = dataLabelingServiceClient.listInstructions(instructionsRequest);
        for (Instruction returnedInstruction : instructionsResponse.getPage().iterateAll()) {
            if (returnedInstruction.getDisplayName().equals("YOUR_INSTRUCTION_DISPLAY_NAME")) {
                instruction = returnedInstruction;
            }
        }
        // Get the annotation spec set
        ListAnnotationSpecSetsRequest annotationRequest = ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListAnnotationSpecSetsPagedResponse annotationsResponse = dataLabelingServiceClient.listAnnotationSpecSets(annotationRequest);
        for (AnnotationSpecSet returnedAnnotation : annotationsResponse.getPage().iterateAll()) {
            if (returnedAnnotation.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
                annotationSpecSet = returnedAnnotation;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ListAnnotationSpecSetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse) PrintStream(java.io.PrintStream) DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ListDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) ListAnnotationSpecSetsRequest(com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) IOException(java.io.IOException) ListDatasetsRequest(com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest) ListInstructionsRequest(com.google.cloud.datalabeling.v1beta1.ListInstructionsRequest) ListInstructionsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListInstructionsPagedResponse) Before(org.junit.Before)

Example 5 with ListAnnotationSpecSetsRequest

use of com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest in project java-datalabeling by googleapis.

the class LabelTextIT method setUp.

@Before
public void setUp() {
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        // Create the dataset
        CreateDataset.createDataset(PROJECT_ID, datasetName);
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        // Get the Dataset
        ListDatasetsRequest datasetsRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListDatasetsPagedResponse datasetsResponse = dataLabelingServiceClient.listDatasets(datasetsRequest);
        for (Dataset returnedDataset : datasetsResponse.getPage().iterateAll()) {
            if (returnedDataset.getDisplayName().equals("LABEL_TEXT_DATASET_NAME")) {
                dataset = returnedDataset;
            }
        }
        // Import the texts
        GcsSource gcsSource = GcsSource.newBuilder().setInputUri(DATASET_GCS_SOURCE_URI).setMimeType("text/csv").build();
        InputConfig inputConfig = InputConfig.newBuilder().setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.TEXT).setGcsSource(gcsSource).build();
        ImportDataRequest importDataRequest = ImportDataRequest.newBuilder().setName(dataset.getName()).setInputConfig(inputConfig).build();
        ImportDataOperationResponse response = dataLabelingServiceClient.importDataAsync(importDataRequest).get();
        System.out.format("Imported items: %d\n", response.getImportCount());
        // Create the instruction
        CreateInstruction.createInstruction(PROJECT_ID, INSTRUCTION_GCS_SOURCE_URI);
        // Create the annotation spec set
        CreateAnnotationSpecSet.createAnnotationSpecSet(PROJECT_ID);
        // Get the instruction
        ListInstructionsRequest instructionsRequest = ListInstructionsRequest.newBuilder().setParent(projectName.toString()).build();
        ListInstructionsPagedResponse instructionsResponse = dataLabelingServiceClient.listInstructions(instructionsRequest);
        for (Instruction returnedInstruction : instructionsResponse.getPage().iterateAll()) {
            if (returnedInstruction.getDisplayName().equals("YOUR_INSTRUCTION_DISPLAY_NAME")) {
                instruction = returnedInstruction;
            }
        }
        // Get the annotation spec set
        ListAnnotationSpecSetsRequest annotationRequest = ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListAnnotationSpecSetsPagedResponse annotationsResponse = dataLabelingServiceClient.listAnnotationSpecSets(annotationRequest);
        for (AnnotationSpecSet returnedAnnotation : annotationsResponse.getPage().iterateAll()) {
            if (returnedAnnotation.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
                annotationSpecSet = returnedAnnotation;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ListAnnotationSpecSetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse) PrintStream(java.io.PrintStream) DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ListDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse) GcsSource(com.google.cloud.datalabeling.v1beta1.GcsSource) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) ListAnnotationSpecSetsRequest(com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) IOException(java.io.IOException) ListDatasetsRequest(com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest) ListInstructionsRequest(com.google.cloud.datalabeling.v1beta1.ListInstructionsRequest) ListInstructionsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListInstructionsPagedResponse) InputConfig(com.google.cloud.datalabeling.v1beta1.InputConfig) ImportDataRequest(com.google.cloud.datalabeling.v1beta1.ImportDataRequest) ImportDataOperationResponse(com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse) Before(org.junit.Before)

Aggregations

ListAnnotationSpecSetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse)6 AnnotationSpecSet (com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet)4 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)4 ListAnnotationSpecSetsRequest (com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest)4 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)4 IOException (java.io.IOException)4 ListDatasetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse)3 ListInstructionsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListInstructionsPagedResponse)3 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)3 Instruction (com.google.cloud.datalabeling.v1beta1.Instruction)3 ListDatasetsRequest (com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest)3 ListInstructionsRequest (com.google.cloud.datalabeling.v1beta1.ListInstructionsRequest)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 Before (org.junit.Before)3 GcsSource (com.google.cloud.datalabeling.v1beta1.GcsSource)2 ImportDataOperationResponse (com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse)2 ImportDataRequest (com.google.cloud.datalabeling.v1beta1.ImportDataRequest)2 InputConfig (com.google.cloud.datalabeling.v1beta1.InputConfig)2 AbstractMessage (com.google.protobuf.AbstractMessage)2