Skip to content

Commit

Permalink
samples: fix checkstyle violations (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
athakor authored Oct 30, 2020
1 parent a528056 commit cbbc861
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ static void createAnnotationSpecSet(String projectId) throws IOException {
}
// [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();
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)) {
DataLabelingServiceClient.create(settings)) {
ProjectName projectName = ProjectName.of(projectId);

List<AnnotationSpec> annotationSpecs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ static void createDataset(String projectId, String datasetName) throws IOExcepti
}
// [START datalabeling_create_dataset_beta]

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

Dataset dataset =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ static void createInstruction(String projectId, String pdfUri) throws IOExceptio
}
// [START datalabeling_create_instruction_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_create_instruction_beta]
.setEndpoint(endpoint)
// [START datalabeling_create_instruction_beta]
.build();
DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_create_instruction_beta]
.setEndpoint(endpoint)
// [START datalabeling_create_instruction_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
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();
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();
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();
CreateInstructionRequest createInstructionRequest =
CreateInstructionRequest.newBuilder()
.setInstruction(instruction)
.setParent(projectName.toString())
.build();

OperationFuture<Instruction, CreateInstructionMetadata> operation =
dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,26 @@ static void exportData(String datasetName, String annotatedDatasetName, String g
}
// [START datalabeling_export_data_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_export_data_beta]
.setEndpoint(endpoint)
// [START datalabeling_export_data_beta]
.build();
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();
DataLabelingServiceClient.create(settings)) {
GcsDestination gcsDestination =
GcsDestination.newBuilder().setOutputUri(gcsOutputUri).setMimeType("text/csv").build();

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

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

OperationFuture<ExportDataOperationResponse, ExportDataOperationMetadata> operation =
dataLabelingServiceClient.exportDataAsync(exportDataRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,25 @@ static void importData(String datasetName, String gcsSourceUri) throws IOExcepti
}
// [START datalabeling_import_data_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_import_data_beta]
.setEndpoint(endpoint)
// [START datalabeling_import_data_beta]
.build();
DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_import_data_beta]
.setEndpoint(endpoint)
// [START datalabeling_import_data_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
GcsSource gcsSource = GcsSource.newBuilder()
.setInputUri(gcsSourceUri)
.setMimeType("text/csv")
.build();
DataLabelingServiceClient.create(settings)) {
GcsSource gcsSource =
GcsSource.newBuilder().setInputUri(gcsSourceUri).setMimeType("text/csv").build();

InputConfig inputConfig = InputConfig.newBuilder()
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
.setGcsSource(gcsSource)
.build();
InputConfig inputConfig =
InputConfig.newBuilder()
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
.setGcsSource(gcsSource)
.build();

ImportDataRequest importDataRequest = ImportDataRequest.newBuilder()
.setName(datasetName)
.setInputConfig(inputConfig)
.build();
ImportDataRequest importDataRequest =
ImportDataRequest.newBuilder().setName(datasetName).setInputConfig(inputConfig).build();

OperationFuture<ImportDataOperationResponse, ImportDataOperationMetadata> operation =
dataLabelingServiceClient.importDataAsync(importDataRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class LabelImage {
static void labelImage(
String formattedInstructionName,
String formattedAnnotationSpecSetName,
String formattedDatasetName) throws IOException {
String formattedDatasetName)
throws IOException {
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
// String formattedAnnotationSpecSetName =
Expand All @@ -52,14 +53,14 @@ static void labelImage(
}
// [START datalabeling_label_image_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_label_image_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_image_beta]
.build();
DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_label_image_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_image_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
DataLabelingServiceClient.create(settings)) {
HumanAnnotationConfig humanAnnotationConfig =
HumanAnnotationConfig.newBuilder()
.setAnnotatedDatasetDisplayName("annotated_displayname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class LabelText {
static void labelText(
String formattedInstructionName,
String formattedAnnotationSpecSetName,
String formattedDatasetName) throws IOException {
String formattedDatasetName)
throws IOException {
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
// String formattedAnnotationSpecSetName =
Expand All @@ -52,14 +53,14 @@ static void labelText(
}
// [START datalabeling_label_text_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_label_text_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_text_beta]
.build();
DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_label_text_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_text_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
DataLabelingServiceClient.create(settings)) {
HumanAnnotationConfig humanAnnotationConfig =
HumanAnnotationConfig.newBuilder()
.setAnnotatedDatasetDisplayName("annotated_displayname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
class LabelVideo {

// Start a Video Labeling Task
static void labelVideo(String formattedInstructionName, String formattedAnnotationSpecSetName,
String formattedDatasetName) throws IOException {
static void labelVideo(
String formattedInstructionName,
String formattedAnnotationSpecSetName,
String formattedDatasetName)
throws IOException {
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
// String formattedAnnotationSpecSetName =
Expand All @@ -50,36 +53,40 @@ static void labelVideo(String formattedInstructionName, String formattedAnnotati
}
// [START datalabeling_label_video_beta]

DataLabelingServiceSettings settings = DataLabelingServiceSettings
.newBuilder()
// [END datalabeling_label_video_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_video_beta]
.build();
DataLabelingServiceSettings settings =
DataLabelingServiceSettings.newBuilder()
// [END datalabeling_label_video_beta]
.setEndpoint(endpoint)
// [START datalabeling_label_video_beta]
.build();
try (DataLabelingServiceClient dataLabelingServiceClient =
DataLabelingServiceClient.create(settings)) {
HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder()
.setAnnotatedDatasetDisplayName("annotated_displayname")
.setAnnotatedDatasetDescription("annotated_description")
.setInstruction(formattedInstructionName)
.build();
DataLabelingServiceClient.create(settings)) {
HumanAnnotationConfig humanAnnotationConfig =
HumanAnnotationConfig.newBuilder()
.setAnnotatedDatasetDisplayName("annotated_displayname")
.setAnnotatedDatasetDescription("annotated_description")
.setInstruction(formattedInstructionName)
.build();

AnnotationSpecSetConfig annotationSpecSetConfig = AnnotationSpecSetConfig.newBuilder()
.setAnnotationSpecSet(formattedAnnotationSpecSetName)
.setAllowMultiLabel(true)
.build();
AnnotationSpecSetConfig annotationSpecSetConfig =
AnnotationSpecSetConfig.newBuilder()
.setAnnotationSpecSet(formattedAnnotationSpecSetName)
.setAllowMultiLabel(true)
.build();

VideoClassificationConfig videoClassificationConfig = VideoClassificationConfig.newBuilder()
.setApplyShotDetection(true)
.addAnnotationSpecSetConfigs(annotationSpecSetConfig)
.build();
VideoClassificationConfig videoClassificationConfig =
VideoClassificationConfig.newBuilder()
.setApplyShotDetection(true)
.addAnnotationSpecSetConfigs(annotationSpecSetConfig)
.build();

LabelVideoRequest labelVideoRequest = LabelVideoRequest.newBuilder()
.setParent(formattedDatasetName)
.setBasicConfig(humanAnnotationConfig)
.setVideoClassificationConfig(videoClassificationConfig)
.setFeature(Feature.CLASSIFICATION)
.build();
LabelVideoRequest labelVideoRequest =
LabelVideoRequest.newBuilder()
.setParent(formattedDatasetName)
.setBasicConfig(humanAnnotationConfig)
.setVideoClassificationConfig(videoClassificationConfig)
.setFeature(Feature.CLASSIFICATION)
.build();

OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation =
dataLabelingServiceClient.labelVideoAsync(labelVideoRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Integration (system) tests for {@link CreateAnnotationSpecSet}.
*/
/** Integration (system) tests for {@link CreateAnnotationSpecSet}. */
@RunWith(JUnit4.class)
@Ignore("b/146064330")
@SuppressWarnings("checkstyle:abbreviationaswordinname")
Expand All @@ -60,12 +58,11 @@ public void tearDown() {
// Delete the Annotation Spec Sheet
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
ProjectName projectName = ProjectName.of(PROJECT_ID);
ListAnnotationSpecSetsRequest listRequest = ListAnnotationSpecSetsRequest.newBuilder()
.setParent(projectName.toString())
.build();
ListAnnotationSpecSetsRequest listRequest =
ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();

ListAnnotationSpecSetsPagedResponse response = dataLabelingServiceClient
.listAnnotationSpecSets(listRequest);
ListAnnotationSpecSetsPagedResponse response =
dataLabelingServiceClient.listAnnotationSpecSets(listRequest);

for (AnnotationSpecSet annotationSpecSet : response.getPage().iterateAll()) {
if (annotationSpecSet.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
Expand All @@ -83,8 +80,8 @@ public void testCreateAnnotationSpecSet() throws IOException {

String output = bout.toString();

assertThat(output, CoreMatchers.containsString(
"DisplayName: YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME"));
assertThat(
output, CoreMatchers.containsString("DisplayName: YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME"));
assertThat(output, CoreMatchers.containsString("Description: YOUR_DESCRIPTION"));
assertThat(output, CoreMatchers.containsString("Annotation Count: 2"));
}
Expand Down
Loading

0 comments on commit cbbc861

Please sign in to comment.