@@ -834,13 +834,13 @@ Vision.prototype.detect = function(images, options, callback) {
834834 * // }
835835 * // },
836836 * // confidence: 56.748849,
837- * // blurry : false,
838- * // dark : false,
839- * // happy : false,
840- * // hat : false,
841- * // mad : false,
842- * // sad : false,
843- * // surprised : false
837+ * // anger : false,
838+ * // blurred : false,
839+ * // headwear : false,
840+ * // joy : false,
841+ * // sorrow : false,
842+ * // surprise : false,
843+ * // underExposed : false
844844 * // }
845845 * // ]
846846 * });
@@ -1343,36 +1343,6 @@ Vision.prototype.detectText = function(images, options, callback) {
13431343 this . detect ( images , options , callback ) ;
13441344} ;
13451345
1346- /**
1347- * Convert an object with "likelihood" values to a boolean-representation, based
1348- * on the lowest likelihood provided.
1349- *
1350- * @private
1351- *
1352- * @example
1353- * Vision.convertToBoolean_(Vision.likelihood.VERY_LIKELY, {
1354- * blurry: 'POSSIBLE'
1355- * });
1356- * // { blurry: false }
1357- *
1358- * Vision.convertToBoolean_(Vision.likelihood.UNLIKELY, {
1359- * blurry: 'POSSIBLE'
1360- * });
1361- * // { blurry: true }
1362- */
1363- Vision . convertToBoolean_ = function ( baseLikelihood , object ) {
1364- var convertedObject = { } ;
1365-
1366- for ( var prop in object ) {
1367- if ( object . hasOwnProperty ( prop ) ) {
1368- var value = Vision . likelihood [ object [ prop ] ] ;
1369- convertedObject [ prop ] = value >= baseLikelihood ;
1370- }
1371- }
1372-
1373- return convertedObject ;
1374- } ;
1375-
13761346/**
13771347 * Determine the type of image the user is asking to be annotated. If a
13781348 * {module:storage/file}, convert to its "gs://{bucket}/{file}" URL. If a remote
@@ -1586,15 +1556,16 @@ Vision.formatFaceAnnotation_ = function(faceAnnotation) {
15861556 confidence : faceAnnotation . detectionConfidence * 100
15871557 } ;
15881558
1589- extend ( formattedFaceAnnotation , Vision . convertToBoolean_ ( LIKELY , {
1590- blurry : faceAnnotation . blurredLikelihood ,
1591- dark : faceAnnotation . underExposedLikelihood ,
1592- happy : faceAnnotation . joyLikelihood ,
1593- hat : faceAnnotation . headwearLikelihood ,
1594- mad : faceAnnotation . angerLikelihood ,
1595- sad : faceAnnotation . sorrowLikelihood ,
1596- surprised : faceAnnotation . surpriseLikelihood
1597- } ) ) ;
1559+ // Remove the `Likelihood` part from a property name.
1560+ // input: "joyLikelihood", output: "joy"
1561+ for ( var prop in faceAnnotation ) {
1562+ if ( prop . indexOf ( 'Likelihood' ) > - 1 ) {
1563+ var shortenedProp = prop . replace ( 'Likelihood' , '' ) ;
1564+
1565+ formattedFaceAnnotation [ shortenedProp ] =
1566+ Vision . gteLikelihood_ ( LIKELY , faceAnnotation [ prop ] ) ;
1567+ }
1568+ }
15981569
15991570 return formattedFaceAnnotation ;
16001571} ;
@@ -1644,12 +1615,33 @@ Vision.formatImagePropertiesAnnotation_ = function(imageAnnotation, options) {
16441615 */
16451616Vision . formatSafeSearchAnnotation_ = function ( ssAnnotation , options ) {
16461617 if ( ! options . verbose ) {
1647- return Vision . convertToBoolean_ ( LIKELY , ssAnnotation ) ;
1618+ for ( var prop in ssAnnotation ) {
1619+ var value = ssAnnotation [ prop ] ;
1620+ ssAnnotation [ prop ] = Vision . gteLikelihood_ ( LIKELY , value ) ;
1621+ }
1622+ return ssAnnotation ;
16481623 }
16491624
16501625 return ssAnnotation ;
16511626} ;
16521627
1628+ /**
1629+ * Convert a "likelihood" value to a boolean representation, based on the lowest
1630+ * likelihood provided.
1631+ *
1632+ * @private
1633+ *
1634+ * @example
1635+ * Vision.gteLikelihood_(Vision.likelihood.VERY_LIKELY, 'POSSIBLE');
1636+ * // false
1637+ *
1638+ * Vision.gteLikelihood_(Vision.likelihood.UNLIKELY, 'POSSIBLE');
1639+ * // true
1640+ */
1641+ Vision . gteLikelihood_ = function ( baseLikelihood , likelihood ) {
1642+ return Vision . likelihood [ likelihood ] >= baseLikelihood ;
1643+ } ;
1644+
16531645/*! Developer Documentation
16541646 *
16551647 * All async methods (except for streams) will return a Promise in the event
0 commit comments