Skip to content

Commit f7b0220

Browse files
committed
updated my fork from original
2 parents 3b5ef3b + 8cab262 commit f7b0220

14 files changed

Lines changed: 925 additions & 202 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ Node-RED Watson Nodes for IBM Bluemix
33

44
[![Codacy Badge](https://api.codacy.com/project/badge/grade/e157cf8407f2442396789dc78075340a)](https://www.codacy.com/app/rezgui-y/node-red-node-watson)
55

6-
### New in next version
6+
### New in version 0.4.3
7+
- New Visual Recognition V3 node to support the V3 GA API. This incorporates the features that were previously
8+
available as part of AlchemyAPI Vision.
9+
10+
### New in version 0.4.2
711
- The transcription returned for the Speech to Text node now returns full (untruncated) transcription. The
812
alternatives are returned in msg.fullresult. The dialog now loads available models dynamically. This will
913
allow new speech models to be identified without requiring a further code change.
14+
- The Retrieve and Rank node nows stores credentials in a configuration node, allowing the credentials to be
15+
shared acrosss a flow with multiple Retrieve and Rank nodes.
16+
- New Tone Analyzer V3 node to support the V3 GA API.
1017

1118
### New in version 0.4.1
1219
- AlchemyAPI Image Analysis and Language nodes migrated from old Alchemy SDK to current

codacy/codacy-conf.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",
@@ -11,7 +11,7 @@
1111
"temp": "^0.8.3",
1212
"qs": "6.x",
1313
"image-type": "^2.0.2",
14-
"watson-developer-cloud": "^1.2.4"
14+
"watson-developer-cloud": "^1.9.2"
1515
},
1616
"repository": {
1717
"type": "git",
@@ -42,7 +42,8 @@
4242
"watson-tradeoff-analytics-v1": "services/tradeoff_analytics/v1.js",
4343
"watson-tone-analyzer-v3-beta": "services/tone_analyzer/v3-beta.js",
4444
"watson-tone-analyzer-v3": "services/tone_analyzer/v3.js",
45-
"watson-visual-recognition-v1": "services/visual_recognition/v1.js"
45+
"watson-visual-recognition-v1": "services/visual_recognition/v1.js",
46+
"watson-visual-recognition-v3": "services/visual_recognition/v3.js"
4647
}
4748
}
48-
}
49+
}

services/retrieve_and_rank/v1.html

Lines changed: 96 additions & 97 deletions
Large diffs are not rendered by default.

services/retrieve_and_rank/v1.js

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function (RED) {
4141
this.username = config.username;
4242
this.password = config.password;
4343
}
44-
44+
4545
function createRankerNode(config) {
4646
RED.nodes.createNode(this, config);
4747
var node = this;
@@ -56,20 +56,20 @@ module.exports = function (RED) {
5656
var params = {
5757
training_data: msg.payload
5858
};
59-
59+
6060
if (config.rankername) {
61-
params.training_metadata = "{\"name\": \""+config.rankername+"\"}";
61+
params.training_metadata = '{\"name\": \"'+config.rankername+'\"}';
6262
}
63-
node.status({fill:"blue",shape:"ring",text:"Uploading training data"});
63+
node.status({fill:'blue',shape:'ring',text:'Uploading training data'});
6464
retrieve_and_rank.createRanker(params, function(err, res) {
6565
handleWatsonCallback(null,node,msg,err,res,function() {
66-
node.status({fill:"blue",shape:"ring",text:"Training data uploaded. Ranker is training"});
66+
node.status({fill:'blue',shape:'ring',text:'Training data uploaded. Ranker is training'});
6767
//Now check the status of the ranker
6868
var ranker_id = res.ranker_id;
6969
checkRankerStatus(retrieve_and_rank,msg,node,ranker_id);
7070
});;
7171
});
72-
});
72+
});
7373
});
7474
}
7575

@@ -97,7 +97,7 @@ module.exports = function (RED) {
9797
var message = 'No ranker id specified';
9898
node.error(message, msg)
9999
return;
100-
}
100+
}
101101
break;
102102
case 'delete':
103103
if (params.ranker_id) {
@@ -111,7 +111,7 @@ module.exports = function (RED) {
111111
}
112112
break;
113113
}
114-
});
114+
});
115115
});
116116
}
117117

@@ -121,7 +121,7 @@ module.exports = function (RED) {
121121

122122
this.on('input', function(msg) {
123123
setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) {
124-
124+
125125
var params = {
126126
cluster_id: config.clusterid,
127127
collection_name: config.collectionname
@@ -144,7 +144,7 @@ module.exports = function (RED) {
144144
handleWatsonCallback(null,node,msg,err,searchResponse);
145145
});
146146

147-
});
147+
});
148148
});
149149
}
150150

@@ -155,8 +155,12 @@ module.exports = function (RED) {
155155
this.on('input', function(msg) {
156156
setupRankRetrieveNode(msg, config, this, function (retrieve_and_rank) {
157157

158+
//Cluster name can be passed into msg.payload, but the cluster name
159+
//specified in the config takes priority
160+
var clustername;
161+
(config.clustername !== '') ? clustername = config.clustername : clustername = msg.payload;
158162
var params = {
159-
cluster_name: config.clustername,
163+
cluster_name: clustername,
160164
cluster_size: config.clustersize !== 'free' ? config.clustersize : null,
161165
}
162166

@@ -166,7 +170,7 @@ module.exports = function (RED) {
166170

167171
if (err) {
168172
node.status({});
169-
var message = "";
173+
var message = '';
170174
(err.error) ? message = err.error : message = err.message;
171175
return node.error(message, msg);
172176
}
@@ -208,7 +212,7 @@ module.exports = function (RED) {
208212
var message = 'No cluster id specified';
209213
node.error(message, msg)
210214
return;
211-
}
215+
}
212216
break;
213217
case 'delete':
214218
if (params.cluster_id) {
@@ -222,7 +226,7 @@ module.exports = function (RED) {
222226
}
223227
break;
224228
}
225-
});
229+
});
226230
});
227231
}
228232

@@ -269,7 +273,7 @@ module.exports = function (RED) {
269273
uploadConfig(file, temp.cleanup);
270274
});
271275
});
272-
});
276+
});
273277
});
274278
}
275279

@@ -297,7 +301,7 @@ module.exports = function (RED) {
297301
//Note. temporary workaround until bug is fixed in Node SDK
298302
//Stream zip file from watson api to temp directory,
299303
//read from temp directory and pass on in msg.payload as buffer
300-
var url = "https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/"+params.cluster_id+"/config/"+params.config_name;
304+
var url = 'https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/'+params.cluster_id+'/config/'+params.config_name;
301305
var sendToPayload = function(zipFile, cb) {
302306
msg.payload = zipFile;
303307
node.send(msg);
@@ -321,12 +325,12 @@ module.exports = function (RED) {
321325
stream_url(info.path, url, function (content) {
322326
sendToPayload(content, temp.cleanup);
323327
});
324-
});
328+
});
325329
} else {
326330
var message = 'Missing cluster id or config name';
327331
node.error(message, msg)
328332
return;
329-
}
333+
}
330334
break;
331335
case 'delete':
332336
if (params.cluster_id && params.config_name) {
@@ -340,7 +344,7 @@ module.exports = function (RED) {
340344
}
341345
break;
342346
}
343-
});
347+
});
344348
});
345349
}
346350

@@ -420,56 +424,56 @@ module.exports = function (RED) {
420424
}
421425
break;
422426
}
423-
});
427+
});
424428
});
425429
}
426430

427-
RED.nodes.registerType("watson-retrieve-rank-credentials", serviceCredentialsConfigurationNode);
431+
RED.nodes.registerType('watson-retrieve-rank-credentials', serviceCredentialsConfigurationNode);
428432
RED.nodes.registerType('watson-retrieve-rank-create-cluster', createClusterNode);
429433

430434
RED.nodes.registerType('watson-retrieve-rank-cluster-settings', clusterSettingsNode, {
431435
credentials: {
432-
username: {type:"text"},
433-
password: {type:"password"}
436+
username: {type:'text'},
437+
password: {type:'password'}
434438
}
435439
});
436440
RED.nodes.registerType('watson-retrieve-rank-upload-solr-configuration', uploadSolrConfigurationNode, {
437441
credentials: {
438-
username: {type:"text"},
439-
password: {type:"password"}
442+
username: {type:'text'},
443+
password: {type:'password'}
440444
}
441445
});
442446
RED.nodes.registerType('watson-retrieve-rank-solr-configuration-settings', solrConfigurationSettingsNode, {
443447
credentials: {
444-
username: {type:"text"},
445-
password: {type:"password"}
448+
username: {type:'text'},
449+
password: {type:'password'}
446450
}
447451
});
448452
RED.nodes.registerType('watson-retrieve-rank-solr-collection', solrCollectionNode, {
449453
credentials: {
450-
username: {type:"text"},
451-
password: {type:"password"}
454+
username: {type:'text'},
455+
password: {type:'password'}
452456
}
453457
});
454458
RED.nodes.registerType('watson-retrieve-rank-create-ranker', createRankerNode, {
455459
credentials: {
456-
username: {type:"text"},
457-
password: {type:"password"}
460+
username: {type:'text'},
461+
password: {type:'password'}
458462
}
459463
});
460464
RED.nodes.registerType('watson-retrieve-rank-ranker-settings', rankerSettingsNode, {
461465
credentials: {
462-
username: {type:"text"},
463-
password: {type:"password"}
466+
username: {type:'text'},
467+
password: {type:'password'}
464468
}
465469
});
466470
RED.nodes.registerType('watson-retrieve-rank-search-and-rank', searchAndRankNode, {
467471
credentials: {
468-
username: {type:"text"},
469-
password: {type:"password"}
472+
username: {type:'text'},
473+
password: {type:'password'}
470474
}
471475
});
472-
476+
473477
function setupRankRetrieveNode(msg,config,node,callback) {
474478
//Check for payload
475479
if (!msg.payload) {
@@ -480,7 +484,6 @@ module.exports = function (RED) {
480484

481485
//Check credentials
482486
this.credentials = RED.nodes.getNode(config.servicecreds);
483-
console.log(config);
484487
username = username || this.credentials.username;
485488
password = password || this.credentials.password;
486489

@@ -501,7 +504,7 @@ module.exports = function (RED) {
501504

502505
function handleWatsonCallback(mode,node,msg,err,res,cb) {
503506
if (err) {
504-
var message = "";
507+
var message = '';
505508
if (err.description) {
506509
message = err.description;
507510
} else if (err.message) {
@@ -512,7 +515,7 @@ module.exports = function (RED) {
512515
node.status({});
513516
return node.error(message, msg);
514517
} else {
515-
(mode == 'delete' && Object.keys(res).length == 0) ? msg.payload = "Ranker deleted" : msg.payload = res;
518+
(mode == 'delete' && Object.keys(res).length == 0) ? msg.payload = 'Ranker deleted' : msg.payload = res;
516519
if (mode != 'index') {
517520
node.send(msg);
518521
}
@@ -522,7 +525,7 @@ module.exports = function (RED) {
522525

523526
function checkRankerStatus(retrieve_and_rank,msg,node,ranker_id) {
524527
var interval = 10000;
525-
//Loop and check the status of the ranker
528+
//Loop and check the status of the ranker
526529
var statusInterval = setInterval(function(){
527530
var params = {
528531
ranker_id: ranker_id
@@ -531,13 +534,13 @@ module.exports = function (RED) {
531534
if (err) {
532535
node.status({});
533536
console.log(err);
534-
var message = "Ranker training state error: "+err.error;
537+
var message = 'Ranker training state error: '+err.error;
535538
clearInterval(statusInterval);
536539
return node.error(message, msg);
537540
} else {
538541
switch (res.status) {
539542
case 'Available':
540-
node.status({fill:"green",shape:"ring",text:"Ranker available"});
543+
node.status({fill:'green',shape:'ring',text:'Ranker available'});
541544
return clearInterval(statusInterval);
542545
break;
543546

@@ -546,7 +549,7 @@ module.exports = function (RED) {
546549

547550
default:
548551
node.status({});
549-
var message = "Ranker training status: "+res.status+", description: "+res.status_description;
552+
var message = 'Ranker training status: '+res.status+', description: '+res.status_description;
550553
clearInterval(statusInterval);
551554
return node.error(message, msg);
552555
}
@@ -566,14 +569,14 @@ module.exports = function (RED) {
566569
retrieve_and_rank.pollCluster(params, function(err, res) {
567570
if (err) {
568571
node.status({});
569-
var message = "Cluster creation state error: "+err.error;
572+
var message = 'Cluster creation state error: '+err.error;
570573
clearInterval(statusInterval);
571574
return node.error(message, msg);
572575
} else {
573576

574577
switch (res.solr_cluster_status) {
575578
case 'READY':
576-
node.status({fill:"green",shape:"ring",text:"Cluster available"});
579+
node.status({fill:'green',shape:'ring',text:'Cluster available'});
577580
return clearInterval(statusInterval);
578581
break;
579582

@@ -582,7 +585,7 @@ module.exports = function (RED) {
582585

583586
default:
584587
node.status({});
585-
var message = "Cluster status: "+res.status+", description: "+res.status_description;
588+
var message = 'Cluster status: '+res.status+', description: '+res.status_description;
586589
clearInterval(statusInterval);
587590
return node.error(message, msg);
588591
}

services/tone_analyzer/v3-beta.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
</script>
5353

5454
<script type="text/x-red" data-help-name="watson-tone-analyzer">
55+
<p><b>NB:</b> This node uses the old beta API and it is only being retained for backward compatibility for anyone that has old credentials. It will no longer work with new credentials.</p>
56+
<br/>
5557
<p>The Tone Analyzer service uses linguistic analysis to detect emotional tones, social propensities, and writing styles in written communication.</p>
5658
<p>The text to analyze should be passed in on <b>msg.payload</b>.</p>
5759
<p>The service response will be returned on <b>msg.response</b>.</p>

services/tone_analyzer/v3.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@
5959
</script>
6060

6161
<script type="text/x-red" data-help-name="watson-tone-analyzer-v3">
62-
<p>The Tone Analyzer service uses linguistic analysis to detect emotional tones, social propensities, and writing styles in written communication.</p>
62+
<p>The Tone Analyzer service uses linguistic analysis to detect emotional tones, social propensities,
63+
and writing styles in written communication.</p>
6364
<p>The text to analyze should be passed in on <b>msg.payload</b>.</p>
6465
<p>The service response will be returned on <b>msg.response</b>.</p>
65-
<p>Usng the node editor dialog users can filter the results by tone (emotion, writing or social) and whether to include sentence-level analysis.</p>
66+
<p>The tone and sentances can be programmaticaly set in <code>msg.tones</code>
67+
and <code>msg.sentences</code></p>
68+
<p>Usng the node editor dialog users can filter the results by tone (emotion, language or social) and
69+
whether to include sentence-level analysis.</p>
6670
<p>For more information about the Tone Analyzer service, read the <a href="https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/tone-analyzer.html">documentation</a>.</p>
6771
</script>
6872

0 commit comments

Comments
 (0)