From f32fefde4770a0af2c638c5f2a6737209c937e3e Mon Sep 17 00:00:00 2001 From: chughts Date: Fri, 13 May 2016 10:03:20 +0100 Subject: [PATCH] Re-enabled processing of msg.alchemy_options --- services/alchemy_language/v1.html | 4 +++- services/alchemy_language/v1.js | 30 ++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/services/alchemy_language/v1.html b/services/alchemy_language/v1.html index c431c851..6430035f 100644 --- a/services/alchemy_language/v1.html +++ b/services/alchemy_language/v1.html @@ -99,7 +99,9 @@

For full details on the feature details, please see the Alchemy API documentation

The content to be analysed should be passed in on msg.payload.

Valid msg.payload types: URL, HTML or Text Content.

-

If you need to send custom parameters along with each feature, set those parameters as children of the msg.alchemy_options object.

+

If you need to send custom parameters along with each feature, set those parameters as children of the msg.alchemy_options object. eg. to limit the output to 3 values per feature set + msg.alchemy_options = {maxRetrieve: 3}; +


Results from the Alchemy API service will made available at msg.features. Each feature result will be a separate child property.

diff --git a/services/alchemy_language/v1.js b/services/alchemy_language/v1.js index 11787493..81792aa3 100644 --- a/services/alchemy_language/v1.js +++ b/services/alchemy_language/v1.js @@ -46,7 +46,8 @@ module.exports = function (RED) { // user who, when he errenously enters bad credentials, can't figure out why // the edited ones are not being taken. - var services = cfenv.getAppEnv().services; + // Taking this line out as codacy was complaining about it. + // var services = cfenv.getAppEnv().services; var service; var apikey, s_apikey; @@ -103,13 +104,18 @@ module.exports = function (RED) { return; } - // The watson node-SDK expects the features as a single string. - var extract = "" ; //doc-sentiment"; - enabled_features.forEach(function(entry){extract += (',' + entry)}) + // The watson node-SDK expects the features as a single string. + var extract = "" ; + extract = enabled_features.join(","); //console.log("Will be looking for ", extract) - var params = { text: msg.payload, extract: extract }; + var params = { text: msg.payload, extract: extract }; + + // Splice in the additional options from msg.alchemy_options + // eg. The user may have entered msg.alchemy_options = {maxRetrieve: 2}; + + for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; } alchemy_language.combined(params, function (err, response) { if (err || response.status === 'ERROR') { @@ -118,16 +124,16 @@ module.exports = function (RED) { node.error(err, msg); } else { - msg.features = {}; - //msg.features['all'] = response; + msg.features = {}; + //msg.features['all'] = response; - Object.keys(FEATURES).forEach(function (feature) { - var answer_feature = FEATURES[feature]; + Object.keys(FEATURES).forEach(function (feature) { + var answer_feature = FEATURES[feature]; - msg.features[feature] = response[answer_feature] || {}; - }); + msg.features[feature] = response[answer_feature] || {}; + }); - node.send(msg); + node.send(msg); } });