Skip to content

Commit ef90207

Browse files
committed
implment update visual recognition classifier
1 parent bd40899 commit ef90207

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Node-RED Watson Nodes for IBM Cloud
1111
- Fix to defaulting name for NLU Node.
1212
- Allow pre-check of audio format to be disabled in Speech to Text node.
1313
- Migrate from deprecated getModels and getCustomizations methods in Speech to Text nodes.
14+
- Implement update classifier in Visual Recognition Util node.
15+
- In Visual Recognition Util node append 'positive_' to zip name if neither 'positive' not 'negative' not already there.
1416

1517
### New in version 0.6.10
1618
- Needed to stringify json before addDocument in Discovery node.

services/visual_recognition/v3.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<option value="createClassifier">Create a classifier</option>
6868
<option value="retrieveClassifiersList">Retrieve a list of classifiers</option>
6969
<option value="retrieveClassifierDetails">Retrieve Classifier Details</option>
70+
<option value="updateClassifier">Update a classifier</option>
7071
<option value="deleteClassifier">Delete a classifier</option>
7172
<option value="deleteAllClassifiers">Delete all classifiers</option>
7273
</select>
@@ -94,7 +95,7 @@
9495
<p>This feature should be provided in input : </p>
9596
<ul>
9697
<li><code>msg.payload</code> : the URL or the Node.js Buffer of an image. Redirects are followed, so you can use shortened URLs. (Required)</li>
97-
<li><code>msg.params["detect_mode"]</code> : A setting of "classify", "faces" or "text" indicating the visual recognition feature required. "Default" is "classify" (string) (Optional)</li>
98+
<li><code>msg.params["detect_mode"]</code> : A setting of "classify" or "faces" indicating the visual recognition feature required. "Default" is "classify" (string) (Optional)</li>
9899
<li><code>msg.params["classifier_ids"]</code> : A comma-separated list of the classifier IDs used to classify the images. "Default" is the classifier_id of the built-in classifier. (string) (Optional)</li>
99100
<li><code>msg.params["owners"]</code> : A comma-separated list with the value(s) "IBM" and/or "me" to specify which classifiers to run. (string) (Optional)</li>
100101
<li><code>msg.params["threshold"]</code> : A floating value (in string format) that specifies the minimum score a class must have to be displayed in the response (Optional)</li>

services/visual_recognition/v3.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ module.exports = function(RED) {
273273
// msg.params["negative_examples"] : a Node.js binary Buffer of the ZIP
274274
// that contains a minimum of 10 images.(Optional)
275275

276-
function prepareParamsCreateClassifier(params, node, msg) {
276+
function prepareParamsClassifierFiles(params, node, msg) {
277277
var p = new Promise(function resolver(resolve, reject) {
278278
var listParams = {},
279279
asyncTasks = [],
@@ -396,6 +396,21 @@ module.exports = function(RED) {
396396
return p;
397397
}
398398

399+
function invokeUpdateClassifier(node, params, msg) {
400+
var p = new Promise(function resolver(resolve, reject) {
401+
params['classifier_id'] = msg.params['classifier_id'];
402+
node.service.updateClassifier(params, function(err, body) {
403+
if (err) {
404+
reject(err);
405+
} else {
406+
resolve(body);
407+
}
408+
});
409+
410+
});
411+
return p;
412+
}
413+
399414
function invokeListClassifiers(node, params) {
400415
var p = new Promise(function resolver(resolve, reject) {
401416
node.service.listClassifiers(params, function(err, body) {
@@ -437,16 +452,26 @@ module.exports = function(RED) {
437452
return p;
438453
}
439454

440-
441455
function executeCreateClassifier(params, node, msg) {
442-
var p = prepareParamsCreateClassifier(params, node, msg)
456+
var p = prepareParamsClassifierFiles(params, node, msg)
443457
.then(function() {
444458
return invokeCreateClassifier(node, params);
445459
});
446460

447461
return p;
448462
}
449463

464+
function executeUpdateClassifier(params, node, msg) {
465+
// This is not an error, the params for create & update
466+
// are essentially the same.
467+
var p = prepareParamsClassifierFiles(params, node, msg)
468+
.then(function() {
469+
return invokeUpdateClassifier(node, params, msg);
470+
});
471+
472+
return p;
473+
}
474+
450475
function executeUtilService(feature, params, node, msg) {
451476
var p = null;
452477
switch (feature) {
@@ -457,6 +482,13 @@ module.exports = function(RED) {
457482
});
458483
break;
459484

485+
case 'updateClassifier':
486+
p = executeUpdateClassifier(params, node, msg)
487+
.then(function(body) {
488+
return processTheResponse(body, feature, node, msg);
489+
});
490+
break;
491+
460492
case 'retrieveClassifiersList':
461493
p = invokeListClassifiers(node, params)
462494
.then(function(body) {

0 commit comments

Comments
 (0)