Search in sources :

Example 1 with CreateAnnotationSpecSetRequest

use of com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest 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)

Aggregations

AnnotationSpec (com.google.cloud.datalabeling.v1beta1.AnnotationSpec)1 AnnotationSpecSet (com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet)1 CreateAnnotationSpecSetRequest (com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest)1 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)1 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)1 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1