Skip to content

Commit

Permalink
Merge pull request #171 from ylecleach/master
Browse files Browse the repository at this point in the history
Visual Recognition V3 : added support of Accept-Language for Classify…
  • Loading branch information
chughts authored Aug 4, 2016
2 parents a81761c + 7ca5339 commit eaa4a5e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ Node-RED Watson Nodes for IBM Bluemix

<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>


### New in version 0.4.9
- Added in German and Japanese support to Natural Language Classifier node
- Visual Recognition V3 : added support of Accept-Language for Classify feature, new icon with pink background, icon label renamed (removing v3 from node name)

### New in version 0.4.8
- Fixed document conversion node when filetype is not recognized
Expand Down
Binary file removed services/visual_recognition/icons/VR-v3-full.png
Binary file not shown.
Binary file added services/visual_recognition/icons/VR-v3-pink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 50 additions & 14 deletions services/visual_recognition/v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row" id="lang-group">
<label for="node-input-lang-label"><i class="fa fa-language"></i> Language</label>
<select type="text" id="node-input-lang" style="display: inline-block; width: 70%;" >
<option value="en">English</option>
<option value="es">Spanish</option>
<option value="ar">Arabic</option>
<option value="ja">Japanese</option>
</select>
</div>
</script>

<script type="text/x-red" data-template-name="visual-recognition-util-v3">
Expand Down Expand Up @@ -84,6 +93,7 @@
<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>
<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>
<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>
<li><code>msg.params["accept_language"]</code> : Specifies the language of the output class names. Can be 'en' (English as default), 'es' (Spanish), 'ar' (Arabic) or 'ja' (Japanese). Classes for which no translation is available are omitted. If specified, it overrides the language specified in the node configuration (Optional)</li>
</ul>
<p>More information on this <a href="http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/visual-recognition/api/v3/?curl#classify_an_image">API documentation</a>.</p>

Expand Down Expand Up @@ -163,29 +173,46 @@


<script type="text/javascript">

// Need to simulate a namespace, as some of the variables had started to leak across nodes
function VISUALRECOGNITIONV3 () {
var language_selected = '';
}

// This is the namespace for visualrecognitionv3. Currently only contains models, but more vars and functions may need to be
// moved in if there is a clash with other nodes.
var visualrecognitionv3 = new VISUALRECOGNITIONV3();

// Save the values in the dynamic lists to the hidden fields.
function oneditsave(){
visualrecognitionv3.language_selected = $('#node-input-lang').val();
}

(function() {
RED.nodes.registerType('visual-recognition-v3', {
category: 'IBM Watson',
defaults: {
name: {value: ""},
apikey: {value: ""},
"image-feature": {value: ""}
"image-feature": {value: ""},
"lang": {value: ""},
},
credentials: {
apikey: {type:"password"}
},
color: 'rgb(72, 232, 211)',
color: 'rgb(228, 189, 255)',
inputs: 1,
outputs: 1,
icon: "VR-v3-25x25.png",
paletteLabel: "visual recognition v3",
icon: "VR-v3-pink.png",
paletteLabel: "visual recognition",
label: function() {
return this.name || "visual recognition v3";
return this.name || "visual recognition";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
var node = this;
$.getJSON('watson-visual-recognition/vcap/')
.done(function (service) {
$('.credentials').toggle(!service);
Expand All @@ -195,10 +222,21 @@
})
.always(function () {
$('#credentials-check').hide();
})
}
});
});

// update list of ruleset for the selected service when the service changes
$('#node-input-image-feature').change(function() {
var selectedFeature = $('#node-input-image-feature');
if (selectedFeature.val() == 'classifyImage') {
$('#lang-group').show();
}
else {
$('#lang-group').hide();
}
});
},
oneditsave: oneditsave
});


RED.nodes.registerType('visual-recognition-util-v3', {
Expand All @@ -211,13 +249,13 @@
credentials: {
apikey: {type:"password"}
},
color: 'rgb(72, 232, 211)',
color: 'rgb(228, 189, 255)',
inputs: 1,
outputs: 1,
icon: "VR-v3-25x25.png",
paletteLabel: "visual recognition util v3",
icon: "VR-v3-pink.png",
paletteLabel: "visual recognition util",
label: function() {
return this.name || "visual recognition util v3";
return this.name || "visual recognition util";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
Expand All @@ -235,7 +273,5 @@
})
}
});


})();
</script>
17 changes: 14 additions & 3 deletions services/visual_recognition/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ module.exports = function (RED) {
node.apikey = sAPIKey || node.credentials.apikey;
if (!node.apikey) {
node.status({fill:'red', shape:'ring', text:'missing credentials'});
var message ='Missing Watson Visual Recognition API service credentials';

node.error(message, msg);
node.error('Missing Watson Visual Recognition API service credentials', msg);
return false;
}
node.service = watson.visual_recognition({
Expand Down Expand Up @@ -154,6 +152,12 @@ module.exports = function (RED) {
if (msg.params != null && msg.params.threshold != null) {
params['threshold'] = msg.params['threshold'];
}
if (node.config != null && node.config.lang != null) {
params['Accept-Language'] = node.config.lang;
}
if (msg.params != null && msg.params.accept_language != null) {
params['Accept-Language'] = msg.params['accept_language'];
}
cb();
});
});
Expand All @@ -168,6 +172,12 @@ module.exports = function (RED) {
if (msg.params != null && msg.params.threshold != null) {
params['threshold'] = msg.params['threshold'];
}
if (node.config != null && node.config.lang != null) {
params['Accept-Language'] = node.config.lang;
}
if (msg.params != null && msg.params.accept_language != null) {
params['Accept-Language'] = msg.params['accept_language'];
}
return cb();
} else {
node.status({fill:'red', shape:'ring', text:'payload is invalid'});
Expand Down Expand Up @@ -331,6 +341,7 @@ module.exports = function (RED) {
function WatsonVisualRecognitionV3Node (config) {
var node = this, b = false, feature = config['image-feature'];
RED.nodes.createNode(this, config);
node.config = config;

node.on('input', function (msg) {
var params = {};
Expand Down

0 comments on commit eaa4a5e

Please sign in to comment.