Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/java-datalabeling #7386

Merged
merged 136 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
9a16129
samples: scaffold pom.xml files (#102)
yoshi-automation Mar 17, 2020
8b8b2fe
samples: fix snippet closing tag (#104)
chingor13 Mar 18, 2020
5d74bf4
chore(deps): update dependency com.google.cloud:libraries-bom to v4.3…
renovate-bot Mar 23, 2020
c2d0bc9
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 25, 2020
8457cc9
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 30, 2020
2d098ad
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 1, 2020
0ac2b31
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 6, 2020
0200c62
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 6, 2020
e78a1f3
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Apr 7, 2020
55a458b
chore(deps): update dependency com.google.cloud:libraries-bom to v5 (…
renovate-bot Apr 14, 2020
d8fc9ea
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 16, 2020
734e55c
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 17, 2020
84a9dfb
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Apr 21, 2020
82c601d
chore(deps): update dependency com.google.cloud:libraries-bom to v5.2…
renovate-bot Apr 23, 2020
d7f788b
chore(deps): update dependency com.google.cloud:libraries-bom to v5.3…
renovate-bot Apr 28, 2020
c3b1748
chore(deps): update dependency com.google.cloud:libraries-bom to v5.6…
renovate-bot Jun 9, 2020
5a6b969
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 10, 2020
3b01226
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
renovate-bot Jun 10, 2020
9662a48
chore(deps): update dependency com.google.cloud:libraries-bom to v6 (…
renovate-bot Jun 16, 2020
6fad4a2
chore(deps): update dependency com.google.cloud:libraries-bom to v7 (…
renovate-bot Jun 17, 2020
1c8cd94
build(deps): update dependency org.codehaus.mojo:build-helper-maven-p…
renovate-bot Jun 22, 2020
839d4cf
chore(deps): update dependency com.google.cloud:libraries-bom to v7.0…
renovate-bot Jun 22, 2020
2b94a86
chore(deps): update dependency com.google.cloud:libraries-bom to v8 (…
renovate-bot Jun 26, 2020
7ceda0a
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
renovate-bot Jul 16, 2020
3d1b26e
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jul 28, 2020
06cb2b1
samples: Datalabeling beta samples (#1365)
nirupa-kumar Apr 4, 2019
596a244
samples: Use test endpoint for datalabeling integration tests. (#1803)
dzlier-gcp Dec 17, 2019
7b36a12
chore(deps): update dependency com.google.cloud:libraries-bom to v10
renovate-bot Sep 10, 2020
e8d48c1
chore(deps): update dependency com.google.cloud:libraries-bom to v11 …
renovate-bot Sep 24, 2020
21caceb
chore(deps): update dependency com.google.cloud:libraries-bom to v12 …
renovate-bot Oct 6, 2020
cfc596b
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Oct 9, 2020
af065a2
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Oct 12, 2020
496b06a
chore(deps): update dependency com.google.cloud:libraries-bom to v12.…
renovate-bot Oct 15, 2020
1c57cdc
test(deps): update dependency junit:junit to v4.13.1 (#272)
renovate-bot Oct 19, 2020
9bff7dc
chore(deps): update dependency com.google.cloud:libraries-bom to v13 …
renovate-bot Oct 20, 2020
4c984fd
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 21, 2020
bd53e92
test(deps): update dependency com.google.truth:truth to v1.1 (#291)
renovate-bot Oct 22, 2020
170e8db
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Oct 22, 2020
a528056
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 23, 2020
cbbc861
samples: fix checkstyle violations (#285)
athakor Oct 30, 2020
0879caf
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 30, 2020
863677a
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Nov 2, 2020
a389381
chore(deps): update dependency com.google.cloud:libraries-bom to v14 …
renovate-bot Nov 4, 2020
236ce95
chore(deps): update dependency com.google.cloud:libraries-bom to v15 …
renovate-bot Nov 11, 2020
131cf3b
chore(deps): update dependency com.google.cloud:libraries-bom to v16 …
renovate-bot Nov 18, 2020
a4a272a
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Nov 19, 2020
2595900
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Nov 19, 2020
96a93b1
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Dec 14, 2020
4686c03
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Dec 15, 2020
6752c38
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 7, 2021
d1e136d
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jan 7, 2021
908b46e
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 20, 2021
df8e001
test(deps): update dependency com.google.truth:truth to v1.1.2 (#378)
renovate-bot Jan 25, 2021
6924db5
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Feb 10, 2021
cd5a8b3
test(deps): update dependency junit:junit to v4.13.2 (#398)
renovate-bot Feb 16, 2021
68ed2e8
chore(deps): update dependency com.google.cloud:libraries-bom to v17 …
renovate-bot Feb 24, 2021
36a576c
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Feb 24, 2021
e0bb6e8
chore(deps): update dependency com.google.cloud:libraries-bom to v18 …
renovate-bot Feb 25, 2021
2d5ff37
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Feb 26, 2021
bc0fc4f
chore(deps): update dependency com.google.cloud:libraries-bom to v18.…
renovate-bot Mar 3, 2021
fc8f370
chore(deps): update dependency com.google.cloud:libraries-bom to v19 …
renovate-bot Mar 4, 2021
f55ad23
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Mar 11, 2021
a6043c7
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 17, 2021
6d20959
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 29, 2021
209188c
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 9, 2021
4de489d
chore(deps): update dependency com.google.cloud:libraries-bom to v20 …
renovate-bot Apr 12, 2021
d19ba35
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 19, 2021
e681d39
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 29, 2021
098237b
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Apr 30, 2021
7cb58fd
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 13, 2021
f869b82
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 17, 2021
61ccdcf
test(deps): update dependency com.google.truth:truth to v1.1.3 (#494)
renovate-bot May 26, 2021
0bc8f53
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot May 26, 2021
d202e71
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 31, 2021
2e8502b
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jun 2, 2021
695b819
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 7, 2021
f235085
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 7, 2021
a4c387d
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jun 9, 2021
af7eeb2
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 23, 2021
53712d0
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jul 7, 2021
593538b
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 9, 2021
6d0b143
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 28, 2021
9ecde44
chore(deps): update dependency com.google.cloud:libraries-bom to v21 …
renovate-bot Aug 19, 2021
61b04d7
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Aug 19, 2021
690cdef
chore(deps): update dependency com.google.cloud:libraries-bom to v22 …
renovate-bot Aug 27, 2021
c6ba600
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Aug 31, 2021
7bd2fa3
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Aug 31, 2021
721b5e1
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 2, 2021
b606157
chore(deps): update dependency com.google.cloud:libraries-bom to v23 …
renovate-bot Sep 13, 2021
ea9841d
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 14, 2021
8ca487e
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 23, 2021
4b280ab
chore(deps): update dependency com.google.cloud:libraries-bom to v23.…
renovate-bot Oct 1, 2021
3a3a615
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Oct 21, 2021
ee02eed
chore(deps): update dependency com.google.cloud:libraries-bom to v24 …
renovate-bot Oct 27, 2021
2348e0c
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Dec 6, 2021
583a713
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Dec 6, 2021
dec7ea7
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 8, 2021
185c2e9
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 28, 2021
f9ac0f2
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 7, 2022
444850e
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jan 17, 2022
f0a73b4
build(deps): update dependency org.codehaus.mojo:build-helper-maven-p…
renovate-bot Jan 18, 2022
8fc650e
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 18, 2022
ad3c764
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Feb 8, 2022
a716cc7
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Feb 9, 2022
54f0d5c
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot Feb 14, 2022
bcafc94
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot Feb 15, 2022
98816cd
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Feb 15, 2022
090bc48
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot Feb 17, 2022
be50a71
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Mar 1, 2022
28ef55c
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Mar 2, 2022
f5b7473
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot Mar 14, 2022
6b70bc6
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Mar 14, 2022
6ccb543
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Apr 1, 2022
5f9c042
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 1, 2022
6595c68
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot Apr 21, 2022
b0bf077
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Apr 21, 2022
1e68fc5
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 27, 2022
f0e22d2
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot May 16, 2022
a7b08cd
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot May 25, 2022
6dd09eb
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Jun 6, 2022
7656493
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Jun 24, 2022
3476dbb
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot Jul 11, 2022
b3af472
build(deps): update dependency org.apache.maven.plugins:maven-deploy-…
renovate-bot Jul 19, 2022
d8068f5
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Aug 16, 2022
f4923fb
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 16, 2022
919c3c6
chore: remove unused proto imports (#777)
gcf-owl-bot[bot] Aug 22, 2022
7953b0a
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 31, 2022
20adfd2
chore(bazel): Update WORKSPACE files for rules_gapic, gax_java, gener…
gcf-owl-bot[bot] Sep 8, 2022
303aead
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 9, 2022
7ed86b0
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 20, 2022
9800a22
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Sep 20, 2022
3633c1d
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Sep 30, 2022
ab30052
chore(deps): update dependency com.google.cloud:google-cloud-datalabe…
renovate-bot Oct 6, 2022
79a085e
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Oct 7, 2022
3abc7ee
Merge remote-tracking branch 'migration/main' into java-datalabeling-…
ivanmkc Nov 3, 2022
4998c47
Removed unneeded files
ivanmkc Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.datalabeling;

// [START datalabeling_create_annotation_spec_set_beta]
import com.google.cloud.datalabeling.v1beta1.AnnotationSpec;
import com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet;
import com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings;
import com.google.cloud.datalabeling.v1beta1.ProjectName;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

class 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()
// [END datalabeling_create_annotation_spec_set_beta]
.setEndpoint(endpoint)
// [START datalabeling_create_annotation_spec_set_beta]
.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();
}
}
}
// [END datalabeling_create_annotation_spec_set_beta]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.datalabeling;

// [START datalabeling_create_dataset_beta]
import com.google.cloud.datalabeling.v1beta1.CreateDatasetRequest;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings;
import com.google.cloud.datalabeling.v1beta1.Dataset;
import com.google.cloud.datalabeling.v1beta1.ProjectName;
import java.io.IOException;

class CreateDataset {

// Create a dataset that is initially empty.
static void createDataset(String projectId, String datasetName) throws IOException {
// String projectId = "YOUR_PROJECT_ID";
// String datasetName = "YOUR_DATASET_DISPLAY_NAME";

// [END datalabeling_create_dataset_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_create_dataset_beta]

DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_create_dataset_beta]
.setEndpoint(endpoint)
// [START datalabeling_create_dataset_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
ProjectName projectName = ProjectName.of(projectId);

Dataset dataset =
Dataset.newBuilder()
.setDisplayName(datasetName)
.setDescription("YOUR_DESCRIPTION")
.build();

CreateDatasetRequest createDatasetRequest =
CreateDatasetRequest.newBuilder()
.setParent(projectName.toString())
.setDataset(dataset)
.build();

Dataset createdDataset = dataLabelingServiceClient.createDataset(createDatasetRequest);

System.out.format("Name: %s\n", createdDataset.getName());
System.out.format("DisplayName: %s\n", createdDataset.getDisplayName());
System.out.format("Description: %s\n", createdDataset.getDescription());
} catch (IOException e) {
e.printStackTrace();
}
}
}
// [END datalabeling_create_dataset_beta]
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.datalabeling;

// [START datalabeling_create_instruction_beta]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata;
import com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings;
import com.google.cloud.datalabeling.v1beta1.DataType;
import com.google.cloud.datalabeling.v1beta1.Instruction;
import com.google.cloud.datalabeling.v1beta1.PdfInstruction;
import com.google.cloud.datalabeling.v1beta1.ProjectName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class 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()
// [END datalabeling_create_instruction_beta]
.setEndpoint(endpoint)
// [START datalabeling_create_instruction_beta]
.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(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
.setPdfInstruction(pdfInstruction) // .setCsvInstruction() or .setPdfInstruction()
.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();
}
}
}
// [END datalabeling_create_instruction_beta]
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.datalabeling;

// [START datalabeling_export_data_beta]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings;
import com.google.cloud.datalabeling.v1beta1.ExportDataOperationMetadata;
import com.google.cloud.datalabeling.v1beta1.ExportDataOperationResponse;
import com.google.cloud.datalabeling.v1beta1.ExportDataRequest;
import com.google.cloud.datalabeling.v1beta1.GcsDestination;
import com.google.cloud.datalabeling.v1beta1.LabelStats;
import com.google.cloud.datalabeling.v1beta1.OutputConfig;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutionException;

class ExportData {

// Export data from an annotated dataset.
static void exportData(String datasetName, String annotatedDatasetName, String gcsOutputUri)
throws IOException {
// String datasetName = DataLabelingServiceClient.formatDatasetName(
// "YOUR_PROJECT_ID", "YOUR_DATASETS_UUID");
// String annotatedDatasetName = DataLabelingServiceClient.formatAnnotatedDatasetName(
// "YOUR_PROJECT_ID",
// "YOUR_DATASET_UUID",
// "YOUR_ANNOTATED_DATASET_UUID");
// String gcsOutputUri = "gs://YOUR_BUCKET_ID/export_path";

// [END datalabeling_export_data_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_export_data_beta]

DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_export_data_beta]
.setEndpoint(endpoint)
// [START datalabeling_export_data_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
GcsDestination gcsDestination =
GcsDestination.newBuilder().setOutputUri(gcsOutputUri).setMimeType("text/csv").build();

OutputConfig outputConfig =
OutputConfig.newBuilder().setGcsDestination(gcsDestination).build();

ExportDataRequest exportDataRequest =
ExportDataRequest.newBuilder()
.setName(datasetName)
.setOutputConfig(outputConfig)
.setAnnotatedDataset(annotatedDatasetName)
.build();

OperationFuture<ExportDataOperationResponse, ExportDataOperationMetadata> operation =
dataLabelingServiceClient.exportDataAsync(exportDataRequest);

ExportDataOperationResponse response = operation.get();

System.out.format("Exported item count: %d\n", response.getExportCount());
LabelStats labelStats = response.getLabelStats();
Set<Entry<String, Long>> entries = labelStats.getExampleCountMap().entrySet();
for (Entry<String, Long> entry : entries) {
System.out.format("\tLabel: %s\n", entry.getKey());
System.out.format("\tCount: %d\n\n", entry.getValue());
}
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
// [END datalabeling_export_data_beta]
Loading