diff --git a/vision/beta/cloud-client/src/main/java/com/example/vision/Detect.java b/vision/beta/cloud-client/src/main/java/com/example/vision/Detect.java index 9780de29705..7bab5b15995 100644 --- a/vision/beta/cloud-client/src/main/java/com/example/vision/Detect.java +++ b/vision/beta/cloud-client/src/main/java/com/example/vision/Detect.java @@ -1319,7 +1319,7 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out) throws } // [END vision_detect_document_uri] - // [START vision_async_detect_document_ocr] + // [START vision_text_detection_pdf_gcs] /** * Performs document text OCR with PDF/TIFF as source files on Google Cloud Storage. * @@ -1436,7 +1436,7 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio } } } - // [END vision_async_detect_document_ocr] + // [END vision_text_detection_pdf_gcs] // [START vision_localize_objects] /** @@ -1482,7 +1482,7 @@ public static void detectLocalizedObjects(String filePath, PrintStream out) } // [END vision_localize_objects] - // [START vision_localize_objects_uri] + // [START vision_localize_objects_gcs] /** * Detects localized objects in a remote image on Google Cloud Storage. * @@ -1525,7 +1525,7 @@ public static void detectLocalizedObjectsGcs(String gcsPath, PrintStream out) } } } - // [END vision_localize_objects_uri] + // [END vision_localize_objects_gcs] // [START vision_handwritten_ocr] /** @@ -1600,7 +1600,7 @@ public static void detectHandwrittenOcr(String filePath, PrintStream out) throws } // [END vision_handwritten_ocr] - // [START vision_handwritten_ocr_uri] + // [START vision_handwritten_ocr_gcs] /** * Performs handwritten text detection on a remote image on Google Cloud Storage. * @@ -1672,5 +1672,5 @@ public static void detectHandwrittenOcrGcs(String gcsPath, PrintStream out) thro } } } - // [END vision_handwritten_ocr_uri] + // [END vision_handwritten_ocr_gcs] } diff --git a/vision/cloud-client/src/main/java/com/example/vision/Detect.java b/vision/cloud-client/src/main/java/com/example/vision/Detect.java index 68f8c98bb5c..2332828db2c 100644 --- a/vision/cloud-client/src/main/java/com/example/vision/Detect.java +++ b/vision/cloud-client/src/main/java/com/example/vision/Detect.java @@ -201,6 +201,7 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception, * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_face_detection] public static void detectFaces(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -234,6 +235,7 @@ public static void detectFaces(String filePath, PrintStream out) throws Exceptio } } } + // [END vision_face_detection] /** * Detects faces in the specified remote image on Google Cloud Storage. @@ -244,6 +246,7 @@ public static void detectFaces(String filePath, PrintStream out) throws Exceptio * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_face_detection_gcs] public static void detectFacesGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -278,6 +281,7 @@ public static void detectFacesGcs(String gcsPath, PrintStream out) throws Except } } } + // [END vision_face_detection_gcs] /** * Detects labels in the specified local image. @@ -287,6 +291,7 @@ public static void detectFacesGcs(String gcsPath, PrintStream out) throws Except * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_label_detection] public static void detectLabels(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -315,6 +320,7 @@ public static void detectLabels(String filePath, PrintStream out) throws Excepti } } } + // [END vision_label_detection] /** * Detects labels in the specified remote image on Google Cloud Storage. @@ -325,6 +331,7 @@ public static void detectLabels(String filePath, PrintStream out) throws Excepti * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_label_detection_gcs] public static void detectLabelsGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -354,6 +361,7 @@ public static void detectLabelsGcs(String gcsPath, PrintStream out) throws Excep } } } + // [END vision_label_detection_gcs] /** * Detects landmarks in the specified local image. @@ -363,6 +371,7 @@ public static void detectLabelsGcs(String gcsPath, PrintStream out) throws Excep * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_landmark_detection] public static void detectLandmarks(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -392,6 +401,7 @@ public static void detectLandmarks(String filePath, PrintStream out) throws Exce } } } + // [END vision_landmark_detection] /** * Detects landmarks in the specified URI. @@ -440,6 +450,7 @@ public static void detectLandmarksUrl(String uri, PrintStream out) throws Except * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_landmark_detection_gcs] public static void detectLandmarksGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -469,6 +480,7 @@ public static void detectLandmarksGcs(String gcsPath, PrintStream out) throws Ex } } } + // [END vision_landmark_detection_gcs] /** * Detects logos in the specified local image. @@ -478,6 +490,7 @@ public static void detectLandmarksGcs(String gcsPath, PrintStream out) throws Ex * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_logo_detection] public static void detectLogos(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -506,6 +519,7 @@ public static void detectLogos(String filePath, PrintStream out) throws Exceptio } } } + // [END vision_logo_detection] /** * Detects logos in the specified remote image on Google Cloud Storage. @@ -516,6 +530,7 @@ public static void detectLogos(String filePath, PrintStream out) throws Exceptio * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_logo_detection_gcs] public static void detectLogosGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -544,6 +559,7 @@ public static void detectLogosGcs(String gcsPath, PrintStream out) throws Except } } } + // [END vision_logo_detection_gcs] /** * Detects text in the specified image. @@ -553,6 +569,7 @@ public static void detectLogosGcs(String gcsPath, PrintStream out) throws Except * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_text_detection] public static void detectText(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -582,6 +599,7 @@ public static void detectText(String filePath, PrintStream out) throws Exception } } } + // [END vision_text_detection] /** * Detects text in the specified remote image on Google Cloud Storage. @@ -591,6 +609,7 @@ public static void detectText(String filePath, PrintStream out) throws Exception * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_text_detection_gcs] public static void detectTextGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -619,6 +638,7 @@ public static void detectTextGcs(String gcsPath, PrintStream out) throws Excepti } } } + // [END vision_text_detection_gcs] /** * Detects image properties such as color frequency from the specified local image. @@ -628,6 +648,7 @@ public static void detectTextGcs(String gcsPath, PrintStream out) throws Excepti * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_image_property_detection] public static void detectProperties(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -663,6 +684,7 @@ public static void detectProperties(String filePath, PrintStream out) throws Exc } } } + // [END vision_image_property_detection] /** * Detects image properties such as color frequency from the specified remote image on Google @@ -673,6 +695,7 @@ public static void detectProperties(String filePath, PrintStream out) throws Exc * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_image_property_detection_gcs] public static void detectPropertiesGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -707,8 +730,8 @@ public static void detectPropertiesGcs(String gcsPath, PrintStream out) throws E } } } + // [END vision_image_property_detection_gcs] - // [START vision_detect_safe_search] /** * Detects whether the specified image has features you would want to moderate. * @@ -717,6 +740,7 @@ public static void detectPropertiesGcs(String gcsPath, PrintStream out) throws E * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_safe_search_detection] public static void detectSafeSearch(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -751,9 +775,8 @@ public static void detectSafeSearch(String filePath, PrintStream out) throws Exc } } } - // [END vision_detect_safe_search] + // [END vision_safe_search_detection] - // [START vision_detect_safe_search_uri] /** * Detects whether the specified image on Google Cloud Storage has features you would want * to moderate. @@ -763,6 +786,7 @@ public static void detectSafeSearch(String filePath, PrintStream out) throws Exc * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_safe_search_detection_gcs] public static void detectSafeSearchGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -796,9 +820,9 @@ public static void detectSafeSearchGcs(String gcsPath, PrintStream out) throws E } } } - // [END vision_detect_safe_search_uri] + // [END vision_safe_search_detection_gcs] - // [START vision_detect_web] + // [START vision_web_detection] /** * Finds references to the specified image on the web. * @@ -861,9 +885,9 @@ public static void detectWebDetections(String filePath, PrintStream out) throws } } } - // [END vision_detect_web] + // [END vision_web_detection] - // [START vision_detect_web_uri] + // [START vision_web_detection_gcs] /** * Detects whether the remote image on Google Cloud Storage has features you would want to * moderate. @@ -926,7 +950,7 @@ public static void detectWebDetectionsGcs(String gcsPath, PrintStream out) throw } } } - // [END vision_detect_web_uri] + // [END vision_web_detection_gcs] /** * Find web entities given a local image. @@ -1001,7 +1025,7 @@ public static void detectWebEntitiesGcs(String gcsPath, PrintStream out) throws } } - // [START vision_web_entities_include_geo_results] + // [START vision_web_detection_include_geo] /** * Find web entities given a local image. * @param filePath The path of the image to detect. @@ -1048,9 +1072,9 @@ public static void detectWebEntitiesIncludeGeoResults(String filePath, PrintStre })); } } - // [END vision_web_entities_include_geo_results] + // [END vision_web_detection_include_geo] - // [START vision_web_entities_include_geo_results_uri] + // [START vision_web_detection_include_geo_gcs] /** * Find web entities given the remote image on Google Cloud Storage. * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities with @@ -1099,7 +1123,7 @@ public static void detectWebEntitiesIncludeGeoResultsGcs(String gcsPath, PrintSt })); } } - // [END vision_web_entities_include_geo_results_uri] + // [END vision_web_detection_include_geo_gcs] /** * Suggests a region to crop to for a local file. @@ -1109,6 +1133,7 @@ public static void detectWebEntitiesIncludeGeoResultsGcs(String gcsPath, PrintSt * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_crop_hint_detection] public static void detectCropHints(String filePath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -1139,6 +1164,7 @@ public static void detectCropHints(String filePath, PrintStream out) throws Exce } } } + // [END vision_crop_hint_detection] /** * Suggests a region to crop to for a remote file on Google Cloud Storage. @@ -1148,6 +1174,7 @@ public static void detectCropHints(String filePath, PrintStream out) throws Exce * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_crop_hint_detection_gcs] public static void detectCropHintsGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -1177,8 +1204,8 @@ public static void detectCropHintsGcs(String gcsPath, PrintStream out) throws Ex } } } + // [END vision_crop_hint_detection_gcs] - // [START vision_detect_document] /** * Performs document text detection on a local image file. * @@ -1187,8 +1214,9 @@ public static void detectCropHintsGcs(String gcsPath, PrintStream out) throws Ex * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_fulltext_detection] public static void detectDocumentText(String filePath, PrintStream out) throws Exception, - IOException { + IOException { List requests = new ArrayList<>(); ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath)); @@ -1241,9 +1269,8 @@ public static void detectDocumentText(String filePath, PrintStream out) throws E } } } - // [END vision_detect_document] + // [END vision_fulltext_detection] - // [START vision_detect_document_uri] /** * Performs document text detection on a remote image on Google Cloud Storage. * @@ -1252,6 +1279,7 @@ public static void detectDocumentText(String filePath, PrintStream out) throws E * @throws Exception on errors while closing the client. * @throws IOException on Input/Output errors. */ + // [START vision_fulltext_detection_gcs] public static void detectDocumentTextGcs(String gcsPath, PrintStream out) throws Exception, IOException { List requests = new ArrayList<>(); @@ -1304,9 +1332,9 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out) throws } } } - // [END vision_detect_document_uri] + // [END vision_fulltext_detection_gcs] - // [START vision_async_detect_document_ocr] + // [START vision_text_detection_pdf_gcs] /** * Performs document text OCR with PDF/TIFF as source files on Google Cloud Storage. * @@ -1423,5 +1451,5 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio } } } - // [END vision_async_detect_document_ocr] + // [END vision_text_detection_pdf_gcs] } diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ImportProductSets.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ImportProductSets.java index 04c0a15783e..6071e33d0ed 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ImportProductSets.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ImportProductSets.java @@ -16,7 +16,7 @@ package com.example.vision; -// [START product_search_import] +// [START vision_product_search_tutorial_import] import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.vision.v1p3beta1.BatchOperationMetadata; import com.google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource; @@ -26,7 +26,7 @@ import com.google.cloud.vision.v1p3beta1.LocationName; import com.google.cloud.vision.v1p3beta1.ProductSearchClient; import com.google.cloud.vision.v1p3beta1.ReferenceImage; - +// [END vision_product_search_tutorial_import] import java.io.PrintStream; import javax.swing.JPanel; @@ -36,7 +36,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to Import Product Sets in Cloud Vision @@ -47,7 +46,7 @@ */ public class ImportProductSets extends JPanel { - // [START product_search_import_product_sets] + // [START vision_product_search_import_product_images] /** * Import images of different products in the product set. * @@ -89,7 +88,7 @@ public static void importProductSets(String projectId, String computeRegion, Str } } } - // [END product_search_import_product_sets] + // [END vision_product_search_import_product_images] public static void main(String[] args) throws Exception { ImportProductSets importProductSet = new ImportProductSets(); diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductInProductSetManagement.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductInProductSetManagement.java index 95c38109cdf..e040d33b26b 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductInProductSetManagement.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductInProductSetManagement.java @@ -16,14 +16,12 @@ package com.example.vision; -// [START product_search_import] import com.google.cloud.vision.v1p3beta1.LocationName; import com.google.cloud.vision.v1p3beta1.Product; import com.google.cloud.vision.v1p3beta1.ProductName; import com.google.cloud.vision.v1p3beta1.ProductSearchClient; import com.google.cloud.vision.v1p3beta1.ProductSet; import com.google.cloud.vision.v1p3beta1.ProductSetName; -import com.google.cloud.vision.v1p3beta1.UpdateProductSetRequest; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -35,7 +33,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to perform basic operations with Products in a Product Set. @@ -46,57 +43,9 @@ public class ProductInProductSetManagement { - // [START product_search_add_product_to_product_set] + // [START vision_product_search_add_product_to_product_set] /** - * Update a product set. - * - * @param projectId - Id of the project. - * @param computeRegion - Region name. - * @param productSetId - Id of the product set. - * @param productSetDisplayName - Display name of the product set. - * @throws IOException - on I/O errors. - */ - public static void addProductToProductSet( - String projectId, String computeRegion, String productSetId, String productSetDisplayName) - throws IOException { - ProductSearchClient client = ProductSearchClient.create(); - - // Get the full path of the product set. - String productSetPath = ProductSetName.of(projectId, computeRegion, productSetId).toString(); - - // Update the product set display name. - ProductSet productSet = - ProductSet.newBuilder() - .setName(productSetPath) - .setDisplayName(productSetDisplayName) - .build(); - - FieldMask updateMask = FieldMask.newBuilder().addPaths("display_name").build(); - - UpdateProductSetRequest request = - UpdateProductSetRequest.newBuilder() - .setProductSet(productSet) - .setUpdateMask(updateMask) - .build(); - - ProductSet updatedProductSet = client.updateProductSet(request); - - // Display the updated set information - System.out.println(String.format("Product set name: %s", updatedProductSet.getName())); - System.out.println( - String.format( - "Product set id: %s", - updatedProductSet - .getName() - .substring(updatedProductSet.getName().lastIndexOf('/') + 1))); - System.out.println( - String.format("Updated product set display name: %s", updatedProductSet.getDisplayName())); - } - // [END product_search_add_product_to_product_set] - - // [START product_search_remove_product_from_product_set] - /** - * Remove a product from a product set. + * Add a product to a product set. * * @param projectId - Id of the project. * @param computeRegion - Region name. @@ -104,7 +53,7 @@ public static void addProductToProductSet( * @param productSetId - Id of the product set. * @throws IOException - on I/O errors. */ - public static void removeProductFromProductSet( + public static void addProductToSet( String projectId, String computeRegion, String productId, String productSetId) throws IOException { ProductSearchClient client = ProductSearchClient.create(); @@ -115,14 +64,14 @@ public static void removeProductFromProductSet( // Get the full path of the product. String productPath = ProductName.of(projectId, computeRegion, productId).toString(); - // Remove the product from the product set. - client.removeProductFromProductSet(productSetPath, productPath); + // Add the product to the product set. + client.addProductToProductSet(productSetPath, productPath); - System.out.println(String.format("Product removed from product set.")); + System.out.println(String.format("Product added to product set.")); } - // [END product_search_remove_product_from_product_set] + // [END vision_product_search_add_product_to_product_set] - // [START product_search_list_products_in_product_set] + // [START vision_product_search_list_products_in_product_set] /** * List all products in a product set. * @@ -154,38 +103,35 @@ public static void listProductsInProductSet( String.format("Product labels: %s\n", product.getProductLabelsList().toString())); } } - // [END product_search_list_products_in_product_set] + // [END vision_product_search_list_products_in_product_set] - // [START product_search_list_products] + // [START vision_product_search_remove_product_from_product_set] /** - * List all products. + * Remove a product from a product set. * * @param projectId - Id of the project. * @param computeRegion - Region name. + * @param productId - Id of the product. + * @param productSetId - Id of the product set. * @throws IOException - on I/O errors. */ - public static void listProducts(String projectId, String computeRegion) throws IOException { + public static void removeProductFromProductSet( + String projectId, String computeRegion, String productId, String productSetId) + throws IOException { ProductSearchClient client = ProductSearchClient.create(); - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, computeRegion); + // Get the full path of the product set. + ProductSetName productSetPath = ProductSetName.of(projectId, computeRegion, productSetId); + + // Get the full path of the product. + String productPath = ProductName.of(projectId, computeRegion, productId).toString(); - // List all the products available in the region. - for (Product product : client.listProducts(projectLocation).iterateAll()) { - // Display the product information - System.out.println(String.format("\nProduct name: %s", product.getName())); - System.out.println( - String.format( - "Product id: %s", - product.getName().substring(product.getName().lastIndexOf('/') + 1))); - System.out.println(String.format("Product display name: %s", product.getDisplayName())); - System.out.println(String.format("Product category: %s", product.getProductCategory())); - System.out.println("Product labels:"); - System.out.println( - String.format("Product labels: %s", product.getProductLabelsList().toString())); - } + // Remove the product from the product set. + client.removeProductFromProductSet(productSetPath, productPath); + + System.out.println(String.format("Product removed from product set.")); } - // [END product_search_list_products] + // [END vision_product_search_remove_product_from_product_set] public static void main(String[] args) throws Exception { ProductInProductSetManagement productInProductSetManagement = @@ -196,15 +142,14 @@ public static void main(String[] args) throws Exception { public static void argsHelper(String[] args, PrintStream out) throws Exception { ArgumentParser parser = ArgumentParsers.newFor("").build(); Subparsers subparsers = parser.addSubparsers().dest("command"); - subparsers.addParser("list_products"); + + Subparser addProductParser = subparsers.addParser("add_product_to_product_set"); + addProductParser.addArgument("productSetId"); + addProductParser.addArgument("productId"); Subparser listProductInProductSetParser = subparsers.addParser("list_products_in_product_set"); listProductInProductSetParser.addArgument("productSetId"); - Subparser updateProductSetParser = subparsers.addParser("update_product_set"); - updateProductSetParser.addArgument("productSetId"); - updateProductSetParser.addArgument("productSetDisplayName"); - Subparser removeProductFromProductSetParser = subparsers.addParser("remove_product_from_product_set"); removeProductFromProductSetParser.addArgument("productId"); @@ -216,23 +161,17 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { Namespace ns = null; try { ns = parser.parseArgs(args); - if (ns.get("command").equals("list_products")) { - listProducts(projectId, computeRegion); + if (ns.get("command").equals("add_product_to_product_set")) { + addProductToSet( + projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId")); } - if (ns.get("command").equals("update_product_set")) { - addProductToProductSet( - projectId, - computeRegion, - ns.getString("productSetId"), - ns.getString("productSetDisplayName")); + if (ns.get("command").equals("list_products_in_product_set")) { + listProductsInProductSet(projectId, computeRegion, ns.getString("productSetId")); } if (ns.get("command").equals("remove_product_from_product_set")) { removeProductFromProductSet( projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId")); } - if (ns.get("command").equals("list_products_in_product_set")) { - listProductsInProductSet(projectId, computeRegion, ns.getString("productSetId")); - } } catch (ArgumentParserException e) { parser.handleError(e); diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductManagement.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductManagement.java index c026b4913e0..0d6661913d1 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductManagement.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductManagement.java @@ -16,7 +16,6 @@ package com.example.vision; -// [START product_search_import] import com.google.cloud.vision.v1p3beta1.LocationName; import com.google.cloud.vision.v1p3beta1.Product; import com.google.cloud.vision.v1p3beta1.Product.KeyValue; @@ -33,7 +32,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to perform basic operations on Products. @@ -44,7 +42,7 @@ public class ProductManagement { - // [START product_search_create_product] + // [START vision_product_search_create_product] /** * Create one product. * @@ -90,9 +88,9 @@ public static void createProduct( // Display the product information System.out.println(String.format("Product name: %s", product.getName())); } - // [END product_search_create_product] + // [END vision_product_search_create_product] - // [START product_search_list_products] + // [START vision_product_search_list_products] /** * List all products. * @@ -121,9 +119,9 @@ public static void listProducts(String projectId, String computeRegion) throws I String.format("Product labels: %s", product.getProductLabelsList().toString())); } } - // [END product_search_list_products] + // [END vision_product_search_list_products] - // [START product_search_get_product] + // [START vision_product_search_get_product] /** * Get information about a product. * @@ -154,9 +152,9 @@ public static void getProduct(String projectId, String computeRegion, String pro System.out.println( String.format("Product labels: %s", product.getProductLabelsList().toString())); } - // [END product_search_get_product] + // [END vision_product_search_get_product] - // [START product_search_update_product_labels] + // [START vision_product_search_update_product_labels] /** * Update the product labels. * @@ -198,9 +196,9 @@ public static void updateProductLabels( String.format( "Updated product labels: %s", updatedProduct.getProductLabelsList().toString())); } - // [END product_search_update_product_labels] + // [END vision_product_search_update_product_labels] - // [START product_search_delete_product] + // [START vision_product_search_delete_product] /** * Delete the product and all its reference images. * @@ -221,7 +219,7 @@ public static void deleteProduct(String projectId, String computeRegion, String System.out.println("Product deleted."); } - // [END product_search_delete_product] + // [END vision_product_search_delete_product] public static void main(String[] args) throws Exception { ProductManagement productManagement = new ProductManagement(); diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSearch.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSearch.java index 91abb208331..d36fa6e24c4 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSearch.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSearch.java @@ -16,7 +16,6 @@ package com.example.vision; -// [START product_search_import] import com.google.cloud.vision.v1p3beta1.AnnotateImageRequest; import com.google.cloud.vision.v1p3beta1.BatchAnnotateImagesResponse; import com.google.cloud.vision.v1p3beta1.Feature; @@ -42,7 +41,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to perform similar product search operation in Cloud Vision @@ -54,7 +52,7 @@ public class ProductSearch { - // [START product_search_get_similar_products_file] + // [START vision_product_search_get_similar_products] /** * Search similar products to image. * @@ -130,7 +128,7 @@ public static void getSimilarProducts( System.out.println(String.format("Image name: %s", product.getImage())); } } - // [END product_search_get_similar_products_file] + // [END vision_product_search_get_similar_products] public static void main(String[] args) throws Exception { ProductSearch productSearch = new ProductSearch(); diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSetManagement.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSetManagement.java index ea362c43c91..d5ed87955fb 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSetManagement.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ProductSetManagement.java @@ -16,7 +16,6 @@ package com.example.vision; -// [START product_search_import] import com.google.cloud.vision.v1p3beta1.CreateProductSetRequest; import com.google.cloud.vision.v1p3beta1.LocationName; import com.google.cloud.vision.v1p3beta1.Product; @@ -34,7 +33,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to perform basic operations on Product Sets. @@ -45,7 +43,7 @@ public class ProductSetManagement { - // [START product_search_create_product_set] + // [START vision_product_search_create_product_set] /** * Create a product set * @@ -76,9 +74,9 @@ public static void createProductSet( // Display the product set information System.out.println(String.format("Product set name: %s", productSet.getName())); } - // [END product_search_create_product_set] + // [END vision_product_search_create_product_set] - // [START product_search_list_product_sets] + // [START vision_product_search_list_product_sets] /** * List all product sets * @@ -107,9 +105,9 @@ public static void listProductSets(String projectId, String computeRegion) throw System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos())); } } - // [END product_search_list_product_sets] + // [END vision_product_search_list_product_sets] - // [START product_search_get_product_set] + // [START vision_product_search_get_product_set] /** * Get info about the product set. * @@ -139,71 +137,9 @@ public static void getProductSet(String projectId, String computeRegion, String System.out.println(String.format("\tseconds: %s", productSet.getIndexTime().getSeconds())); System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos())); } - // [END product_search_get_product_set] + // [END vision_product_search_get_product_set] - // [START product_search_list_products_in_product_set] - /** - * List all products in a product set. - * - * @param projectId - Id of the project. - * @param computeRegion - Region name. - * @param productSetId - Id of the product set. - * @throws IOException - on I/O errors. - */ - public static void listProductsInSet(String projectId, String computeRegion, String productSetId) - throws IOException { - ProductSearchClient client = ProductSearchClient.create(); - - // Get the full path of the product set. - ProductSetName productSetPath = ProductSetName.of(projectId, computeRegion, productSetId); - - // List all the products available in the product set. - for (Product product : - client.listProductsInProductSet(productSetPath.toString()).iterateAll()) { - // Display the product information - System.out.println(String.format("Product name: %s", product.getName())); - System.out.println( - String.format( - "Product id: %s", - product.getName().substring(product.getName().lastIndexOf('/') + 1))); - System.out.println(String.format("Product display name: %s", product.getDisplayName())); - System.out.println(String.format("Product description: %s", product.getDescription())); - System.out.println(String.format("Product category: %s", product.getProductCategory())); - System.out.println( - String.format("Product labels: %s\n", product.getProductLabelsList().toString())); - } - } - // [END product_search_list_products_in_product_set] - - // [START product_search_add_product_to_product_set] - /** - * Add a product to a product set. - * - * @param projectId - Id of the project. - * @param computeRegion - Region name. - * @param productId - Id of the product. - * @param productSetId - Id of the product set. - * @throws IOException - on I/O errors. - */ - public static void addProductToSet( - String projectId, String computeRegion, String productId, String productSetId) - throws IOException { - ProductSearchClient client = ProductSearchClient.create(); - - // Get the full path of the product set. - ProductSetName productSetPath = ProductSetName.of(projectId, computeRegion, productSetId); - - // Get the full path of the product. - String productPath = ProductName.of(projectId, computeRegion, productId).toString(); - - // Add the product to the product set. - client.addProductToProductSet(productSetPath, productPath); - - System.out.println(String.format("Product added to product set.")); - } - // [END product_search_add_product_to_product_set] - - // [START product_search_delete_product_set] + // [START vision_product_search_delete_product_set] /** * Delete a product set. * @@ -224,7 +160,7 @@ public static void deleteProductSet( System.out.println(String.format("Product set deleted")); } - // [END product_search_delete_product_set] + // [END vision_product_search_delete_product_set] public static void main(String[] args) throws Exception { ProductSetManagement productSetManagement = new ProductSetManagement(); @@ -239,18 +175,11 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { createProductSetParser.addArgument("productSetId"); createProductSetParser.addArgument("productSetDisplayName"); - Subparser addProductParser = subparsers.addParser("add_product_to_product_set"); - addProductParser.addArgument("productSetId"); - addProductParser.addArgument("productId"); - subparsers.addParser("list_product_sets"); Subparser getProductSetParser = subparsers.addParser("get_product_set"); getProductSetParser.addArgument("productSetId"); - Subparser listProductsInProductSetParser = subparsers.addParser("list_products_in_product_set"); - listProductsInProductSetParser.addArgument("productSetId"); - Subparser deleteProductSetParser = subparsers.addParser("delete_product_set"); deleteProductSetParser.addArgument("productSetId"); @@ -273,13 +202,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { if (ns.get("command").equals("get_product_set")) { getProductSet(projectId, computeRegion, ns.getString("productSetId")); } - if (ns.get("command").equals("add_product_to_product_set")) { - addProductToSet( - projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId")); - } - if (ns.get("command").equals("list_products_in_product_set")) { - listProductsInSet(projectId, computeRegion, ns.getString("productSetId")); - } if (ns.get("command").equals("delete_product_set")) { deleteProductSet(projectId, computeRegion, ns.getString("productSetId")); } diff --git a/vision/product-search/cloud-client/src/main/java/com/example/vision/ReferenceImageManagement.java b/vision/product-search/cloud-client/src/main/java/com/example/vision/ReferenceImageManagement.java index 11a6164e5ec..7618b3d796c 100644 --- a/vision/product-search/cloud-client/src/main/java/com/example/vision/ReferenceImageManagement.java +++ b/vision/product-search/cloud-client/src/main/java/com/example/vision/ReferenceImageManagement.java @@ -17,7 +17,6 @@ package com.example.vision; -// [START product_search_import] import com.google.cloud.vision.v1p3beta1.ProductName; import com.google.cloud.vision.v1p3beta1.ProductSearchClient; import com.google.cloud.vision.v1p3beta1.ReferenceImage; @@ -32,7 +31,6 @@ import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparsers; -// [END product_search_import] /** * This application demonstrates how to perform basic operations on Reference Images in Cloud Vision @@ -44,7 +42,7 @@ public class ReferenceImageManagement { - // [START product_search_create_reference_image] + // [START vision_product_search_create_reference_image] /** * Create a reference image. * @@ -76,9 +74,9 @@ public static void createReferenceImage( System.out.println(String.format("Reference image name: %s", image.getName())); System.out.println(String.format("Reference image uri: %s", image.getUri())); } - // [END product_search_create_reference_image] + // [END vision_product_search_create_reference_image] - // [START product_search_list_reference_images] + // [START vision_product_search_list_reference_images] /** * List all images in a product. * @@ -107,9 +105,9 @@ public static void listReferenceImagesOfProduct( "Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString())); } } - // [END product_search_list_reference_images] + // [END vision_product_search_list_reference_images] - // [START product_search_get_reference_image] + // [START vision_product_search_get_reference_image] /** * Get info about a reference image. * @@ -142,9 +140,9 @@ public static void getReferenceImage( String.format( "Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString())); } - // [END product_search_get_reference_image] + // [END vision_product_search_get_reference_image] - // [START product_search_delete_reference_image] + // [START vision_product_search_delete_reference_image] /** * Delete a reference image. * @@ -167,7 +165,7 @@ public static void deleteReferenceImage( client.deleteReferenceImage(referenceImagePath.toString()); System.out.println("Reference image deleted from product."); } - // [END product_search_delete_reference_image] + // [END vision_product_search_delete_reference_image] public static void main(String[] args) throws Exception { ReferenceImageManagement referenceImageManagement = new ReferenceImageManagement();