Search in sources :

Example 6 with AnnotationSpecSet

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

the class CreateAnnotationSpecSet method createAnnotationSpecSet.

// Create an annotation spec set.
static void createAnnotationSpecSet(String projectId) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";
    Map<String, String> annotationLabels = new HashMap<>();
    annotationLabels.put("label_1", "label_1_description");
    annotationLabels.put("label_2", "label_2_description");
    // [END datalabeling_create_annotation_spec_set_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_create_annotation_spec_set_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        ProjectName projectName = ProjectName.of(projectId);
        List<AnnotationSpec> annotationSpecs = new ArrayList<>();
        for (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("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").addAllAnnotationSpecs(annotationSpecs).build();
        CreateAnnotationSpecSetRequest request = CreateAnnotationSpecSetRequest.newBuilder().setAnnotationSpecSet(annotationSpecSet).setParent(projectName.toString()).build();
        AnnotationSpecSet result = dataLabelingServiceClient.createAnnotationSpecSet(request);
        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("Annotation Count: %d\n", result.getAnnotationSpecsCount());
        for (AnnotationSpec annotationSpec : result.getAnnotationSpecsList()) {
            System.out.format("\tDisplayName: %s\n", annotationSpec.getDisplayName());
            System.out.format("\tDescription: %s\n\n", annotationSpec.getDescription());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) HashMap(java.util.HashMap) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationSpec(com.google.cloud.datalabeling.v1beta1.AnnotationSpec) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) CreateAnnotationSpecSetRequest(com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest)

Example 7 with AnnotationSpecSet

use of com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet 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 8 with AnnotationSpecSet

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

the class ITSystemTest method getAnnotationSpecSetTest.

@Test
public void getAnnotationSpecSetTest() {
    String formattedName = AnnotationSpecSetName.format(PROJECT_ID, annotationSpecSetId);
    AnnotationSpecSet response = client.getAnnotationSpecSet(formattedName);
    assertEquals(ANNOTATION_SPEC_SET, response.getDisplayName());
    assertEquals(DESCRIPTION, response.getDescription());
}
Also used : AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) Test(org.junit.Test)

Example 9 with AnnotationSpecSet

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

the class DataLabelingServiceClientTest method listAnnotationSpecSetsTest2.

@Test
public void listAnnotationSpecSetsTest2() throws Exception {
    AnnotationSpecSet responsesElement = AnnotationSpecSet.newBuilder().build();
    ListAnnotationSpecSetsResponse expectedResponse = ListAnnotationSpecSetsResponse.newBuilder().setNextPageToken("").addAllAnnotationSpecSets(Arrays.asList(responsesElement)).build();
    mockDataLabelingService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, 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)

Aggregations

AnnotationSpecSet (com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet)7 ListAnnotationSpecSetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotationSpecSetsPagedResponse)6 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)5 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)5 IOException (java.io.IOException)5 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)4 ListAnnotationSpecSetsRequest (com.google.cloud.datalabeling.v1beta1.ListAnnotationSpecSetsRequest)4 ListDatasetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse)3 ListInstructionsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListInstructionsPagedResponse)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 Test (org.junit.Test)3 AnnotationSpec (com.google.cloud.datalabeling.v1beta1.AnnotationSpec)2 GcsSource (com.google.cloud.datalabeling.v1beta1.GcsSource)2 ImportDataOperationResponse (com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse)2 ImportDataRequest (com.google.cloud.datalabeling.v1beta1.ImportDataRequest)2