From 905c3ecacdc01ba99ff73e610ffda7bfd26c7c78 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Tue, 10 Nov 2026 20:51:23 +0000 Subject: [PATCH] cleanup(vision): remove decommissioned beta batch file annotation samples --- .../vision/DetectBatchAnnotateFiles.java | 109 ------------------ .../vision/DetectBatchAnnotateFilesGcs.java | 108 ----------------- .../java/com/example/vision/DetectBetaIT.java | 21 ---- 3 files changed, 238 deletions(-) delete mode 100644 vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFiles.java delete mode 100644 vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFilesGcs.java diff --git a/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFiles.java b/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFiles.java deleted file mode 100644 index 7ef3ac6f74d..00000000000 --- a/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFiles.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.vision; - -// [START vision_batch_annotate_files_beta] -import com.google.api.core.ApiFuture; -import com.google.cloud.vision.v1p4beta1.AnnotateFileRequest; -import com.google.cloud.vision.v1p4beta1.AnnotateFileResponse; -import com.google.cloud.vision.v1p4beta1.BatchAnnotateFilesRequest; -import com.google.cloud.vision.v1p4beta1.BatchAnnotateFilesResponse; -import com.google.cloud.vision.v1p4beta1.Block; -import com.google.cloud.vision.v1p4beta1.Feature; -import com.google.cloud.vision.v1p4beta1.Feature.Type; -import com.google.cloud.vision.v1p4beta1.ImageAnnotatorClient; -import com.google.cloud.vision.v1p4beta1.InputConfig; -import com.google.cloud.vision.v1p4beta1.Page; -import com.google.cloud.vision.v1p4beta1.Paragraph; -import com.google.cloud.vision.v1p4beta1.Symbol; -import com.google.cloud.vision.v1p4beta1.TextAnnotation; -import com.google.cloud.vision.v1p4beta1.Word; -import com.google.protobuf.ByteString; -import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class DetectBatchAnnotateFiles { - - // Performs document feature detection on a local PDF/TIFF/GIF file. - public static void detectBatchAnnotateFiles(String filePath) { - // String filePath = "path/to/your_file"; - - try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { - // Annotate the first two pages and the last one (max 5 pages) - // First page starts at 1, and not 0. Last page is -1. - List pages = Arrays.asList(1, 2, -1); - ByteString pdfBytes = ByteString.readFrom(new FileInputStream(filePath)); - Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build(); - // Other supported mime types : 'image/tiff' or 'image/gif' - InputConfig inputConfig = - InputConfig.newBuilder().setMimeType("application/pdf").setContent(pdfBytes).build(); - AnnotateFileRequest request = - AnnotateFileRequest.newBuilder() - .addFeatures(feat) - .setInputConfig(inputConfig) - .addAllPages(pages) - .build(); - List requests = new ArrayList<>(); - requests.add(request); - - BatchAnnotateFilesRequest batchAnnotateFilesRequest = - BatchAnnotateFilesRequest.newBuilder().addAllRequests(requests).build(); - ApiFuture future = - client.batchAnnotateFilesCallable().futureCall(batchAnnotateFilesRequest); - BatchAnnotateFilesResponse response = future.get(); - - // Getting the first response - AnnotateFileResponse annotateFileResponse = response.getResponses(0); - - // For full list of available annotations, see http://g.co/cloud/vision/docs - TextAnnotation textAnnotation = annotateFileResponse.getResponses(0).getFullTextAnnotation(); - for (Page page : textAnnotation.getPagesList()) { - String pageText = ""; - for (Block block : page.getBlocksList()) { - String blockText = ""; - for (Paragraph para : block.getParagraphsList()) { - String paraText = ""; - for (Word word : para.getWordsList()) { - String wordText = ""; - for (Symbol symbol : word.getSymbolsList()) { - wordText = wordText + symbol.getText(); - System.out.format( - "Symbol text: %s (Confidence: %f)\n", symbol.getText(), symbol.getConfidence()); - } - System.out.format( - "Word text: %s (Confidence: %f)\n\n", wordText, word.getConfidence()); - paraText = String.format("%s %s", paraText, wordText); - } - // Output Example using Paragraph: - System.out.println("\nParagraph: \n" + paraText); - System.out.format("Paragraph Confidence: %f\n", para.getConfidence()); - blockText = blockText + paraText; - } - pageText = pageText + blockText; - } - } - System.out.println("\nComplete annotation:"); - System.out.println(textAnnotation.getText()); - - } catch (Exception e) { - System.out.println("Error during detectPdfText: \n" + e.toString()); - } - } -} -// [END vision_batch_annotate_files_beta] diff --git a/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFilesGcs.java b/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFilesGcs.java deleted file mode 100644 index 3f8b9582018..00000000000 --- a/vision/snippets/src/main/java/com/example/vision/DetectBatchAnnotateFilesGcs.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.vision; - -// [START vision_batch_annotate_files_gcs_beta] -import com.google.api.core.ApiFuture; -import com.google.cloud.vision.v1p4beta1.AnnotateFileRequest; -import com.google.cloud.vision.v1p4beta1.AnnotateFileResponse; -import com.google.cloud.vision.v1p4beta1.BatchAnnotateFilesRequest; -import com.google.cloud.vision.v1p4beta1.BatchAnnotateFilesResponse; -import com.google.cloud.vision.v1p4beta1.Block; -import com.google.cloud.vision.v1p4beta1.Feature; -import com.google.cloud.vision.v1p4beta1.Feature.Type; -import com.google.cloud.vision.v1p4beta1.GcsSource; -import com.google.cloud.vision.v1p4beta1.ImageAnnotatorClient; -import com.google.cloud.vision.v1p4beta1.InputConfig; -import com.google.cloud.vision.v1p4beta1.Page; -import com.google.cloud.vision.v1p4beta1.Paragraph; -import com.google.cloud.vision.v1p4beta1.Symbol; -import com.google.cloud.vision.v1p4beta1.TextAnnotation; -import com.google.cloud.vision.v1p4beta1.Word; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class DetectBatchAnnotateFilesGcs { - - // Performs document feature detection on a remote PDF/TIFF/GIF file on Google Cloud Storage. - public static void detectBatchAnnotateFilesGcs(String gcsPath) { - // String gcsPath = "gs://Your_BUCKET_ID/path_to_your_data"; - - try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { - // Annotate the first two pages and the last one (max 5 pages) - // First page starts at 1, and not 0. Last page is -1. - List pages = Arrays.asList(1, 2, -1); - GcsSource gcsSource = GcsSource.newBuilder().setUri(gcsPath).build(); - Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build(); - // Other supported mime types : 'image/tiff' or 'image/gif' - InputConfig inputConfig = - InputConfig.newBuilder().setMimeType("application/pdf").setGcsSource(gcsSource).build(); - AnnotateFileRequest request = - AnnotateFileRequest.newBuilder() - .addFeatures(feat) - .setInputConfig(inputConfig) - .addAllPages(pages) - .build(); - List requests = new ArrayList<>(); - requests.add(request); - - BatchAnnotateFilesRequest batchAnnotateFilesRequest = - BatchAnnotateFilesRequest.newBuilder().addAllRequests(requests).build(); - ApiFuture future = - client.batchAnnotateFilesCallable().futureCall(batchAnnotateFilesRequest); - BatchAnnotateFilesResponse response = future.get(); - - // Getting the first response - AnnotateFileResponse annotateFileResponse = response.getResponses(0); - - // For full list of available annotations, see http://g.co/cloud/vision/docs - TextAnnotation textAnnotation = annotateFileResponse.getResponses(0).getFullTextAnnotation(); - for (Page page : textAnnotation.getPagesList()) { - String pageText = ""; - for (Block block : page.getBlocksList()) { - String blockText = ""; - for (Paragraph para : block.getParagraphsList()) { - String paraText = ""; - for (Word word : para.getWordsList()) { - String wordText = ""; - for (Symbol symbol : word.getSymbolsList()) { - wordText = wordText + symbol.getText(); - System.out.format( - "Symbol text: %s (Confidence: %f)\n", symbol.getText(), symbol.getConfidence()); - } - System.out.format( - "Word text: %s (Confidence: %f)\n\n", wordText, word.getConfidence()); - paraText = String.format("%s %s", paraText, wordText); - } - // Output Example using Paragraph: - System.out.println("\nParagraph: \n" + paraText); - System.out.format("Paragraph Confidence: %f\n", para.getConfidence()); - blockText = blockText + paraText; - } - pageText = pageText + blockText; - } - } - System.out.println("\nComplete annotation:"); - System.out.println(textAnnotation.getText()); - - } catch (Exception e) { - System.out.println("Error during detectPdfText: \n" + e.toString()); - } - } -} -// [END vision_batch_annotate_files_gcs_beta] diff --git a/vision/snippets/src/test/java/com/example/vision/DetectBetaIT.java b/vision/snippets/src/test/java/com/example/vision/DetectBetaIT.java index d02ff9779d8..f6855885bf3 100644 --- a/vision/snippets/src/test/java/com/example/vision/DetectBetaIT.java +++ b/vision/snippets/src/test/java/com/example/vision/DetectBetaIT.java @@ -111,27 +111,6 @@ public void testDetectHandwrittenOcrGcs() throws Exception { assertThat(got).contains("Platform"); } - @Test - public void testDetectDocumentFeatures() { - // Act - DetectBatchAnnotateFiles.detectBatchAnnotateFiles("./resources/kafka.pdf"); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Samsa"); - } - - @Test - public void testDetectDocumentFeaturesGcs() throws Exception { - // Act - DetectBatchAnnotateFilesGcs.detectBatchAnnotateFilesGcs( - "gs://cloud-samples-data/video/kafka.pdf"); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Samsa"); - } - @Test public void testAsyncBatchAnnotateImagesGcs() throws Exception { // Act