Skip to content

Commit 3ab6fff

Browse files
alixhamichingor13
authored andcommitted
samples: Vision region tag update (#1182)
* updates region tags for detecting-crop-hints page * updates region tags for detecting-faces page * updates region tags for detecting-fulltext page * updates region tags for detecting-labels page * updates region tags for detecting-landmarks page * update region tags for detect-logos page * update region tags for detecting-properties page * update region tags for detecting-safe-search page * update region tags for detecting-text page * update region tags for detecting-web page * update beta tags to standard * update PDF detection region tags to standard * updates product search region tags to standard * fix label detection tag * remove region tags from imports * updates to mirror python files * Fix indentation
1 parent 6e92e60 commit 3ab6fff

File tree

6 files changed

+67
-213
lines changed

6 files changed

+67
-213
lines changed

vision/snippets/src/main/java/com/example/vision/ImportProductSets.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.example.vision;
1818

19-
// [START product_search_import]
19+
// [START vision_product_search_tutorial_import]
2020
import com.google.api.gax.longrunning.OperationFuture;
2121
import com.google.cloud.vision.v1p3beta1.BatchOperationMetadata;
2222
import com.google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource;
@@ -26,7 +26,7 @@
2626
import com.google.cloud.vision.v1p3beta1.LocationName;
2727
import com.google.cloud.vision.v1p3beta1.ProductSearchClient;
2828
import com.google.cloud.vision.v1p3beta1.ReferenceImage;
29-
29+
// [END vision_product_search_tutorial_import]
3030
import java.io.PrintStream;
3131
import javax.swing.JPanel;
3232

@@ -36,7 +36,6 @@
3636
import net.sourceforge.argparse4j.inf.Namespace;
3737
import net.sourceforge.argparse4j.inf.Subparser;
3838
import net.sourceforge.argparse4j.inf.Subparsers;
39-
// [END product_search_import]
4039

4140
/**
4241
* This application demonstrates how to Import Product Sets in Cloud Vision
@@ -47,7 +46,7 @@
4746
*/
4847

4948
public class ImportProductSets extends JPanel {
50-
// [START product_search_import_product_sets]
49+
// [START vision_product_search_import_product_images]
5150
/**
5251
* Import images of different products in the product set.
5352
*
@@ -89,7 +88,7 @@ public static void importProductSets(String projectId, String computeRegion, Str
8988
}
9089
}
9190
}
92-
// [END product_search_import_product_sets]
91+
// [END vision_product_search_import_product_images]
9392

9493
public static void main(String[] args) throws Exception {
9594
ImportProductSets importProductSet = new ImportProductSets();

vision/snippets/src/main/java/com/example/vision/ProductInProductSetManagement.java

+35-96
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package com.example.vision;
1818

19-
// [START product_search_import]
2019
import com.google.cloud.vision.v1p3beta1.LocationName;
2120
import com.google.cloud.vision.v1p3beta1.Product;
2221
import com.google.cloud.vision.v1p3beta1.ProductName;
2322
import com.google.cloud.vision.v1p3beta1.ProductSearchClient;
2423
import com.google.cloud.vision.v1p3beta1.ProductSet;
2524
import com.google.cloud.vision.v1p3beta1.ProductSetName;
26-
import com.google.cloud.vision.v1p3beta1.UpdateProductSetRequest;
2725
import com.google.protobuf.FieldMask;
2826

2927
import java.io.IOException;
@@ -35,7 +33,6 @@
3533
import net.sourceforge.argparse4j.inf.Namespace;
3634
import net.sourceforge.argparse4j.inf.Subparser;
3735
import net.sourceforge.argparse4j.inf.Subparsers;
38-
// [END product_search_import]
3936

4037
/**
4138
* This application demonstrates how to perform basic operations with Products in a Product Set.
@@ -46,65 +43,17 @@
4643

4744
public class ProductInProductSetManagement {
4845

49-
// [START product_search_add_product_to_product_set]
46+
// [START vision_product_search_add_product_to_product_set]
5047
/**
51-
* Update a product set.
52-
*
53-
* @param projectId - Id of the project.
54-
* @param computeRegion - Region name.
55-
* @param productSetId - Id of the product set.
56-
* @param productSetDisplayName - Display name of the product set.
57-
* @throws IOException - on I/O errors.
58-
*/
59-
public static void addProductToProductSet(
60-
String projectId, String computeRegion, String productSetId, String productSetDisplayName)
61-
throws IOException {
62-
ProductSearchClient client = ProductSearchClient.create();
63-
64-
// Get the full path of the product set.
65-
String productSetPath = ProductSetName.of(projectId, computeRegion, productSetId).toString();
66-
67-
// Update the product set display name.
68-
ProductSet productSet =
69-
ProductSet.newBuilder()
70-
.setName(productSetPath)
71-
.setDisplayName(productSetDisplayName)
72-
.build();
73-
74-
FieldMask updateMask = FieldMask.newBuilder().addPaths("display_name").build();
75-
76-
UpdateProductSetRequest request =
77-
UpdateProductSetRequest.newBuilder()
78-
.setProductSet(productSet)
79-
.setUpdateMask(updateMask)
80-
.build();
81-
82-
ProductSet updatedProductSet = client.updateProductSet(request);
83-
84-
// Display the updated set information
85-
System.out.println(String.format("Product set name: %s", updatedProductSet.getName()));
86-
System.out.println(
87-
String.format(
88-
"Product set id: %s",
89-
updatedProductSet
90-
.getName()
91-
.substring(updatedProductSet.getName().lastIndexOf('/') + 1)));
92-
System.out.println(
93-
String.format("Updated product set display name: %s", updatedProductSet.getDisplayName()));
94-
}
95-
// [END product_search_add_product_to_product_set]
96-
97-
// [START product_search_remove_product_from_product_set]
98-
/**
99-
* Remove a product from a product set.
48+
* Add a product to a product set.
10049
*
10150
* @param projectId - Id of the project.
10251
* @param computeRegion - Region name.
10352
* @param productId - Id of the product.
10453
* @param productSetId - Id of the product set.
10554
* @throws IOException - on I/O errors.
10655
*/
107-
public static void removeProductFromProductSet(
56+
public static void addProductToSet(
10857
String projectId, String computeRegion, String productId, String productSetId)
10958
throws IOException {
11059
ProductSearchClient client = ProductSearchClient.create();
@@ -115,14 +64,14 @@ public static void removeProductFromProductSet(
11564
// Get the full path of the product.
11665
String productPath = ProductName.of(projectId, computeRegion, productId).toString();
11766

118-
// Remove the product from the product set.
119-
client.removeProductFromProductSet(productSetPath, productPath);
67+
// Add the product to the product set.
68+
client.addProductToProductSet(productSetPath, productPath);
12069

121-
System.out.println(String.format("Product removed from product set."));
70+
System.out.println(String.format("Product added to product set."));
12271
}
123-
// [END product_search_remove_product_from_product_set]
72+
// [END vision_product_search_add_product_to_product_set]
12473

125-
// [START product_search_list_products_in_product_set]
74+
// [START vision_product_search_list_products_in_product_set]
12675
/**
12776
* List all products in a product set.
12877
*
@@ -154,38 +103,35 @@ public static void listProductsInProductSet(
154103
String.format("Product labels: %s\n", product.getProductLabelsList().toString()));
155104
}
156105
}
157-
// [END product_search_list_products_in_product_set]
106+
// [END vision_product_search_list_products_in_product_set]
158107

159-
// [START product_search_list_products]
108+
// [START vision_product_search_remove_product_from_product_set]
160109
/**
161-
* List all products.
110+
* Remove a product from a product set.
162111
*
163112
* @param projectId - Id of the project.
164113
* @param computeRegion - Region name.
114+
* @param productId - Id of the product.
115+
* @param productSetId - Id of the product set.
165116
* @throws IOException - on I/O errors.
166117
*/
167-
public static void listProducts(String projectId, String computeRegion) throws IOException {
118+
public static void removeProductFromProductSet(
119+
String projectId, String computeRegion, String productId, String productSetId)
120+
throws IOException {
168121
ProductSearchClient client = ProductSearchClient.create();
169122

170-
// A resource that represents Google Cloud Platform location.
171-
LocationName projectLocation = LocationName.of(projectId, computeRegion);
123+
// Get the full path of the product set.
124+
ProductSetName productSetPath = ProductSetName.of(projectId, computeRegion, productSetId);
125+
126+
// Get the full path of the product.
127+
String productPath = ProductName.of(projectId, computeRegion, productId).toString();
172128

173-
// List all the products available in the region.
174-
for (Product product : client.listProducts(projectLocation).iterateAll()) {
175-
// Display the product information
176-
System.out.println(String.format("\nProduct name: %s", product.getName()));
177-
System.out.println(
178-
String.format(
179-
"Product id: %s",
180-
product.getName().substring(product.getName().lastIndexOf('/') + 1)));
181-
System.out.println(String.format("Product display name: %s", product.getDisplayName()));
182-
System.out.println(String.format("Product category: %s", product.getProductCategory()));
183-
System.out.println("Product labels:");
184-
System.out.println(
185-
String.format("Product labels: %s", product.getProductLabelsList().toString()));
186-
}
129+
// Remove the product from the product set.
130+
client.removeProductFromProductSet(productSetPath, productPath);
131+
132+
System.out.println(String.format("Product removed from product set."));
187133
}
188-
// [END product_search_list_products]
134+
// [END vision_product_search_remove_product_from_product_set]
189135

190136
public static void main(String[] args) throws Exception {
191137
ProductInProductSetManagement productInProductSetManagement =
@@ -196,15 +142,14 @@ public static void main(String[] args) throws Exception {
196142
public static void argsHelper(String[] args, PrintStream out) throws Exception {
197143
ArgumentParser parser = ArgumentParsers.newFor("").build();
198144
Subparsers subparsers = parser.addSubparsers().dest("command");
199-
subparsers.addParser("list_products");
145+
146+
Subparser addProductParser = subparsers.addParser("add_product_to_product_set");
147+
addProductParser.addArgument("productSetId");
148+
addProductParser.addArgument("productId");
200149

201150
Subparser listProductInProductSetParser = subparsers.addParser("list_products_in_product_set");
202151
listProductInProductSetParser.addArgument("productSetId");
203152

204-
Subparser updateProductSetParser = subparsers.addParser("update_product_set");
205-
updateProductSetParser.addArgument("productSetId");
206-
updateProductSetParser.addArgument("productSetDisplayName");
207-
208153
Subparser removeProductFromProductSetParser =
209154
subparsers.addParser("remove_product_from_product_set");
210155
removeProductFromProductSetParser.addArgument("productId");
@@ -216,23 +161,17 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception {
216161
Namespace ns = null;
217162
try {
218163
ns = parser.parseArgs(args);
219-
if (ns.get("command").equals("list_products")) {
220-
listProducts(projectId, computeRegion);
164+
if (ns.get("command").equals("add_product_to_product_set")) {
165+
addProductToSet(
166+
projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId"));
221167
}
222-
if (ns.get("command").equals("update_product_set")) {
223-
addProductToProductSet(
224-
projectId,
225-
computeRegion,
226-
ns.getString("productSetId"),
227-
ns.getString("productSetDisplayName"));
168+
if (ns.get("command").equals("list_products_in_product_set")) {
169+
listProductsInProductSet(projectId, computeRegion, ns.getString("productSetId"));
228170
}
229171
if (ns.get("command").equals("remove_product_from_product_set")) {
230172
removeProductFromProductSet(
231173
projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId"));
232174
}
233-
if (ns.get("command").equals("list_products_in_product_set")) {
234-
listProductsInProductSet(projectId, computeRegion, ns.getString("productSetId"));
235-
}
236175

237176
} catch (ArgumentParserException e) {
238177
parser.handleError(e);

vision/snippets/src/main/java/com/example/vision/ProductManagement.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.example.vision;
1818

19-
// [START product_search_import]
2019
import com.google.cloud.vision.v1p3beta1.LocationName;
2120
import com.google.cloud.vision.v1p3beta1.Product;
2221
import com.google.cloud.vision.v1p3beta1.Product.KeyValue;
@@ -33,7 +32,6 @@
3332
import net.sourceforge.argparse4j.inf.Namespace;
3433
import net.sourceforge.argparse4j.inf.Subparser;
3534
import net.sourceforge.argparse4j.inf.Subparsers;
36-
// [END product_search_import]
3735

3836
/**
3937
* This application demonstrates how to perform basic operations on Products.
@@ -44,7 +42,7 @@
4442

4543
public class ProductManagement {
4644

47-
// [START product_search_create_product]
45+
// [START vision_product_search_create_product]
4846
/**
4947
* Create one product.
5048
*
@@ -90,9 +88,9 @@ public static void createProduct(
9088
// Display the product information
9189
System.out.println(String.format("Product name: %s", product.getName()));
9290
}
93-
// [END product_search_create_product]
91+
// [END vision_product_search_create_product]
9492

95-
// [START product_search_list_products]
93+
// [START vision_product_search_list_products]
9694
/**
9795
* List all products.
9896
*
@@ -121,9 +119,9 @@ public static void listProducts(String projectId, String computeRegion) throws I
121119
String.format("Product labels: %s", product.getProductLabelsList().toString()));
122120
}
123121
}
124-
// [END product_search_list_products]
122+
// [END vision_product_search_list_products]
125123

126-
// [START product_search_get_product]
124+
// [START vision_product_search_get_product]
127125
/**
128126
* Get information about a product.
129127
*
@@ -154,9 +152,9 @@ public static void getProduct(String projectId, String computeRegion, String pro
154152
System.out.println(
155153
String.format("Product labels: %s", product.getProductLabelsList().toString()));
156154
}
157-
// [END product_search_get_product]
155+
// [END vision_product_search_get_product]
158156

159-
// [START product_search_update_product_labels]
157+
// [START vision_product_search_update_product_labels]
160158
/**
161159
* Update the product labels.
162160
*
@@ -198,9 +196,9 @@ public static void updateProductLabels(
198196
String.format(
199197
"Updated product labels: %s", updatedProduct.getProductLabelsList().toString()));
200198
}
201-
// [END product_search_update_product_labels]
199+
// [END vision_product_search_update_product_labels]
202200

203-
// [START product_search_delete_product]
201+
// [START vision_product_search_delete_product]
204202
/**
205203
* Delete the product and all its reference images.
206204
*
@@ -221,7 +219,7 @@ public static void deleteProduct(String projectId, String computeRegion, String
221219

222220
System.out.println("Product deleted.");
223221
}
224-
// [END product_search_delete_product]
222+
// [END vision_product_search_delete_product]
225223

226224
public static void main(String[] args) throws Exception {
227225
ProductManagement productManagement = new ProductManagement();

vision/snippets/src/main/java/com/example/vision/ProductSearch.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.example.vision;
1818

19-
// [START product_search_import]
2019
import com.google.cloud.vision.v1p3beta1.AnnotateImageRequest;
2120
import com.google.cloud.vision.v1p3beta1.BatchAnnotateImagesResponse;
2221
import com.google.cloud.vision.v1p3beta1.Feature;
@@ -42,7 +41,6 @@
4241
import net.sourceforge.argparse4j.inf.Namespace;
4342
import net.sourceforge.argparse4j.inf.Subparser;
4443
import net.sourceforge.argparse4j.inf.Subparsers;
45-
// [END product_search_import]
4644

4745
/**
4846
* This application demonstrates how to perform similar product search operation in Cloud Vision
@@ -54,7 +52,7 @@
5452

5553
public class ProductSearch {
5654

57-
// [START product_search_get_similar_products_file]
55+
// [START vision_product_search_get_similar_products]
5856
/**
5957
* Search similar products to image.
6058
*
@@ -130,7 +128,7 @@ public static void getSimilarProducts(
130128
System.out.println(String.format("Image name: %s", product.getImage()));
131129
}
132130
}
133-
// [END product_search_get_similar_products_file]
131+
// [END vision_product_search_get_similar_products]
134132

135133
public static void main(String[] args) throws Exception {
136134
ProductSearch productSearch = new ProductSearch();

0 commit comments

Comments
 (0)