|
21 | 21 | import com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet;
|
22 | 22 | import com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest;
|
23 | 23 | import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
|
| 24 | +import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings; |
24 | 25 | import com.google.cloud.datalabeling.v1beta1.ProjectName;
|
25 | 26 | import java.io.IOException;
|
26 | 27 | import java.util.ArrayList;
|
|
32 | 33 | class CreateAnnotationSpecSet {
|
33 | 34 |
|
34 | 35 | // Create an annotation spec set.
|
35 |
| - static void createAnnotationSpecSet(String projectId) { |
| 36 | + static void createAnnotationSpecSet(String projectId) throws IOException { |
36 | 37 | // String projectId = "YOUR_PROJECT_ID";
|
37 | 38 |
|
38 | 39 | Map<String, String> annotationLabels = new HashMap<>();
|
39 | 40 | annotationLabels.put("label_1", "label_1_description");
|
40 | 41 | annotationLabels.put("label_2", "label_2_description");
|
41 | 42 |
|
42 |
| - try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) { |
| 43 | + // [END datalabeling_create_annotation_spec_set_beta] |
| 44 | + String endpoint = System.getenv("DATALABELING_ENDPOINT"); |
| 45 | + if (endpoint == null) { |
| 46 | + endpoint = DataLabelingServiceSettings.getDefaultEndpoint(); |
| 47 | + } |
| 48 | + // [START datalabeling_create_annotation_spec_set_beta] |
43 | 49 |
|
| 50 | + DataLabelingServiceSettings settings = DataLabelingServiceSettings |
| 51 | + .newBuilder() |
| 52 | + // [END datalabeling_create_annotation_spec_set_beta] |
| 53 | + .setEndpoint(endpoint) |
| 54 | + // [START datalabeling_create_annotation_spec_set_beta] |
| 55 | + .build(); |
| 56 | + try (DataLabelingServiceClient dataLabelingServiceClient = |
| 57 | + DataLabelingServiceClient.create(settings)) { |
44 | 58 | ProjectName projectName = ProjectName.of(projectId);
|
45 | 59 |
|
46 | 60 | List<AnnotationSpec> annotationSpecs = new ArrayList<>();
|
47 | 61 | for (Entry<String, String> entry : annotationLabels.entrySet()) {
|
48 |
| - AnnotationSpec annotationSpec = AnnotationSpec.newBuilder() |
49 |
| - .setDisplayName(entry.getKey()) |
50 |
| - .setDescription(entry.getValue()) |
51 |
| - .build(); |
| 62 | + AnnotationSpec annotationSpec = |
| 63 | + AnnotationSpec.newBuilder() |
| 64 | + .setDisplayName(entry.getKey()) |
| 65 | + .setDescription(entry.getValue()) |
| 66 | + .build(); |
52 | 67 | annotationSpecs.add(annotationSpec);
|
53 | 68 | }
|
54 | 69 |
|
55 |
| - AnnotationSpecSet annotationSpecSet = AnnotationSpecSet.newBuilder() |
56 |
| - .setDisplayName("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME") |
57 |
| - .setDescription("YOUR_DESCRIPTION") |
58 |
| - .addAllAnnotationSpecs(annotationSpecs) |
59 |
| - .build(); |
| 70 | + AnnotationSpecSet annotationSpecSet = |
| 71 | + AnnotationSpecSet.newBuilder() |
| 72 | + .setDisplayName("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME") |
| 73 | + .setDescription("YOUR_DESCRIPTION") |
| 74 | + .addAllAnnotationSpecs(annotationSpecs) |
| 75 | + .build(); |
60 | 76 |
|
61 |
| - CreateAnnotationSpecSetRequest request = CreateAnnotationSpecSetRequest.newBuilder() |
62 |
| - .setAnnotationSpecSet(annotationSpecSet) |
63 |
| - .setParent(projectName.toString()) |
64 |
| - .build(); |
| 77 | + CreateAnnotationSpecSetRequest request = |
| 78 | + CreateAnnotationSpecSetRequest.newBuilder() |
| 79 | + .setAnnotationSpecSet(annotationSpecSet) |
| 80 | + .setParent(projectName.toString()) |
| 81 | + .build(); |
65 | 82 |
|
66 | 83 | AnnotationSpecSet result = dataLabelingServiceClient.createAnnotationSpecSet(request);
|
67 | 84 |
|
|
0 commit comments