Skip to content

Commit

Permalink
Add support for NLP Query in Discovery Node
Browse files Browse the repository at this point in the history
  • Loading branch information
chughts committed Jun 20, 2017
1 parent 2350729 commit a00bceb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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.5.11
- Add support for NLP Query in Discovery and Discovery Query Builder Nodes.

### New in version 0.5.10
- Allowed detect_mode for Visual Recognition node to be set in msg.params

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-watson",
"version": "0.5.10",
"version": "0.5.11",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"alchemy-api": "^1.3.0",
Expand Down
1 change: 0 additions & 1 deletion services/conversation/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
</ul>
</script>


<script type="text/javascript">
var oneditprepare = function() {
$('input#node-input-context').change(function () {
Expand Down
28 changes: 23 additions & 5 deletions services/discovery/discovery-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ DiscoveryUtils.prototype = {
var sourceField = 'query',
targetField = 'query';

if (config.nlp_query) {
if (config.nlp_query || msg.discoveryparams.nlp_query) {
targetField = 'natural_language_query';
}
if (msg.discoveryparams && msg.discoveryparams[sourceField]) {
Expand Down Expand Up @@ -109,6 +109,27 @@ DiscoveryUtils.prototype = {
if (config.collection) {
params.collection_id = config.collection;
}

if (config.passages) {
params.passages = config.passages;
}

params = this.buildMsgQueryOverrides(msg, config, params);

return params;
},

buildMsgQueryOverrides: function(msg, config, params) {
if (config.nlp_query) {
params.query = config.querynlp;
params.nlp_query = config.nlp_query;
} else {
params = buildStructuredQuery(msg, config, params);
}
return params;
},

buildStructuredQuery: function(msg, config, params) {
if (config.query1 && config.queryvalue1) {
params.query = config.query1 + ':"' + config.queryvalue1 + '"';
}
Expand All @@ -124,13 +145,10 @@ DiscoveryUtils.prototype = {
}
params.query += config.query3 + ':"' + config.queryvalue3 + '"';
}
if (config.passages) {
params.passages = config.passages;
}

return params;
},


paramEnvCheck: function(params) {
var response = '';
if (!params.environment_id) {
Expand Down
92 changes: 74 additions & 18 deletions services/discovery/v1-query-builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@
<input type="hidden" id="node-input-collectionhidden"/>
</div>

<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-passages" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-passages" style="width: 70%;"> Passages</label>
</div>
<div>
<input type="hidden" id="node-input-passageshidden"/>
</div>

<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-nlp_query" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-nlp_query" style="width: 70%;"> Query in Plain Language</label>
</div>
<div>
<input type="hidden" id="node-input-nlp_queryhidden"/>
</div>

<div class="form-row">
<label for="node-input-querynlp"><i class="fa fa-book"></i> NLP Query </label>
<input type="text" id="node-input-querynlp" placeholder="">
</div>
<div>
<input type="hidden" id="node-input-querynlphidden"/>
</div>

<div class="form-row">
<label for="node-input-query1"><i class="fa fa-book"></i> Query Key 1</label>
<select type="text" id="node-input-query1" style="display: inline-block; vertical-align:middle; width: 70%;">
Expand Down Expand Up @@ -100,15 +126,6 @@
<input type="hidden" id="node-input-queryvalue3hidden"/>
</div>

<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-passages" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-passages" style="width: 70%;"> Passages</label>
</div>
<div>
<input type="hidden" id="node-input-passageshidden"/>
</div>

</script>

<script type="text/x-red" data-help-name="watson-discovery-v1-query-builder">
Expand Down Expand Up @@ -150,14 +167,17 @@
disQB.query2_selected = $('#node-input-query2hidden').val();
disQB.query3_selected = $('#node-input-query3hidden').val();
disQB.passages_selected = $('#node-input-passageshidden').val();
disQB.nlp_query_selected = $('#node-input-nlp_queryhidden').val();

// Nothing is to be shown unless the values to show in the listCollections
// can be obtained from the service.
disQB.hideAll = function() {
$('#credentials-not-found').show();
cv1wm.hideSelectedFields(fields);
$('#something-went-wrong').hide();
$('#node-input-environment').parent().hide();
$('#node-input-collection').parent().hide();
$('#node-input-querynlp').parent().hide();
$('#node-input-query1').parent().hide();
$('#node-input-query2').parent().hide();
$('#node-input-query3').parent().hide();
Expand All @@ -169,6 +189,12 @@
}
}

disQB.hideSelectedFields = function(fields) {
for (i = 0; i < fields.length; i++) {
$(fields[i]).parent().hide();
}
}

// Set up listeners for the select lists to determine if the subsequent
// list boxes need refreshing. ie. A change in selected Envionment, needs
// the collection list to be revised. A change in selected collection, needs
Expand Down Expand Up @@ -216,6 +242,21 @@
disQB.query3_selected = $('#node-input-query3').val();
});

$('input#node-input-nlp_query').change(function () {
var checked = $('input#node-input-nlp_query').prop('checked')
if (checked) {
$('#node-input-querynlp').parent().show();
$('#node-input-query1').parent().hide();
$('#node-input-query2').parent().hide();
$('#node-input-query3').parent().hide();
} else {
$('#node-input-querynlp').parent().hide();
$('#node-input-query1').parent().show();
$('#node-input-query2').parent().show();
$('#node-input-query3').parent().show();
}
});

}

// The dialog is about to be shown.
Expand Down Expand Up @@ -497,32 +538,37 @@
// they can be restored.
disQB.restoreHidden = function () {
disQB.environment_selected = $('#node-input-environmenthidden').val();
$('select#node-input-environment').val(disQB.environment_selected);
$('#node-input-environment').val(disQB.environment_selected);

disQB.collection_selected = $('#node-input-collectionhidden').val();
$('select#node-input-collection').val(disQB.collection_selected);
$('#node-input-collection').val(disQB.collection_selected);

disQB.querynlp_selected = $('#node-input-querynlphidden').val();
$('#node-input-querynlp').val(disQB.querynlp_selected);

disQB.query1_selected = $('#node-input-query1hidden').val();
$('select#node-input-query1').val(disQB.query1_selected);
$('#node-input-query1').val(disQB.query1_selected);

disQB.queryvalue1_selected = $('#node-input-queryvalue1hidden').val();
$('select#node-input-queryvalue1').val(disQB.queryvalue1_selected);
$('#node-input-queryvalue1').val(disQB.queryvalue1_selected);

disQB.query2_selected = $('#node-input-query2hidden').val();
$('select#node-input-query2').val(disQB.query2_selected);
$('#node-input-query2').val(disQB.query2_selected);

disQB.queryvalue2_selected = $('#node-input-queryvalue2hidden').val();
$('select#node-input-queryvalue2').val(disQB.queryvalue2_selected);
$('#node-input-queryvalue2').val(disQB.queryvalue2_selected);

disQB.query3_selected = $('#node-input-query3hidden').val();
$('select#node-input-query3').val(disQB.query3_selected);
$('#node-input-query3').val(disQB.query3_selected);

disQB.queryvalue3_selected = $('#node-input-queryvalue3hidden').val();
$('select#node-input-queryvalue3').val(disQB.queryvalue3_selected);
$('#node-input-queryvalue3').val(disQB.queryvalue3_selected);

disQB.passages_selected = $('#node-input-passageshidden').val();
$('inpu#node-input-passages').val(disQB.passages_selected);
$('#node-input-passages').val(disQB.passages_selected);

disQB.nlp_query_selected = $('#node-input-nlp_queryhidden').val();
$('#node-input-nlp_query').val(disQB.nlp_query_selected);
}


Expand Down Expand Up @@ -579,6 +625,9 @@
disQB.collection_selected = $('#node-input-collection').val();
$('#node-input-collectionhidden').val(disQB.collection_selected);

disQB.querynlp_selected = $('#node-input-querynlp').val();
$('#node-input-querynlphidden').val(disQB.querynlp_selected);

disQB.query1_selected = $('#node-input-query1').val();
$('#node-input-query1hidden').val(disQB.query1_selected);

Expand All @@ -599,6 +648,9 @@

disQB.passages_selected = $('#node-input-passages').val();
$('#node-input-passageshidden').val(disQB.passages_selected);

disQB.nlp_query_selected = $('#node-input-nlp_query').val();
$('#node-input-nlp_queryhidden').val(disQB.nlp_query_selected);
}

(function() {
Expand All @@ -611,6 +663,10 @@
environmenthidden: {value: ''},
collection: {value: ''},
collectionhidden: {value: ''},
nlp_query: {value: 'true'},
nlp_queryhidden: {value: 'true'},
querynlp: {value: ''},
querynlphidden: {value: ''},
query1: {value: ''},
query1hidden: {value: ''},
queryvalue1: {value: ''},
Expand Down

0 comments on commit a00bceb

Please sign in to comment.