Skip to content

Commit

Permalink
Merge pull request #59 from chughts/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
chughts committed May 13, 2016
2 parents 4610616 + f32fefd commit 1e02d1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion services/alchemy_language/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
<p>For full details on the feature details, please see the <a href="http://www.alchemyapi.com/api">Alchemy API documentation</a></p>
<p>The content to be analysed should be passed in on <code>msg.payload</code>.</p>
<p>Valid <code>msg.payload</code> types: URL, HTML or Text Content.</p>
<p>If you need to send custom parameters along with each feature, set those parameters as children of the <code>msg.alchemy_options</code> object.</p>
<p>If you need to send custom parameters along with each feature, set those parameters as children of the <code>msg.alchemy_options</code> object. eg. to limit the output to 3 values per feature set
<code>msg.alchemy_options = {maxRetrieve: 3};</code>
</p>
<br>
<p>Results from the Alchemy API service will made available at <code>msg.features</code>. Each feature result will be a separate child property.</p>
</script>
Expand Down
30 changes: 18 additions & 12 deletions services/alchemy_language/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand All @@ -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);
}
});

Expand Down

0 comments on commit 1e02d1b

Please sign in to comment.