Search in sources :

Example 61 with Dataset

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

the class CreateInstruction method createInstruction.

// Create a instruction for a dataset.
static void createInstruction(String projectId, String pdfUri) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";
    // String pdfUri = "gs://YOUR_BUCKET_ID/path_to_pdf_or_csv";
    // [END datalabeling_create_instruction_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_create_instruction_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        ProjectName projectName = ProjectName.of(projectId);
        // There are two types of instructions: CSV (CsvInstruction) or PDF (PdfInstruction)
        PdfInstruction pdfInstruction = PdfInstruction.newBuilder().setGcsFileUri(pdfUri).build();
        Instruction instruction = Instruction.newBuilder().setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.IMAGE).setPdfInstruction(// .setCsvInstruction() or .setPdfInstruction()
        pdfInstruction).build();
        CreateInstructionRequest createInstructionRequest = CreateInstructionRequest.newBuilder().setInstruction(instruction).setParent(projectName.toString()).build();
        OperationFuture<Instruction, CreateInstructionMetadata> operation = dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);
        Instruction result = operation.get();
        System.out.format("Name: %s\n", result.getName());
        System.out.format("DisplayName: %s\n", result.getDisplayName());
        System.out.format("Description: %s\n", result.getDescription());
        System.out.format("GCS SOURCE URI: %s\n", result.getPdfInstruction().getGcsFileUri());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) CreateInstructionRequest(com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest) IOException(java.io.IOException) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) CreateInstructionMetadata(com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException)

Example 62 with Dataset

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

the class ITSystemTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    client = DataLabelingServiceClient.create();
    /**
     * create Dataset
     */
    Dataset dataSetResponse = client.createDataset(PARENT, DATASET);
    dataSetId = dataSetResponse.getName().split("/")[3];
    LOGGER.info("Dataset created successfully.");
    /**
     * create AnnotationSpecSet
     */
    Map<String, String> annotationLabels = new HashMap<>();
    annotationLabels.put(LABEL_1, DESCRIPTION1);
    annotationLabels.put(LABEL_2, DESCRIPTION2);
    List<AnnotationSpec> annotationSpecs = new ArrayList<>();
    for (Map.Entry<String, String> entry : annotationLabels.entrySet()) {
        AnnotationSpec annotationSpec = AnnotationSpec.newBuilder().setDisplayName(entry.getKey()).setDescription(entry.getValue()).build();
        annotationSpecs.add(annotationSpec);
    }
    AnnotationSpecSet annotationSpecSet = AnnotationSpecSet.newBuilder().setDisplayName(ANNOTATION_SPEC_SET).setDescription(DESCRIPTION).addAllAnnotationSpecs(annotationSpecs).build();
    AnnotationSpecSet response = client.createAnnotationSpecSet(PARENT, annotationSpecSet);
    annotationSpecSetId = response.getName().split("/")[3];
    LOGGER.info("AnnotationSpecSet created successfully.");
}
Also used : HashMap(java.util.HashMap) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ArrayList(java.util.ArrayList) AnnotationSpec(com.google.cloud.datalabeling.v1beta1.AnnotationSpec) HashMap(java.util.HashMap) Map(java.util.Map) BeforeClass(org.junit.BeforeClass)

Example 63 with Dataset

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

the class ITSystemTest method getDatasetTest.

@Test
public void getDatasetTest() {
    String dataset = DatasetName.format(PROJECT_ID, dataSetId);
    Dataset response = client.getDataset(dataset);
    assertEquals(DATASET_DISPLAY_NAME, response.getDisplayName());
    assertEquals(DESCRIPTION, response.getDescription());
}
Also used : Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) Test(org.junit.Test)

Example 64 with Dataset

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

the class DataLabelingServiceClientTest method listDatasetsTest.

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

Example 65 with Dataset

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

the class DataLabelingServiceClientTest method listDatasetsTest2.

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

Aggregations

IOException (java.io.IOException)20 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 PrintStream (java.io.PrintStream)10 Before (org.junit.Before)10 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)8 LocationName (com.google.cloud.automl.v1.LocationName)7 ListDatasetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse)7 AbstractMessage (com.google.protobuf.AbstractMessage)7 CreateDatasetOperationMetadata (com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata)6 Dataset (com.google.cloud.aiplatform.v1.Dataset)6 DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)6 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)6 LocationName (com.google.cloud.aiplatform.v1.LocationName)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6