1616import java .io .File ;
1717import java .net .URL ;
1818import java .util .HashMap ;
19+ import java .util .ListIterator ;
1920import java .util .Map ;
2021
2122import com .ibm .watson .developer_cloud .alchemy .v1 .model .AlchemyGenericModel ;
2223import com .ibm .watson .developer_cloud .alchemy .v1 .model .ImageFaces ;
24+ import com .ibm .watson .developer_cloud .alchemy .v1 .model .ImageKeyword ;
2325import com .ibm .watson .developer_cloud .alchemy .v1 .model .ImageKeywords ;
2426import com .ibm .watson .developer_cloud .alchemy .v1 .model .ImageLink ;
2527import com .ibm .watson .developer_cloud .alchemy .v1 .model .ImageSceneText ;
@@ -71,6 +73,9 @@ public class AlchemyVision extends AlchemyService {
7173 /** The Constant URL. (value is "url") */
7274 public static final String URL = "url" ;
7375
76+ /** The Constant NO_TAGS. (value is "NO_TAGS") */
77+ private static final String NO_TAGS = "NO_TAGS" ;
78+
7479 /**
7580 * Executes the request and return the POJO that represent the response.
7681 *
@@ -93,11 +98,11 @@ private <T extends AlchemyGenericModel> T executeRequest(Map<String, Object> par
9398 params .put (IMAGE_POST_MODE , RAW );
9499 final File image = (File ) params .get (IMAGE );
95100 if (!image .exists ()) {
96- throw new IllegalArgumentException ("The file: " + image . getAbsolutePath ()
97- + " does not exist." );
101+ throw new IllegalArgumentException (
102+ "The file: " + image . getAbsolutePath () + " does not exist." );
98103 } else {
99- requestBuilder . withBody ( RequestBody . create ( HttpMediaType . BINARY_FILE ,
100- (File ) params .get (IMAGE )));
104+ requestBuilder
105+ . withBody ( RequestBody . create ( HttpMediaType . BINARY_FILE , (File ) params .get (IMAGE )));
101106 params .remove (IMAGE );
102107 }
103108 }
@@ -133,22 +138,23 @@ public ImageSceneText getImageSceneText(File image) {
133138
134139 return executeRequest (params , AlchemyAPI .image_scene_text , ImageSceneText .class );
135140 }
136-
141+
137142 /**
138- * Identifies text in an image specified by URL or in the primary image in a web page specified by URL
143+ * Identifies text in an image specified by URL or in the primary image in a web page specified by
144+ * URL
139145 *
140146 * @param url the image URL
141147 * @return {@link ImageSceneText}
142148 */
143149 public ImageSceneText getImageSceneText (URL url ) {
144150 Validate .notNull (url , "url cannot be null" );
145-
151+
146152 final Map <String , Object > params = new HashMap <String , Object >();
147153 params .put (URL , url );
148-
154+
149155 return executeRequest (params , AlchemyAPI .image_scene_text , ImageSceneText .class );
150156 }
151-
157+
152158 /**
153159 * Extracts keywords from an image
154160 *
@@ -170,7 +176,16 @@ public ImageKeywords getImageKeywords(File image, Boolean forceShowAll, Boolean
170176 if (knowledgeGraph != null )
171177 params .put (KNOWLEDGE_GRAPH , knowledgeGraph ? 1 : 0 );
172178
173- return executeRequest (params , AlchemyAPI .image_keywords , ImageKeywords .class );
179+ ImageKeywords imageKeywords = executeRequest (params , AlchemyAPI .image_keywords , ImageKeywords .class );
180+
181+ // Remove the NO_TAGS keywords
182+ ListIterator <ImageKeyword > iter = imageKeywords .getImageKeywords ().listIterator ();
183+ while (iter .hasNext ()){
184+ if (iter .next ().getText ().equals (NO_TAGS )){
185+ iter .remove ();
186+ }
187+ }
188+ return imageKeywords ;
174189 }
175190
176191
0 commit comments