From 2350729a9609d8c0a353ab4c84b95fdc22590549 Mon Sep 17 00:00:00 2001 From: chughts Date: Tue, 20 Jun 2017 12:14:39 +0100 Subject: [PATCH 1/3] Implement NLP Query in Discovery Node --- services/discovery/discovery-utils.js | 20 +++++++++- services/discovery/v1.html | 57 ++++++++++++++++----------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js index 28447ff3..0c6e6d1f 100644 --- a/services/discovery/discovery-utils.js +++ b/services/discovery/discovery-utils.js @@ -34,6 +34,21 @@ DiscoveryUtils.prototype = { return params; }, + buildParamsForQuery: function(msg, config, params) { + var sourceField = 'query', + targetField = 'query'; + + if (config.nlp_query) { + targetField = 'natural_language_query'; + } + if (msg.discoveryparams && msg.discoveryparams[sourceField]) { + params[targetField] = msg.discoveryparams[sourceField]; + } else if (config[sourceField]) { + params[targetField] = config[sourceField]; + } + return params; + }, + buildParamsForPayload: function(msg, config, params) { var isJSON = this.isJsonString(msg.payload) || this.isJsonObject(msg.payload); @@ -67,11 +82,12 @@ DiscoveryUtils.prototype = { var params = {}, me = this; - params = this.buildParamsForName(msg, config, params); + params = me.buildParamsForName(msg, config, params); + params = me.buildParamsForQuery(msg, config, params); ['environment_id', 'collection_id', 'configuration_id', 'collection_name', - 'query', 'passages', 'description', 'size' + 'passages', 'description', 'size' ].forEach(function(f) { params = me.buildParamsFor(msg, config, params, f); }); diff --git a/services/discovery/v1.html b/services/discovery/v1.html index 35e349b0..b819f428 100644 --- a/services/discovery/v1.html +++ b/services/discovery/v1.html @@ -36,6 +36,7 @@
@@ -84,10 +84,18 @@ +
+ + + +
+
+ +
@@ -279,6 +287,7 @@ $('#node-input-configuration_id').parent().hide(); $('#node-input-count').parent().hide(); $('#node-input-passages').parent().hide(); + $('#node-input-nlp_query').parent().hide(); $('#node-input-query').parent().hide(); $('#node-input-filter').parent().hide(); $('#node-input-aggregation').parent().hide(); @@ -333,6 +342,7 @@ + ', #node-input-collection_id' + ', #node-input-count' + ', #node-input-passages' + + ', #node-input-nlp_query' + ', #node-input-query' + ', #node-input-filter' + ', #node-input-aggregation' @@ -372,37 +382,38 @@ RED.nodes.registerType('watson-discovery-v1', { category: 'IBM Watson', defaults: { - name: {value: ""}, - environmentname: {value: ""}, - environment_id: {value: ""}, - collection_id: {value: ""}, - configurationname: {value: ""}, - configuration_id: {value: ""}, - collection_name: {value: ""}, - count: {value: "1"}, - passages: {value: "false"}, - query: {value: ""}, - filter: {value: ""}, - aggregation: {value: ""}, - return: {value: ""}, - description: {value: ""}, + name: {value: ''}, + environmentname: {value: ''}, + environment_id: {value: ''}, + collection_id: {value: ''}, + configurationname: {value: ''}, + configuration_id: {value: ''}, + collection_name: {value: ''}, + count: {value: '1'}, + passages: {value: 'false'}, + nlp_query: {value: 'false'}, + query: {value: ''}, + filter: {value: ''}, + aggregation: {value: ''}, + return: {value: ''}, + description: {value: ''}, size: {value: 0}, - "discovery-method": {value:"listEnvrionments"} + 'discovery-method': {value:'listEnvrionments'} }, credentials: { - username: {type:"text"}, - password: {type:"password"} + username: {type:'text'}, + password: {type:'password'} }, - color: "rgb(230,140,80)", + color: 'rgb(230,140,80)', inputs: 1, outputs: 1, - icon: "discovery.png", - paletteLabel: "discovery", + icon: 'discovery.png', + paletteLabel: 'discovery', label: function() { - return this.name || "discovery"; + return this.name || 'discovery'; }, labelStyle: function() { - return this.name ? "node_label_italic" : ""; + return this.name ? 'node_label_italic' : ''; }, oneditprepare: oneditprepare }); From a00bceb3f21f221199812a72a5c7fd558925286f Mon Sep 17 00:00:00 2001 From: chughts Date: Tue, 20 Jun 2017 16:39:31 +0100 Subject: [PATCH 2/3] Add support for NLP Query in Discovery Node --- README.md | 3 + package.json | 2 +- services/conversation/v1.html | 1 - services/discovery/discovery-utils.js | 28 ++++++-- services/discovery/v1-query-builder.html | 92 +++++++++++++++++++----- 5 files changed, 101 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 855cd45e..d70d938a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix CLA assistant +### 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 diff --git a/package.json b/package.json index 2229be25..9ae6041c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/services/conversation/v1.html b/services/conversation/v1.html index 52cd75c2..da0ac7d9 100644 --- a/services/conversation/v1.html +++ b/services/conversation/v1.html @@ -99,7 +99,6 @@ -