From 50870f75238d258e51471e6e877b38486ee341e0 Mon Sep 17 00:00:00 2001 From: chughts Date: Wed, 22 Jan 2020 22:26:04 +0000 Subject: [PATCH 01/11] Migrate to ibm-watson --- README.md | 8 + services/assistant/v1.html | 16 +- services/assistant/v1.js | 304 +++++++++++++++++++++---------------- 3 files changed, 180 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index 68f17100..6a8e7945 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,14 @@ Node-RED Watson Nodes for IBM Cloud CLA assistant +### New in version 0.9.0 +- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of + - Assistant V1 + - Assistant V2 +- All Nodes now require Node-RED 1.0.x or above +- Remove watson-developer-cloud dependancy +- Remove code for redundant nodes + ### New in version 0.8.2 - Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of - Document Translator node diff --git a/services/assistant/v1.html b/services/assistant/v1.html index 04bd8e2b..b3192f77 100644 --- a/services/assistant/v1.html +++ b/services/assistant/v1.html @@ -39,11 +39,6 @@ -
- - - -
@@ -135,14 +130,6 @@ $('#conversation-form-tips').hide(); } }); - $('input#node-input-default-endpoint').change(function () { - var checked = $('input#node-input-default-endpoint').prop('checked'); - if (checked) { - $('#node-input-service-endpoint').parent().hide(); - } else { - $('#node-input-service-endpoint').parent().show(); - } - }); $.getJSON('watson-conversation/vcap/') .done(function (service) { @@ -165,8 +152,7 @@ multiuser: {value: false}, context: {value: true}, 'empty-payload': {value: false}, - 'default-endpoint' : {value: true}, - 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'}, + 'service-endpoint' : {value: ''}, timeout: {value: '', validate: RED.validators.number(true)}, 'optout-learning': {value: false} }, diff --git a/services/assistant/v1.js b/services/assistant/v1.js index e82240ff..af8cd072 100644 --- a/services/assistant/v1.js +++ b/services/assistant/v1.js @@ -16,11 +16,13 @@ module.exports = function(RED) { const SERVICE_IDENTIFIER = 'assistant', - OLD_SERVICE_IDENTIFIER = 'conversation'; + OLD_SERVICE_IDENTIFIER = 'conversation', + AssistantV1 = require('ibm-watson/assistant/v1'), + { IamAuthenticator } = require('ibm-watson/auth'); var pkg = require('../../package.json'), - AssistantV1 = require('watson-developer-cloud/assistant/v1'), serviceutils = require('../../utilities/service-utils'), + payloadutils = require('../../utilities/payload-utils'), service = null, sApikey = null, sUsername = null, @@ -50,10 +52,9 @@ module.exports = function(RED) { shape: 'ring', text: 'missing payload' }); - node.error('Missing property: msg.payload', msg); - return false; + return Promise.reject('Missing property: msg.payload'); } - return true; + return Promise.resolve(); } function verifyOptionalInputs(node, msg, config, params) { @@ -70,17 +71,7 @@ module.exports = function(RED) { } } - function verifyInputs(node, msg, config, params) { - if (!config.workspaceid && !msg.params.workspace_id) { - node.error('Missing workspace_id. check node documentation.', msg); - return false; - } - // mandatory message - params.input = { - text: msg.payload - }; - var prop = null; - + function setContextParams(node, msg, config, params) { if (config.context) { if (config.multiuser) { if (msg.user) { @@ -105,15 +96,20 @@ module.exports = function(RED) { } } } + } + function setWorkspaceParams(node, msg, config, params) { // workspaceid can be either configured in the node, // or sent into msg.params.workspace_id if (config.workspaceid) { - params.workspace_id = config.workspaceid; + params.workspaceId = config.workspaceid; } if (msg.params && msg.params.workspace_id) { - params.workspace_id = msg.params.workspace_id; + params.workspaceId = msg.params.workspace_id; } + } + + function setSavedContextParams(node, msg, config, params) { // option context in JSON format if (msg.params && msg.params.context) { if (config.context) { @@ -127,13 +123,37 @@ module.exports = function(RED) { } params.context = msg.params.context; } + } + + function setAlternativeIntentsParams(node, msg, config, params) { // optional alternate_intents : boolean if (msg.params && msg.params.alternate_intents) { params.alternate_intents = msg.params.alternate_intents; } + } - verifyOptionalInputs(node, msg, config, params); - return true; + function verifyInputs(node, msg, config, params) { + return new Promise(function resolver(resolve, reject) { + if (!config.workspaceid && (!msg || !msg.params ||!msg.params.workspace_id)) { + reject('Missing workspace_id. check node documentation.'); + } + + // mandatory message + params.input = { + text: msg.payload + }; + + var prop = null; + + // Invoke each of the functions building up the params in turn + [setContextParams, setWorkspaceParams, setSavedContextParams, + setAlternativeIntentsParams, verifyOptionalInputs].forEach((f) => { + f(node, msg, config, params); + }); + + resolve(); + + }); } function verifyCredentials(msg, k, u, p) { @@ -153,154 +173,172 @@ module.exports = function(RED) { // takes precedence over the existing one. // If msg.params contain credentials then these will Overridde // the bound or configured credentials. - const serviceSettings = { - headers: { - 'User-Agent': pkg.name + '-' + pkg.version + return new Promise(function resolver(resolve, reject) { + let authSettings = {}, + serviceSettings = { + headers: { + 'User-Agent': pkg.name + '-' + pkg.version + } + }; + + let userName = sUsername || node.credentials.username, + passWord = sPassword || node.credentials.password, + apiKey = sApikey || node.credentials.apikey, + endpoint = '', + optoutLearning = false, + version = '2018-09-20'; + + if (!verifyCredentials(msg, apiKey, userName, passWord)) { + reject('Missing Watson Assistant API service credentials'); + } + + if (msg.params) { + if (msg.params.username) { + userName = msg.params.username; + } + if (msg.params.password) { + passWord = msg.params.password; + } + if (msg.params.apikey) { + apiKey = msg.params.apikey; + } + if (msg.params.version) { + version = msg.params.version; + } } - }; - - let userName = sUsername || node.credentials.username, - passWord = sPassword || node.credentials.password, - apiKey = sApikey || node.credentials.apikey, - endpoint = '', - optoutLearning = false, - version = '2018-09-20'; - - if (!verifyCredentials(msg, apiKey, userName, passWord)) { - node.error('Missing Watson Assistant API service credentials'); - return false; - } - if (msg.params) { - if (msg.params.username) { - userName = msg.params.username; + if (apiKey) { + authSettings.apikey = apiKey; + } else { + authSettings.username = userName; + authSettings.password = passWord; } - if (msg.params.password) { - passWord = msg.params.password; + serviceSettings.authenticator = new IamAuthenticator(authSettings); + + serviceSettings.version = version; + serviceSettings.version_date = version; + + if (service) { + endpoint = service.url; } - if (msg.params.apikey) { - apiKey = msg.params.apikey; + if (config['service-endpoint']) { + endpoint = config['service-endpoint']; } - if (msg.params.version) { - version = msg.params.version; + if (msg.params && msg.params.endpoint) { + endpoint = msg.params.endpoint; } - } - if (apiKey) { - serviceSettings.iam_apikey = apiKey; - } else { - serviceSettings.username = userName; - serviceSettings.password = passWord; - } - - serviceSettings.version = version; - serviceSettings.version_date = version; + if (endpoint) { + serviceSettings.url = endpoint; + } - if (service) { - endpoint = service.url; - } - if (!config['default-endpoint'] && config['service-endpoint']) { - endpoint = config['service-endpoint']; - } - if (msg.params && msg.params.endpoint) { - endpoint = msg.params.endpoint; - } + if ((msg.params && msg.params['optout_learning'])){ + optoutLearning = true; + } else if (config['optout-learning']){ + optoutLearning = true; + } - if (endpoint) { - serviceSettings.url = endpoint; - } + if (optoutLearning){ + serviceSettings.headers = serviceSettings.headers || {}; + serviceSettings.headers['X-Watson-Learning-Opt-Out'] = '1'; + } - if ((msg.params && msg.params['optout_learning'])){ - optoutLearning = true; - } else if (config['optout-learning']){ - optoutLearning = true; - } + if (config['timeout'] && config['timeout'] !== '0' && isFinite(config['timeout'])){ + serviceSettings.timeout = parseInt(config['timeout']); + } - if (optoutLearning){ - serviceSettings.headers = serviceSettings.headers || {}; - serviceSettings.headers['X-Watson-Learning-Opt-Out'] = '1'; - } + if (msg.params && msg.params.timeout !== '0' && isFinite(msg.params.timeout)){ + serviceSettings.timeout = parseInt(msg.params.timeout); + } - if (config['timeout'] && config['timeout'] !== '0' && isFinite(config['timeout'])){ - serviceSettings.timeout = parseInt(config['timeout']); - } + if (msg.params && msg.params.disable_ssl_verification){ + serviceSettings.disable_ssl_verification = true; + } - if (msg.params && msg.params.timeout !== '0' && isFinite(msg.params.timeout)){ - serviceSettings.timeout = parseInt(msg.params.timeout); - } + node.service = new AssistantV1(serviceSettings); + resolve(); + }); + } - if (msg.params && msg.params.disable_ssl_verification){ - serviceSettings.disable_ssl_verification = true; - } + function processResponse(response, node, msg, config) { + return new Promise(function resolver(resolve, reject) { + if (response === null || typeof (response) === 'undefined') { + reject('call to watson conversation service failed'); + } - node.service = new AssistantV1(serviceSettings); - return true; - } + msg.payload = response; + if (response && response.result) { + msg.payload = response.result; + } - function processResponse(err, body, node, msg, config) { - if (err !== null && (body === null || typeof (body) === 'undefined')) { - node.error(err, msg); - node.status({ - fill: 'red', - shape: 'ring', - text: 'call to watson conversation service failed' - }); - return; - } - msg.payload = body; + let body = msg.payload; - if (config.context) { - if (config.multiuser && msg.user) { - node.context().flow.set('context-' + msg.user, body.context); - } else { - if (msg.user) { - node.warn('msg.user ignored when multiple users not set in node'); + if (config.context && body && body.context) { + if (config.multiuser && msg.user) { + node.context().flow.set('context-' + msg.user, body.context); + } else { + if (msg.user) { + node.warn('msg.user ignored when multiple users not set in node'); + } + node.context().flow.set('context', body.context); } - node.context().flow.set('context', body.context); } - } - node.send(msg); - node.status({}); + resolve(); + }); } function execute(params, node, msg, config) { - node.status({ - fill: 'blue', - shape: 'dot', - text: 'Calling Conversation service ...' - }); - // call POST /message through SDK - node.service.message(params, function(err, body) { - processResponse(err, body, node, msg, config); + return new Promise(function resolver(resolve, reject) { + node.status({ + fill: 'blue', + shape: 'dot', + text: 'Calling Conversation service ...' + }); + // call POST /message through SDK + node.service.message(params) + .then((response) => { + return processResponse(response, node, msg, config); + }) + .then(() => { + resolve(); + }) + .catch((err) => { + reject(err); + }); }); } // This is the Watson Conversation V1 (GA) Node function WatsonConversationV1Node(config) { - var node = this, - b = false; + var node = this; RED.nodes.createNode(this, config); - node.on('input', function(msg) { + this.on('input', function(msg, send, done) { var params = {}; node.status({}); - b = verifyPayload(node, msg, config); - if (!b) { - return; - } - b = verifyInputs(node, msg, config, params); - if (!b) { - return; - } - b = verifyServiceCredentials(node, msg, config); - if (!b) { - return; - } - execute(params, node, msg, config); + verifyPayload(node, msg, config) + .then(() => { + return verifyInputs(node, msg, config, params); + }) + .then(() => { + return verifyServiceCredentials(node, msg, config); + }) + .then(() => { + return execute(params, node, msg, config); + }) + .then(() => { + send(msg); + node.status({}); + done(); + }) + .catch(function(err){ + let errMsg = payloadutils.reportError(node, msg, err); + done(errMsg); + }); }); } From d6820d6c66dda6d274c2d551dadb86d37f0d27da Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:17:04 +0000 Subject: [PATCH 02/11] Migrate to ibm-watson --- package.json | 2 +- services/assistant/v1.html | 2 +- services/assistant/v2.html | 19 +------- services/assistant/v2.js | 90 ++++++++++++++++++++++---------------- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index bcfab526..f818672f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-watson", - "version": "0.8.2", + "version": "0.9.0", "description": "A collection of Node-RED nodes for IBM Watson services", "dependencies": { "async": "^1.5.2", diff --git a/services/assistant/v1.html b/services/assistant/v1.html index b3192f77..ddb0b702 100644 --- a/services/assistant/v1.html +++ b/services/assistant/v1.html @@ -39,7 +39,7 @@
-
+
diff --git a/services/assistant/v2.html b/services/assistant/v2.html index 01f1a59f..3a8c603d 100644 --- a/services/assistant/v2.html +++ b/services/assistant/v2.html @@ -41,11 +41,6 @@
- - - -
-
@@ -115,7 +110,7 @@
  • msg.payload : the message of the Assistant to analyse. Format: String
  • msg.params.session_id (optional): unique identifier for the conversation session. If this field is not provided then the node will generate a new session_id and - return itt as part of the response. If the node is not used in multi-session mode, then + return it as part of the response. If the node is not used in multi-session mode, then a session_id need not be provided, to reset the session_id in single-session mode send a null value as the session_id. Format: String
  • msg.params.assistant_id : unique identifier of the assistant to be used. Could be also configured in the node. Format: String
  • @@ -171,15 +166,6 @@ $('#assistantv2-form-tips').hide(); } }); - - $('input#node-input-default-endpoint').change(function () { - var checked = $('input#node-input-default-endpoint').prop('checked'); - if (checked) { - $('#node-input-service-endpoint').parent().hide(); - } else { - $('#node-input-service-endpoint').parent().show(); - } - }); } assistantV2.checkCredentials = function () { @@ -205,8 +191,7 @@ category: 'IBM Watson', defaults: { name: { value: '' }, - 'default-endpoint' : {value: true}, - 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'}, + 'service-endpoint' : {value: ''}, assistant_id: {value: ''}, debug: {value: false}, restart: {value: false}, diff --git a/services/assistant/v2.js b/services/assistant/v2.js index a1db637c..6790ee45 100644 --- a/services/assistant/v2.js +++ b/services/assistant/v2.js @@ -17,10 +17,11 @@ module.exports = function(RED) { const SERVICE_IDENTIFIER = 'assistant', OLD_SERVICE_IDENTIFIER = 'conversation', - SERVICE_VERSION = '2018-11-08'; + SERVICE_VERSION = '2018-11-08', + AssistantV2 = require('ibm-watson/assistant/v2'), + { IamAuthenticator } = require('ibm-watson/auth'); var pkg = require('../../package.json'), - AssistantV2 = require('watson-developer-cloud/assistant/v2'), serviceutils = require('../../utilities/service-utils'), payloadutils = require('../../utilities/payload-utils'), service = null, @@ -64,7 +65,7 @@ module.exports = function(RED) { creds.password = msg.params.password; } if (msg.params.apikey) { - creds.apiKey = msg.params.apikey; + creds.apikey = msg.params.apikey; } } @@ -141,6 +142,10 @@ module.exports = function(RED) { if (msg.params) { checkAndSet(msg.params, params, 'assistant_id'); } + if (params && params['assistant_id']) { + params.assistantId = params['assistant_id']; + delete params['assistant_id']; + } } function setInputOptions(msg, params) { @@ -173,7 +178,7 @@ module.exports = function(RED) { 'text' : msg.payload, 'options' : {} }, - 'session_id' : setSessionID(msg) + 'sessionId' : setSessionID(msg) }; let context = setContext(msg, params); @@ -190,8 +195,9 @@ module.exports = function(RED) { } function setServiceSettings(msg, creds) { - const serviceSettings = { - headers: { + let authSettings = {}; + let serviceSettings = { + headers: { 'User-Agent': pkg.name + '-' + pkg.version } }; @@ -201,16 +207,17 @@ module.exports = function(RED) { version = SERVICE_VERSION; if (creds.apikey) { - serviceSettings.iam_apikey = creds.apikey; + authSettings.apikey = creds.apikey; } else { - serviceSettings.username = creds.username; - serviceSettings.password = creds.password; + authSettings.username = creds.username; + authSettings.password = creds.password; } + serviceSettings.authenticator = new IamAuthenticator(authSettings); if (service) { endpoint = service.url; } - if (!config['default-endpoint'] && config['service-endpoint']) { + if (config['service-endpoint']) { endpoint = config['service-endpoint']; } @@ -260,41 +267,49 @@ module.exports = function(RED) { function checkSession(params) { return new Promise(function resolver(resolve, reject){ - if (params.session_id) { + if (params.sessionId) { resolve(); } else { - node.service.createSession({ - assistant_id: params.assistant_id - }, function(err, response) { - if (err) { - reject(err); - } else if (response && response.session_id) { - params.session_id = response.session_id; - if (!config.multisession) { - node.context().flow.set('session_id', params.session_id); + node.service.createSession({assistantId: params.assistantId}) + .then((response) => { + if (response && response.result && response.result.session_id) { + params.sessionId = response.result.session_id; + } else if (response && response.session_id) { + params.sessionId = response.session_id; } - resolve(); - } else { - reject('Unable to set session'); - } - }); + if (params.sessionId) { + if (!config.multisession) { + node.context().flow.set('session_id', params.sessionId); + } + resolve(); + } else { + reject('Unable to set session'); + } + }) + .catch((err) => { + reject(err); + }); } }); } function messageTurn(params) { - return new Promise(function resolver(resolve, reject){ - node.service.message(params, function(err, body) { - if (err) { + return new Promise(function resolver(resolve, reject) { + node.service.message(params) + .then((response) => { + if (response.result) { + resolve(response.result); + } else { + resolve(response); + } + }) + .catch((err) => { reject(err); - } else { - resolve(body); - } - }); + }) }); } - this.on('input', function(msg) { + this.on('input', function(msg, send, done) { var creds = setCredentials(msg), params = {}; @@ -325,17 +340,18 @@ module.exports = function(RED) { return messageTurn(params); }) .then(function(body){ - body.session_id = params.session_id; + body.session_id = params.sessionId; msg.payload = body; return Promise.resolve(); }) .then(function(){ node.status({}); - node.send(msg); + send(msg); + done(); }) .catch(function(err){ - payloadutils.reportError(node,msg,err); - node.send(msg); + let errMsg = payloadutils.reportError(node, msg, err); + done(errMsg); }); }); From f1c0abe3b704d4e2051597004cdbd07a87698139 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:29:33 +0000 Subject: [PATCH 03/11] Remove redundant nodes --- .../icons/AlchemyDataNews.png | Bin 1671 -> 0 bytes services/alchemy_data_news/icons/news2.png | Bin 745 -> 0 bytes services/alchemy_data_news/v1.html | 315 ------------------ services/alchemy_data_news/v1.js | 122 ------- .../icons/AlchemyLanguage.png | Bin 1671 -> 0 bytes .../alchemy_date_extraction/icons/temp.txt | 17 - services/alchemy_date_extraction/v1.html | 90 ----- services/alchemy_date_extraction/v1.js | 102 ------ .../icons/AlchemyLanguage.png | Bin 1671 -> 0 bytes services/alchemy_language/icons/temp.txt | 17 - services/alchemy_language/v1.html | 220 ------------ services/alchemy_language/v1.js | 163 --------- .../alchemy_vision/icons/AlchemyVision.png | Bin 1671 -> 0 bytes services/alchemy_vision/icons/temp.txt | 17 - services/alchemy_vision/v1.html | 101 ------ services/alchemy_vision/v1.js | 186 ----------- 16 files changed, 1350 deletions(-) delete mode 100644 services/alchemy_data_news/icons/AlchemyDataNews.png delete mode 100644 services/alchemy_data_news/icons/news2.png delete mode 100644 services/alchemy_data_news/v1.html delete mode 100644 services/alchemy_data_news/v1.js delete mode 100644 services/alchemy_date_extraction/icons/AlchemyLanguage.png delete mode 100644 services/alchemy_date_extraction/icons/temp.txt delete mode 100644 services/alchemy_date_extraction/v1.html delete mode 100644 services/alchemy_date_extraction/v1.js delete mode 100644 services/alchemy_language/icons/AlchemyLanguage.png delete mode 100644 services/alchemy_language/icons/temp.txt delete mode 100644 services/alchemy_language/v1.html delete mode 100644 services/alchemy_language/v1.js delete mode 100644 services/alchemy_vision/icons/AlchemyVision.png delete mode 100644 services/alchemy_vision/icons/temp.txt delete mode 100644 services/alchemy_vision/v1.html delete mode 100644 services/alchemy_vision/v1.js diff --git a/services/alchemy_data_news/icons/AlchemyDataNews.png b/services/alchemy_data_news/icons/AlchemyDataNews.png deleted file mode 100644 index dedba865d287868cbbab0c6fd28ff0f84cdbf71b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1671 zcmeAS@N?(olHy`uVBq!ia0vp^azHH4!3HEh~aDsl^esu>t;Dy)Fa+|-gpg^Jvqyke^gTP3gx zD1^l#~=$ z>Fbx5m+O@q>*W`v>l<2HTIw4Z=^Gj80#)c1SLT%@R_NvxD?a#8ycOWDy)d+*y*DhOjBG80syc2lYWR`i6Q2`q;DqJqvdqimr;p0*EHC zuOOD$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zD?NweUs6P3SPEjIllXZ!yJA+TbN|DvU9#h=XZIHOrO4ntKrWZ zBDIo=3a6f${`Q#b?G{tU%co>J?xr*CU<}>a^V#Q}@lM@5bK|CC>N>W^>gD#7xIYlD kP*&Gfzo~cb@2z)C?dybZ#yu?g0xIr3UHx3vIVCg!0I3qV-2eap diff --git a/services/alchemy_data_news/icons/news2.png b/services/alchemy_data_news/icons/news2.png deleted file mode 100644 index 2df74ffbbb172a4621108e3359b654a13be07154..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 745 zcmVP000>X1^@s6#OZ}&00088NklA{iCq|7#;Bky!sw=UV_WClvLQi`7X?9q z5~7JEb35<*9w$U~H?j{1Eu(M3{F?hXrzdOM+43xz-g)59&dvM$_WYm!^B#cp@wlJa zfT%4%SOC1#x%L1;ofesYu=vy@O0y6)2P9IzCbj2>s~ibh+32|5chchHF$Cyofy@WN zGg7@OfIa}W6cz7jO!_z-aB3Qi@i^qNg(n>1QSaRMaanWq#C?xWkzndb$N&a z8+EkG2th4;3N~D{`GZ|JpJXmb{hAd9gs9{AyCfi^`^>xHLak2iPmLgrO5^t*9BRSC z&(i>_5oVAz6A(63(6$5>8#P7xnFUFjPNklPuDd%Bv|up-6C&9zF6%IjIXhxg9fSCs7qW+EKKWt=h21iR|pedAUG z9-dy=Ow>4Zj#Vw+1*>x45=IRGOqcj#uz!CucEDE%&~bt3@_u_S&xv96+C^asV=qfG;AM%GtA_z}+QW*8UD0 z=kU^Xr@bB%^eA`P_!K5*Ptg}-v_(^y b*8TGf-gkd7+tG7$00000NkvXXu0mjfp_^j| diff --git a/services/alchemy_data_news/v1.html b/services/alchemy_data_news/v1.html deleted file mode 100644 index 3504acda..00000000 --- a/services/alchemy_data_news/v1.html +++ /dev/null @@ -1,315 +0,0 @@ - - - - - diff --git a/services/alchemy_data_news/v1.js b/services/alchemy_data_news/v1.js deleted file mode 100644 index 4aab547c..00000000 --- a/services/alchemy_data_news/v1.js +++ /dev/null @@ -1,122 +0,0 @@ -module.exports = function(RED) { - - var cfEnv = require("cfenv"); - var appEnv = cfEnv.getAppEnv(); - - var watson = require('watson-developer-cloud'); - - var newss = []; - for (var i in appEnv.services) { - if (i.match(/^(alchemy_api)/i)) { - newss = newss.concat(appEnv.services[i].map(function(v) { - return { - name: v.name, - label: v.label, - key: v.credentials.apikey - }; - })); - } - } - - RED.httpAdmin.get('/watson-news/vcap', function(req,res) { - res.send(JSON.stringify(newss)); - }); - - function NewsNode(config) { - - RED.nodes.createNode(this,config); - - var node = this; - - this.name = config.name; - this.service = config.service; - this.key = config.key; - this.start = config.start; - this.end = config.end; - this.max = config.max; - this.mode = config.node; - this.custom = config.custom; - this.query = config.query; - this.queries = config.queries; - this.results = config.results; - - this.buildQuery = function(params) { - var queries=[]; - for (var i=0;i~aDsl^esu>t;Dy)Fa+|-gpg^Jvqyke^gTP3gx zD1^l#~=$ z>Fbx5m+O@q>*W`v>l<2HTIw4Z=^Gj80#)c1SLT%@R_NvxD?a#8ycOWDy)d+*y*DhOjBG80syc2lYWR`i6Q2`q;DqJqvdqimr;p0*EHC zuOOD$fQ+*8FUm{>Iv3<9J3||=@hD;l$Jqc)w{k8@O)SYT3dzsUv2z54wSs4EVtQ&& zYGO*IjXt^xsAd~|kav;14+&eaC@^sCxPUrg5oO1ovRT^;`d6vn)R~rE5#n zTDB5*;ctgGFq9ou4G8-ob651QoQH5m7R!NoeAy4uSDf~hO1mi@>t}S#&qG+@temZ= zT=QCiOGkF_F3h!O)zsWI=Yz|nSu0jw%(!#1xooli!BB})xpuD^`yJQXOS3s-ieydN z&vKW${^0cwx-~pq+EXW3CoYILl&va?K6l`sT2q}F`!CUIaT$ixB>_*@N3Z|Ga{2QN zxt#J;pEt8x`t+NP_Fpm+|1Y(sxp+Z|*FV=D>3%i8LKBJS4~^Lu?mk$2rZLrk>+0t%^BH?T%EmBj zyX>DU@n86nd_k)A!CP|@{Y%7MR@$`NvM?90P5Ct~TtE6^@|*kem3L;RwHC6>Dg2Qa zsZ!5>d;2u~DbWkAOs+JXJ7M}d;l5ta@2-oEXYOH=&UL81mRg%6-}-n1>y(R5zCX-` z@{K%WmYEmNn67p5aql;l^Z!_ctr?GsR@{%tRkGYVKT5vb`RB1CaT`h=U)cSCzazKo zbaGODV)ec3&2GL?ZkNl9Z1$R6RQto|SM>Sb!Tz_$a(Aq9oVS-DzESl_%ifz8`8SK? zm+ij&RCi{&BtdQ(n&bZj(qmB(sArFzA@^%zujomWo!^ zocCw;-m=3d(%$z&VuktdX<=4vZ{!c#v)p#jJik3{d3*BTiepy~+!rdRJvJWs&}BYz^2-*^wZCt?vQ+yvyP8k#ROjlgyIaciZwGDIH+4qo!@uG>e|~5F zPcgB%U%8>JsL*Yn&a9m!^A7!!F*}&Oz@F)4Yg5>)2NQV?J4(EMEwXf5^AFwdJ^Xz} z9=mrP{kQNozkI_Zv(W7pxzge%w_TUDk6T!OIHmsp>kk9AB>sk_n+5(_5 zB-8IPr$#+!{)xv5r(HL?#kbTy%oQtUT6-nG@W(r^U)vTvZoZ_MnYCW6xBq|=+i@+k zgnE`!8Ef^DpZcBqzD?NweUs6P3SPEjIllXZ!yJA+TbN|DvU9#h=XZIHOrO4ntKrWZ zBDIo=3a6f${`Q#b?G{tU%co>J?xr*CU<}>a^V#Q}@lM@5bK|CC>N>W^>gD#7xIYlD kP*&Gfzo~cb@2z)C?dybZ#yu?g0xIr3UHx3vIVCg!0I3qV-2eap diff --git a/services/alchemy_date_extraction/icons/temp.txt b/services/alchemy_date_extraction/icons/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/alchemy_date_extraction/icons/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/alchemy_date_extraction/v1.html b/services/alchemy_date_extraction/v1.html deleted file mode 100644 index 5aa8c414..00000000 --- a/services/alchemy_date_extraction/v1.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - diff --git a/services/alchemy_date_extraction/v1.js b/services/alchemy_date_extraction/v1.js deleted file mode 100644 index 13a771bd..00000000 --- a/services/alchemy_date_extraction/v1.js +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright 2013,2015, 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'gateway-a.watsonplatform.net'; - var watson = require('watson-developer-cloud'), - payloadutils = require('../../utilities/payload-utils'), - serviceutils = require('../../utilities/service-utils'), - apikey, s_apikey, - service = serviceutils.getServiceCredsAlchemy(SERVICE_IDENTIFIER); - - // Require the Cloud Foundry Module to pull credentials from bound service - // If they are found then the api key is stored in the variable s_apikey. - // - // This separation between s_apikey and apikey is to allow - // the end user to modify the key redentials when the service is not bound. - // Otherwise, once set apikey is never reset, resulting in a frustrated - // user who, when he errenously enters bad credentials, can't figure out why - // the edited ones are not being taken. - - if (service) { - s_apikey = service.apikey; - } - - RED.httpAdmin.get('/alchemy-date-extraction/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - - // This is the Alchemy Date Extract Node - function AlchemyDateExtractionNode (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - this.status({fill:'red', shape:'ring', text:'missing payload'}); - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - // If it is present the newly provided user entered key takes precedence over the existing one. - apikey = s_apikey || this.credentials.apikey; - this.status({}); - - if (!apikey) { - this.status({fill:'red', shape:'ring', text:'missing credentials'}); - var message = 'Missing Alchemy API service credentials'; - node.error(message, msg); - return; - } - - var alchemy_language = watson.alchemy_language( { api_key: apikey } ); - var date = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') - var params = { anchorDate: date}; - - if (payloadutils.urlCheck(msg.payload)) { - params['url'] = msg.payload; - } else { - params['text'] = msg.payload; - } - - - for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; } - - alchemy_language.dates(params, function (err, response) { - if (err || response.status === 'ERROR') { - node.status({fill:'red', shape:'ring', text:'call to alchmeyapi language service failed'}); - console.log('Error:', msg, err); - node.error(err, msg); - } - else { - msg.features = response; - node.send(msg); - } - }); - - }); - } - - - //Register the node as alchemy-feature-extract to nodeRED - RED.nodes.registerType('alchemy-date-extraction', AlchemyDateExtractionNode, { - credentials: { - apikey: {type:"password"} - } - }); -}; diff --git a/services/alchemy_language/icons/AlchemyLanguage.png b/services/alchemy_language/icons/AlchemyLanguage.png deleted file mode 100644 index dedba865d287868cbbab0c6fd28ff0f84cdbf71b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1671 zcmeAS@N?(olHy`uVBq!ia0vp^azHH4!3HEh~aDsl^esu>t;Dy)Fa+|-gpg^Jvqyke^gTP3gx zD1^l#~=$ z>Fbx5m+O@q>*W`v>l<2HTIw4Z=^Gj80#)c1SLT%@R_NvxD?a#8ycOWDy)d+*y*DhOjBG80syc2lYWR`i6Q2`q;DqJqvdqimr;p0*EHC zuOOD$fQ+*8FUm{>Iv3<9J3||=@hD;l$Jqc)w{k8@O)SYT3dzsUv2z54wSs4EVtQ&& zYGO*IjXt^xsAd~|kav;14+&eaC@^sCxPUrg5oO1ovRT^;`d6vn)R~rE5#n zTDB5*;ctgGFq9ou4G8-ob651QoQH5m7R!NoeAy4uSDf~hO1mi@>t}S#&qG+@temZ= zT=QCiOGkF_F3h!O)zsWI=Yz|nSu0jw%(!#1xooli!BB})xpuD^`yJQXOS3s-ieydN z&vKW${^0cwx-~pq+EXW3CoYILl&va?K6l`sT2q}F`!CUIaT$ixB>_*@N3Z|Ga{2QN zxt#J;pEt8x`t+NP_Fpm+|1Y(sxp+Z|*FV=D>3%i8LKBJS4~^Lu?mk$2rZLrk>+0t%^BH?T%EmBj zyX>DU@n86nd_k)A!CP|@{Y%7MR@$`NvM?90P5Ct~TtE6^@|*kem3L;RwHC6>Dg2Qa zsZ!5>d;2u~DbWkAOs+JXJ7M}d;l5ta@2-oEXYOH=&UL81mRg%6-}-n1>y(R5zCX-` z@{K%WmYEmNn67p5aql;l^Z!_ctr?GsR@{%tRkGYVKT5vb`RB1CaT`h=U)cSCzazKo zbaGODV)ec3&2GL?ZkNl9Z1$R6RQto|SM>Sb!Tz_$a(Aq9oVS-DzESl_%ifz8`8SK? zm+ij&RCi{&BtdQ(n&bZj(qmB(sArFzA@^%zujomWo!^ zocCw;-m=3d(%$z&VuktdX<=4vZ{!c#v)p#jJik3{d3*BTiepy~+!rdRJvJWs&}BYz^2-*^wZCt?vQ+yvyP8k#ROjlgyIaciZwGDIH+4qo!@uG>e|~5F zPcgB%U%8>JsL*Yn&a9m!^A7!!F*}&Oz@F)4Yg5>)2NQV?J4(EMEwXf5^AFwdJ^Xz} z9=mrP{kQNozkI_Zv(W7pxzge%w_TUDk6T!OIHmsp>kk9AB>sk_n+5(_5 zB-8IPr$#+!{)xv5r(HL?#kbTy%oQtUT6-nG@W(r^U)vTvZoZ_MnYCW6xBq|=+i@+k zgnE`!8Ef^DpZcBqzD?NweUs6P3SPEjIllXZ!yJA+TbN|DvU9#h=XZIHOrO4ntKrWZ zBDIo=3a6f${`Q#b?G{tU%co>J?xr*CU<}>a^V#Q}@lM@5bK|CC>N>W^>gD#7xIYlD kP*&Gfzo~cb@2z)C?dybZ#yu?g0xIr3UHx3vIVCg!0I3qV-2eap diff --git a/services/alchemy_language/icons/temp.txt b/services/alchemy_language/icons/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/alchemy_language/icons/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/alchemy_language/v1.html b/services/alchemy_language/v1.html deleted file mode 100644 index 700092c3..00000000 --- a/services/alchemy_language/v1.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - diff --git a/services/alchemy_language/v1.js b/services/alchemy_language/v1.js deleted file mode 100644 index fd38fc18..00000000 --- a/services/alchemy_language/v1.js +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Copyright 2013,2015, 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - - -// AlchemyAPI Text Analysis functions supported by this node -var FEATURES = { - 'page-image': 'image', - 'image-kw': 'imageKeywords', - 'feed': 'feed', - 'entity': 'entities', - 'keyword': 'keywords', - 'title': 'title', - 'author': 'author', - 'taxonomy': 'taxonomy', - 'concept': 'concepts', - 'relation': 'relations', - 'pub-date': 'publicationDate', - 'doc-sentiment': 'docSentiment', - 'doc-emotion': 'docEmotions' -}; - -module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'gateway-a.watsonplatform.net'; - - var watson = require('watson-developer-cloud'); - - var payloadutils = require('../../utilities/payload-utils'), - serviceutils = require('../../utilities/service-utils'), - apikey, s_apikey, - service = serviceutils.getServiceCredsAlchemy(SERVICE_IDENTIFIER); - - - // Require the Cloud Foundry Module to pull credentials from bound service - // If they are found then the api key is stored in the variable s_apikey. - // - // This separation between s_apikey and apikey is to allow - // the end user to modify the key redentials when the service is not bound. - // Otherwise, once set apikey is never reset, resulting in a frustrated - // user who, when he errenously enters bad credentials, can't figure out why - // the edited ones are not being taken. - - if (service) { - s_apikey = service.apikey; - } - - RED.httpAdmin.get('/alchemy-feature-extract/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - - function buildParams(wanted_features, config, msg) { - // The watson node-SDK expects the features as a single string. - - var params = { extract: wanted_features.join(',') }; - - if (config['entity-sentiment']) { - params.sentiment = '1'; - } - if (config['entity-emotion']) { - params.emotion = '1'; - } - - if (payloadutils.urlCheck(msg.payload)) { - params['url'] = msg.payload; - } else { - params['text'] = msg.payload; - } - - return params; - } - - // This is the Alchemy Data Node - - function AlchemyFeatureExtractNode (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - this.status({fill:'red', shape:'ring', text:'missing payload'}); - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - // If it is present the newly provided user entered key takes precedence over the existing one. - apikey = s_apikey || this.credentials.apikey; - this.status({}); - - if (!apikey) { - this.status({fill:'red', shape:'ring', text:'missing credentials'}); - var message = 'Missing Alchemy API service credentials'; - node.error(message, msg); - return; - } - - var alchemy_language = watson.alchemy_language( { api_key: apikey } ); - - // Check which features have been requested. - - var enabled_features = Object.keys(FEATURES).filter(function (feature) { - return config[feature] - }); - - - if (!enabled_features.length) { - this.status({fill:'red', shape:'ring', text:'no features selected'}); - var message = 'AlchemyAPI node must have at least one selected feature.'; - node.error(message, msg); - return; - } - - var params = buildParams(enabled_features, config, msg); - - // 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') { - node.status({fill:'red', shape:'ring', text:'call to alchmeyapi language service failed'}); - console.log('Error:', msg, err); - node.error(err, msg); - } - else { - msg.features = {}; - //msg.features['all'] = response; - - Object.keys(FEATURES).forEach(function (feature) { - var answer_feature = FEATURES[feature]; - - msg.features[feature] = response[answer_feature] || {}; - }); - - node.send(msg); - } - }); - - }); - } - - - //Register the node as alchemy-feature-extract to nodeRED - RED.nodes.registerType('alchemy-feature-extract', AlchemyFeatureExtractNode, { - credentials: { - apikey: {type:"password"} - } - }); -}; diff --git a/services/alchemy_vision/icons/AlchemyVision.png b/services/alchemy_vision/icons/AlchemyVision.png deleted file mode 100644 index dedba865d287868cbbab0c6fd28ff0f84cdbf71b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1671 zcmeAS@N?(olHy`uVBq!ia0vp^azHH4!3HEh~aDsl^esu>t;Dy)Fa+|-gpg^Jvqyke^gTP3gx zD1^l#~=$ z>Fbx5m+O@q>*W`v>l<2HTIw4Z=^Gj80#)c1SLT%@R_NvxD?a#8ycOWDy)d+*y*DhOjBG80syc2lYWR`i6Q2`q;DqJqvdqimr;p0*EHC zuOOD$fQ+*8FUm{>Iv3<9J3||=@hD;l$Jqc)w{k8@O)SYT3dzsUv2z54wSs4EVtQ&& zYGO*IjXt^xsAd~|kav;14+&eaC@^sCxPUrg5oO1ovRT^;`d6vn)R~rE5#n zTDB5*;ctgGFq9ou4G8-ob651QoQH5m7R!NoeAy4uSDf~hO1mi@>t}S#&qG+@temZ= zT=QCiOGkF_F3h!O)zsWI=Yz|nSu0jw%(!#1xooli!BB})xpuD^`yJQXOS3s-ieydN z&vKW${^0cwx-~pq+EXW3CoYILl&va?K6l`sT2q}F`!CUIaT$ixB>_*@N3Z|Ga{2QN zxt#J;pEt8x`t+NP_Fpm+|1Y(sxp+Z|*FV=D>3%i8LKBJS4~^Lu?mk$2rZLrk>+0t%^BH?T%EmBj zyX>DU@n86nd_k)A!CP|@{Y%7MR@$`NvM?90P5Ct~TtE6^@|*kem3L;RwHC6>Dg2Qa zsZ!5>d;2u~DbWkAOs+JXJ7M}d;l5ta@2-oEXYOH=&UL81mRg%6-}-n1>y(R5zCX-` z@{K%WmYEmNn67p5aql;l^Z!_ctr?GsR@{%tRkGYVKT5vb`RB1CaT`h=U)cSCzazKo zbaGODV)ec3&2GL?ZkNl9Z1$R6RQto|SM>Sb!Tz_$a(Aq9oVS-DzESl_%ifz8`8SK? zm+ij&RCi{&BtdQ(n&bZj(qmB(sArFzA@^%zujomWo!^ zocCw;-m=3d(%$z&VuktdX<=4vZ{!c#v)p#jJik3{d3*BTiepy~+!rdRJvJWs&}BYz^2-*^wZCt?vQ+yvyP8k#ROjlgyIaciZwGDIH+4qo!@uG>e|~5F zPcgB%U%8>JsL*Yn&a9m!^A7!!F*}&Oz@F)4Yg5>)2NQV?J4(EMEwXf5^AFwdJ^Xz} z9=mrP{kQNozkI_Zv(W7pxzge%w_TUDk6T!OIHmsp>kk9AB>sk_n+5(_5 zB-8IPr$#+!{)xv5r(HL?#kbTy%oQtUT6-nG@W(r^U)vTvZoZ_MnYCW6xBq|=+i@+k zgnE`!8Ef^DpZcBqzD?NweUs6P3SPEjIllXZ!yJA+TbN|DvU9#h=XZIHOrO4ntKrWZ zBDIo=3a6f${`Q#b?G{tU%co>J?xr*CU<}>a^V#Q}@lM@5bK|CC>N>W^>gD#7xIYlD kP*&Gfzo~cb@2z)C?dybZ#yu?g0xIr3UHx3vIVCg!0I3qV-2eap diff --git a/services/alchemy_vision/icons/temp.txt b/services/alchemy_vision/icons/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/alchemy_vision/icons/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/alchemy_vision/v1.html b/services/alchemy_vision/v1.html deleted file mode 100644 index c699cb42..00000000 --- a/services/alchemy_vision/v1.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - diff --git a/services/alchemy_vision/v1.js b/services/alchemy_vision/v1.js deleted file mode 100644 index 5fb5ce66..00000000 --- a/services/alchemy_vision/v1.js +++ /dev/null @@ -1,186 +0,0 @@ -/** - * Copyright 2013,2015, 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -// AlchemyAPI Image Analysis functions supported by this node -var FEATURE_RESPONSES = { - imageFaces: 'imageFaces', - imageLink: "image", - imageKeywords: "imageKeywords", - imageText: "sceneTextLines" -}; - - -module.exports = function (RED) { - var cfenv = require('cfenv'); - var watson = require('watson-developer-cloud'); - - var imageType = require('image-type'); - var temp = require('temp'); - var fileType = require('file-type'); - var fs = require('fs'); - - var payloadutils = require('../../utilities/payload-utils'); - - // temp is being used for file streaming to allow the file to arrive so it can be processed. - temp.track(); - - // Require the Cloud Foundry Module to pull credentials from bound service - // If they are found then the api key is stored in the variable s_apikey. - // - // This separation between s_apikey and apikey is to allow - // the end user to modify the key redentials when the service is not bound. - // Otherwise, once set apikey is never reset, resulting in a frustrated - // user who, when he errenously enters bad credentials, can't figure out why - // the edited ones are not being taken. - - // Taking this line out as codacy was complaining about it. - // var services = cfenv.getAppEnv().services, - - var apikey, s_apikey; - - var service = cfenv.getAppEnv().getServiceCreds(/alchemy/i); - - if (service) { - s_apikey = service.apikey; - } - - RED.httpAdmin.get('/alchemy-image-analysis/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - // Utility functions that check for image buffers, urls and stream data in - - function imageCheck(data) { - return data instanceof Buffer && imageType(data) !== null; - }; - - function stream_buffer(file, contents, cb) { - fs.writeFile(file, contents, function (err) { - if (err) throw err; - cb(); - }); - }; - - // Utility function that performs the alchemy vision call. - // the cleanup removes the temp storage, and I am not sure whether - // it should be called here or after alchemy returns and passed - // control back to cbdone. - - function performAction(params, feature, cbdone, cbcleanup) { - var alchemy_vision = watson.alchemy_vision( { api_key: apikey } ); - - if (feature == 'imageFaces') - { - alchemy_vision.recognizeFaces(params, cbdone); - } else if (feature == 'imageLink') { - alchemy_vision.getImageLinks(params, cbdone); - } else if (feature == 'imageKeywords') { - alchemy_vision.getImageKeywords(params, cbdone); - } else if (feature == 'imageText') { - alchemy_vision.getImageSceneText(params, cbdone); - } - - if (cbcleanup) cbcleanup(); - } - - - // This is the Alchemy Image Node - - function AlchemyImageAnalysisNode (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - this.status({fill:'red', shape:'ring', text:'missing payload'}); - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - // If it is present the newly provided user entered key takes precedence over the existing one. - apikey = s_apikey || this.credentials.apikey; - this.status({}); - - if (!apikey) { - this.status({fill:'red', shape:'ring', text:'missing credentials'}); - var message ='Missing Alchemy API service credentials'; - node.error(message, msg); - return; - } - - // Check which single feature has been requested. - var feature = config["image-feature"]; - - // Splice in the additional options from msg.alchemy_options - // eg. The user may have entered msg.alchemy_options = {knowledgeGraph: 1}; - var params = {}; - - for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; } - - // This is the callback after the call to the alchemy service. - // Set up as a var within this scope, so it has access to node, msg etc. - // in preparation for the Alchemy service action - var actionComplete = function(err, keywords) { - if (err || keywords.status === 'ERROR') { - node.status({fill:'red', shape:'ring', text:'call to alchmeyapi vision service failed'}); - console.log('Error:', msg, err); - node.error(err, msg); - } - else { - msg.result = keywords[FEATURE_RESPONSES[feature]] || []; - msg.fullresult = {}; - msg.fullresult['all'] = keywords; - node.send(msg); - } - } - - // If the input is an image, need to stream the input in, giving time for the - // data to arrive, before invoking the service. - if (imageCheck(msg.payload)) { - temp.open({suffix: '.' + fileType(msg.payload).ext}, function (err, info) { - if (err) { - this.status({fill:'red', shape:'ring', text:'unable to open image stream'}); - var message ='Node has been unable to open the image stream'; - node.error(message, msg); - return; - } - - stream_buffer(info.path, msg.payload, function () { - params['image'] = fs.createReadStream(info.path); - performAction(params, feature, actionComplete, temp.cleanup); - }); - - }); - } else if (payloadutils.urlCheck(msg.payload)) { - params['url'] = msg.payload; - performAction(params, feature, actionComplete); - } else { - this.status({fill:'red', shape:'ring', text:'payload is invalid'}); - var message ='Payload must be either an image buffer or a string representing a url'; - node.error(message, msg); - return; - } - - }); - } - - RED.nodes.registerType('alchemy-image-analysis', AlchemyImageAnalysisNode, { - credentials: { - apikey: {type:"password"} - } - }); -}; From 1f54d25d6e64df93886c114d760c7266c9b21f89 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:34:01 +0000 Subject: [PATCH 04/11] Remove redundant nodes --- services/concept_expansion/icons/temp.txt | 17 - services/concept_expansion/temp.txt | 17 - .../icons/ConceptInsights.png | Bin 1152 -> 0 bytes services/concept_insights/v2.html | 445 ----------- services/concept_insights/v2.js | 423 ---------- services/discovery/discovery-utils.js | 384 --------- services/discovery/icons/discovery.png | Bin 630 -> 0 bytes services/discovery/v1-document-loader.html | 138 ---- services/discovery/v1-document-loader.js | 250 ------ services/discovery/v1-exp.html | 216 ----- services/discovery/v1-exp.js | 164 ---- services/discovery/v1-query-builder.html | 738 ------------------ services/discovery/v1-query-builder.js | 133 ---- services/discovery/v1.html | 546 ------------- services/discovery/v1.js | 423 ---------- 15 files changed, 3894 deletions(-) delete mode 100644 services/concept_expansion/icons/temp.txt delete mode 100644 services/concept_expansion/temp.txt delete mode 100644 services/concept_insights/icons/ConceptInsights.png delete mode 100644 services/concept_insights/v2.html delete mode 100644 services/concept_insights/v2.js delete mode 100644 services/discovery/discovery-utils.js delete mode 100644 services/discovery/icons/discovery.png delete mode 100644 services/discovery/v1-document-loader.html delete mode 100644 services/discovery/v1-document-loader.js delete mode 100644 services/discovery/v1-exp.html delete mode 100644 services/discovery/v1-exp.js delete mode 100644 services/discovery/v1-query-builder.html delete mode 100644 services/discovery/v1-query-builder.js delete mode 100644 services/discovery/v1.html delete mode 100644 services/discovery/v1.js diff --git a/services/concept_expansion/icons/temp.txt b/services/concept_expansion/icons/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/concept_expansion/icons/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/concept_expansion/temp.txt b/services/concept_expansion/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/concept_expansion/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/concept_insights/icons/ConceptInsights.png b/services/concept_insights/icons/ConceptInsights.png deleted file mode 100644 index d42a61c9a5e87e273e08a476106cd8273344f65a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1152 zcmeAS@N?(olHy`uVBq!ia0vp^B0wy_!3HG7B;uuk6id3JuOkD)#(wTUiL5}rLb6AY zF9SoB8UsT^3j@P1pisjL28L1t28LG&3=CE?7#PG0=Ijcz0ZMQdctjR6Fz6|RFk{71 z`!WUw#?zT05hW46K32*3xq68y`AMmI6}bgK)eHl#hD=EpgRf_NpP;kyKN>wn`Gto0pvg1-vP_QXVNwW%aaf50H@@$ndN=gc> z^!3Zj%k|2Q_413-^$jg8E%gnI^o@*kfhu&1EAvVcD|GXUl_7?}%yCIAPA&<7|MYTR9h{CYIzEh2-bw*g1m2TER0nF+DXX zH8G{qMju@TRI`mf$h%11hlDLy6d1U6TtJ<$h_d6_q+Iurfq_Zh)5S5wLNIjl?rc#< zk@oWUzK@iJj!3X@ALUTYRFdFX!m-SQ>!6qP{Eh`-Nedr5j^D7&XQf%vhnq(-x*{SX zIg*6AMUNcgU^{BF=kfQm=VHv+_x+t){O!!lxpQYO@(^>+4u=6NmiFS{(|0z>Rm(I^^j1_MGgnu!7o1DM!|8K!7`wQ4V`c^Ew zCD3~`qkQ$%s@7|{(-s)}^<17{!?9m7KE!vM!1)7TquwceEWhwa_m;TC8Ph<|E%xH~ zpFXX>-u+)jFS6rZqw9sbaG`sPYjc#ZqsSBzPrpkH0*L$?S=^OL8 zr8O^m`p;f_qxx@I$c4`P6aOUsxo$A?k>a1<1*%8u9CA92-Te0=!P_8ZV%z()Qq_8y z|GX7kHRVEj>i2goJDI;=ZHUmdi^~gm-E`JT?|f{)FDE;FAA@i}uG%@)6}Net9Cxtx zAK=}|>z*+C?8U_&gg>n+I4tw#-17edrHeoGG4Fb?AV=iuWB-GRH(2Epcw<)mFK2yZ z@BZE@`nT4^4nxa+-}Wp$>5pX=tn(eCSF2QbZ+RNgoy=Um - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/concept_insights/v2.js b/services/concept_insights/v2.js deleted file mode 100644 index f5b62ff5..00000000 --- a/services/concept_insights/v2.js +++ /dev/null @@ -1,423 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'); - var watson = require('watson-developer-cloud'); - - var username, password; - var service = cfenv.getAppEnv().getServiceCreds(/concept insights/i); - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-concept-insights/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function CorpusConfigurationNode(config) { - RED.nodes.createNode(this,config); - this.cname = config.cname; - this.access = config.access; - this.publiccorpus = config.publiccorpus; - } - - RED.nodes.registerType("watson-concept-insights-corpus", CorpusConfigurationNode); - - function searchNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupConceptInsightsNode(msg,config,this,function(concept_insights,account_id) { - this.corpus = RED.nodes.getNode(config.corpus); - - if (this.corpus) { - var corpus_name; - if (this.corpus.cname) { - corpus_name = this.corpus.cname; - } else { - corpus_name = this.corpus.publiccorpus; - account_id = 'public'; - } - var document_name = config.docname; - - node.status({fill:"blue",shape:"ring",text:"requesting..."}); - - //Check for document or corpus mode - if (config.mode === 'document') { - - if (!document_name) { - node.status({}); - var message = 'No document name specified'; - return node.error(message, msg); - } - - var params = { - id: '/corpora/'+account_id+'/'+corpus_name+'/documents/'+document_name - } - - switch (config.docapicall) { - case 'annotations': - params.id = params.id+'/annotations'; - concept_insights.corpora.getDocumentAnnotations(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - - case 'relatedconcepts': - concept_insights.corpora.getRelatedConcepts(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - - case 'relationscores': - params.concepts = msg.concepts; - concept_insights.corpora.getRelationScores(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - } - } else { - //Corpus mode - params = { - corpus: '/corpora/'+account_id+'/'+corpus_name - } - switch (config.corpusapicall) { - case 'statistics': - concept_insights.corpora.getCorpusStats(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - - case 'relatedconcepts': - concept_insights.corpora.getRelatedConcepts(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - - case 'relationscores': - params.concepts = msg.concepts; - concept_insights.corpora.getRelationScores(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - break; - - case 'conceptualsearch': - if (msg.concepts) { - params.ids = msg.concepts; - concept_insights.corpora.getRelatedDocuments(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - } else { - node.status({}); - var message = 'No concepts exist on the msg object'; - node.error(message, msg); - } - break; - - case 'documentlabel': - - if (params.query) { - params.prefix=true; - params.query=config.query; - concept_insights.corpora.searchByLabel(params, function(err,res) { - handleWatsonCallback(node,msg,err,res); - }); - } else { - node.status({}); - message = 'No query term specified'; - node.error(message, msg); - } - break; - - default: - return; - } - } - } else { - message = 'No corpus configuration specified'; - return node.error(message, msg); - } - }); - }); - } - - RED.nodes.registerType('watson-concept-insights-search', searchNode, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); - - function searchConceptsNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupConceptInsightsNode(msg,config,this,function(concept_insights,account_id) { - - //Set up parameters, searching the latest wikipedia graph - if (!msg.payload || typeof(msg.payload) != 'string') { - var message = "No query term specified"; - return node.error(message, msg); - } - var params = { - graph: '/graphs/wikipedia/en-latest', - query: msg.payload, - prefix: true, - concept_fields: '{"link":1}' - } - node.status({fill:"blue",shape:"ring",text:"requesting..."}); - concept_insights.graphs.searchConceptByLabel(params, function(err, res) { - node.status({}); - if (err) { - var message = err.error; - return node.error(message, msg); - } else { - - //Build up array of concept ids to attach to msg.concepts - var concepts = []; - var matches = res.matches; - for (var i=0; i 0) interval = (2*fileLength) + 5; - - //Loop and check the status of the document - var statusInterval = setInterval(function(){ - concept_insights.corpora.getDocumentProcessingState(params, function(err,res) { - if (err) { - node.status({}); - var message = "Document processing state error: "+err.error; - clearInterval(statusInterval); - return node.error(message, msg); - } else { - //get status - if (res.status == 'ready') { - node.status({fill:"green",shape:"ring",text:"Document ready"}); - return clearInterval(statusInterval); - } - } - }); - },interval); - } - }); - }); - } - - RED.nodes.registerType('watson-concept-insights-upload-document', uploadDocumentNode, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); - - function setupConceptInsightsNode(msg,config,node,callback) { - - //Check for payload - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg) - return; - } - - //Check credentials - username = username || node.credentials.username; - password = password || node.credentials.password; - - if (!username || !password) { - message = 'Missing Concept Insights service credentials'; - return node.error(message, msg); - } - - //Connect to Watson - var concept_insights = watson.concept_insights({ - username: username, - password: password, - version: 'v2' - }); - - node.status({fill:"blue",shape:"ring",text:"Getting account information"}); - concept_insights.accounts.getAccountsInfo({},function(err,res) { - node.status({}); - if (err) { - var message = err.error; - return node.error(message, msg); - } else { - var account_id = res.accounts[0].account_id; - if (callback) callback(concept_insights,account_id); - } - }); - } - - function handleWatsonCallback(node,msg,err,res) { - node.status({}); - if (err) { - var message = err.error; - return node.error(message, msg); - } else { - msg.payload = res; - node.send(msg); - } - } -}; - - diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js deleted file mode 100644 index 0a5e2fd1..00000000 --- a/services/discovery/discovery-utils.js +++ /dev/null @@ -1,384 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ -const pkg = require('../../package.json'), - DiscoveryV1 = require('ibm-watson/discovery/v1'), - { IamAuthenticator } = require('ibm-watson/auth'); - - -function DiscoveryUtils() {} -DiscoveryUtils.prototype = { - - buildService: function(username, password, apikey, endpoint) { - let authSettings = {}; - let serviceSettings = { - version: '2019-04-30', - headers: { - 'User-Agent': pkg.name + '-' + pkg.version - } - }; - - if (apikey) { - authSettings.apikey = apikey; - } else { - authSettings.username = username; - authSettings.password = password; - } - serviceSettings.authenticator = new IamAuthenticator(authSettings); - - if (endpoint) { - serviceSettings.url = endpoint; - } - - return new DiscoveryV1(serviceSettings); - - }, - - buildParamsForName: function(msg, config, params) { - if (msg.discoveryparams && msg.discoveryparams.environmentname) { - params.name = msg.discoveryparams.environmentname; - } else if (config.environmentname) { - params.name = config.environmentname; - } else if (msg.discoveryparams && msg.discoveryparams.configurationname) { - params.name = msg.discoveryparams.configurationname; - } else if (config.configurationname) { - params.name = config.configurationname; - } else if (msg.discoveryparams && msg.discoveryparams.collection_name) { - params.name = msg.discoveryparams.collection_name; - } else if (config.collection_name) { - params.name = config.collection_name; - } - return params; - }, - - buildParamsForQuery: function(msg, config, params) { - var sourceField = 'query', - targetField = 'query'; - - if (config.nlp_query || (msg.discoveryparams && msg.discoveryparams.nlp_query)) { - targetField = 'naturalLanguageQuery'; - } - 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); - - // Payload (text to be analysed) must be a string (content is either raw string or Buffer) - if (typeof msg.payload === 'string' || isJSON) { - params.file = this.isJsonObject(msg.payload) ? - JSON.stringify(msg.payload) : - msg.payload; - params.fileContentType = 'application/json'; - } - return params; - }, - - buildParamsFor: function(msg, config, params, field) { - if (msg.discoveryparams && msg.discoveryparams[field]) { - params[field] = msg.discoveryparams[field]; - } else if (config[field]) { - params[field] = config[field]; - } - return params; - }, - - buildParamsForPassages: function (me, msg, config, params) { - let passagesFound = false; - - // Allow the passages parameters to be passed in three ways - // 1. As the API was expecting (watson-developer-cloud) - ['passages.fields', 'passages.count', 'passages.characters' - ].forEach(function(f) { - params = me.buildParamsFor(msg, config, params, f); - passagesFound = true; - }); - - // 2. As anyone misreading the documentation might do it. - // (again watson-developer-cloud) - if (msg.discoveryparams && msg.discoveryparams.passages) { - passagesFound = true; - ['fields', 'count', 'characters' - ].forEach(function(f) { - if (msg.discoveryparams.passages[f]) { - params['passages.' + f] = msg.discoveryparams.passages[f]; - } - }); - } - - // 3. As the ibm-watson SDK expects - ['passagesFields', 'passagesCount', 'passagesCharacters' - ].forEach(function(f) { - params = me.buildParamsFor(msg, config, params, f); - passagesFound = true; - }); - - if (passagesFound) { - // Perform autocorrect for watson-developer-cloud to ibm-watson - // differences - ['passages.fields', 'passages.count', 'passages.characters' - ].forEach(function(f) { - if (params[f]) { - let parts = f.split("."); - let secondPart = parts[1] - let reformedField = parts[0] + secondPart[0].toUpperCase() + secondPart.slice(1); - params[reformedField] = params[f]; - } - }); - params.passages = true; - } - - return params; - }, - - buildParamsFromConfig: function(config, params, field) { - if (config[field]) { - params[field] = config[field]; - } - return params; - }, - - // The field to create a new language collection is language, but - // the SDK creates a language_code field which it defaults to 'en-us' - languageCodeFix: function(params) { - if (params.language_code) { - params.language = params.language_code; - } - return params; - }, - - buildParams: function(msg, config) { - var params = {}, - me = this; - - params = me.buildParamsForName(msg, config, params); - params = me.buildParamsForQuery(msg, config, params); - - ['environmentId', 'collectionId', 'configurationId', - 'collection_name', 'language_code', - 'passages', 'description', 'size', 'filename', - 'highlight' - ].forEach(function(f) { - params = me.buildParamsFor(msg, config, params, f); - }); - - params = me.buildParamsForPassages(me, msg, config, params); - - ['count', 'filter', 'aggregation', 'return'].forEach(function(f) { - params = me.buildParamsFromConfig(config, params, f); - }); - - params = me.languageCodeFix(params); - - params = me.buildParamsForPayload(msg, config, params); - - return params; - }, - - buildMsgOverrides: function(msg, config) { - var params = {}; - if (config.environment) { - params.environmentId = config.environment; - } - if (config.collection) { - params.collectionId = config.collection; - } - if (config.passages) { - params.passages = config.passages; - } - if (config.collection) { - params.filename = config.filename; - } - - 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 = this.buildStructuredQuery(msg, config, params); - } - return params; - }, - - buildStructuredQuery: function(msg, config, params) { - if (config.query1 && config.queryvalue1) { - params.query = config.query1 + ':"' + config.queryvalue1 + '"'; - } - if (config.query2 && config.queryvalue2) { - if (params.query) { - params.query += ','; - } - params.query += config.query2 + ':"' + config.queryvalue2 + '"'; - } - if (config.query3 && config.queryvalue3) { - if (params.query) { - params.query += ','; - } - params.query += config.query3 + ':"' + config.queryvalue3 + '"'; - } - return params; - }, - - - paramEnvCheck: function(params) { - var response = ''; - if (!params.environmentId) { - response = 'Missing Environment ID '; - } - return response; - }, - - paramJSONCheck: function(params) { - var response = ''; - if (!params.file) { - response = 'Missing JSON file on payload'; - } - return response; - }, - - paramDocumentCheck: function(params) { - var response = ''; - if (!params.file) { - response = 'Missing document file on payload'; - } - return response; - }, - - paramNameCheck: function(params) { - var response = ''; - if (!params.name) { - response = 'Missing Name '; - } - return response; - }, - - paramDescriptionCheck: function(params) { - var response = ''; - if (!params.description) { - response = 'Missing Description '; - } - return response; - }, - - paramCollectionCheck: function(params) { - var response = ''; - if (!params.collectionId) { - response = 'Missing Collection ID '; - } - return response; - }, - - paramConfigurationCheck: function(params) { - var response = ''; - if (!params.configurationId) { - response = 'Missing Configuration ID '; - } - return response; - }, - - // Looking for Text, Type and label - buildFieldByStep: function(d, fields, txt) { - for (var k in d) { - var t = txt; - if (isNaN(k)) { - t += txt ? '.' : ''; - t += k; - } - - if ('object' === typeof d[k]) { - fields = this.buildFieldByStep(d[k], fields, t); - } else { - switch (k) { - case 'text': - case 'type': - case 'label': - fields.push(t); - break; - } - } - } - return fields; - }, - - // sorting functions - uniqueFilter: function(value, index, self) { - return self.indexOf(value) === index; - }, - - // Looking for Text, Type and label - buildFieldList: function(schemaData) { - var fields = []; - - if (schemaData && - 'object' === typeof schemaData && - schemaData.result && - 'object' === typeof schemaData.result && - schemaData.result['fields'] && - Array.isArray(schemaData.result['fields'])) { - schemaData.result['fields'].forEach((f) => { - if (f['field'] && f['type'] && 'nested' !== f['type']) { - fields.push(f['field']); - } - }); - } - - if (fields.length) { - fields = fields.filter(this.uniqueFilter); - fields.sort(); - } - - return fields; - }, - - // reportError: function (node, msg, message) { - // var messageTxt = message.error ? message.error : message; - // node.status({fill:'red', shape:'dot', text: messageTxt}); - // node.error(message, msg); - // } , - - isJsonString: function(str) { - try { - JSON.parse(str); - } catch (e) { - return false; - } - return true; - }, - - isJsonObject: function(str) { - if (str instanceof Array || str instanceof Object || - 'object' === typeof str || Array.isArray(str)) { - return true; - } - return false; - } - - -}; - -var discoveryutils = new DiscoveryUtils(); - -module.exports = discoveryutils; diff --git a/services/discovery/icons/discovery.png b/services/discovery/icons/discovery.png deleted file mode 100644 index b1666923e6fc55edb5403ec2db524da21e708c7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 630 zcmV-+0*U>JP)P000>X1^@s6#OZ}&0006#NklbSUDUH zB^HY*v)N45>vih;`eA_SVr?`Upin4?=Yzq39b~asFebHFERas8A(P2K zC=??0X*?c7DwP6*!Eo`Z)oR#ox6B~%c$`Si<#M4?sesGnBK)yf45U)&rK?CJf(y8g z>G%80AUqzA2n+-Q#G23NLo^!2cBj)JItm7ZL~J-5rh}|jDL95lmw!`6o(}APymC>A`qjfSGjfl#M z#Uc@-R4Q3PghC-5WW8R~D)sq%7h5Ki;VC+=o6RQfRFxfpy z?(ukFxm?1nymSpCdPydeV7J@x_eVFO*XzY&jF@}3+u@DA*8P4D|K1PD54%oNUu0G} Q3jhEB07*qoM6N<$f+5H)pa1{> diff --git a/services/discovery/v1-document-loader.html b/services/discovery/v1-document-loader.html deleted file mode 100644 index cf6e942a..00000000 --- a/services/discovery/v1-document-loader.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - diff --git a/services/discovery/v1-document-loader.js b/services/discovery/v1-document-loader.js deleted file mode 100644 index 2182bdb1..00000000 --- a/services/discovery/v1-document-loader.js +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Copyright 20016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - - const SERVICE_IDENTIFIER = 'discovery'; - var fs = require('fs'), - temp = require('temp'), - fileType = require('file-type'), - isDocx = require('is-docx'), - discoveryutils = require('./discovery-utils'), - serviceutils = require('../../utilities/service-utils'), - payloadutils = require('../../utilities/payload-utils'), - dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), - username = null, - password = null, - sUsername = null, - sPassword = null, - apikey = null, - sApikey = null, - endpoint = '', - sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; - - temp.track(); - - function initialCheck(u, p, k) { - var message = ''; - if (!k && (!u || !p)) { - message = 'Missing Watson Discovery service credentials'; - } - if (message) { - return Promise.reject(message); - } - return Promise.resolve(); - } - - function checkParams(params){ - var response = discoveryutils.paramEnvCheck(params) + - discoveryutils.paramCollectionCheck(params); - if (response) { - return Promise.reject(response); - } - return Promise.resolve(); - } - - function verifyPayload(msg) { - if (!msg.payload) { - return Promise.reject('Missing property: msg.payload'); - } else if ( (msg.payload instanceof Buffer) || - (discoveryutils.isJsonObject(msg.payload)) ) { - return Promise.resolve(); - } - return Promise.reject('msg.payload should be a data buffer or json object'); - } - - function determineSuffix(msg) { - // Let's assume that if we can't determine the suffix that - // its a word doc. - let ext = '.json'; - if (! discoveryutils.isJsonObject(msg.payload)) { - let ext = '.json', - ft = fileType(msg.payload); - - if (ft && ft.ext) { - ext = '.' + ft.ext; - } - - if (isDocx(msg.payload)) { - ext = '.docx'; - } - } - - return Promise.resolve(ext); - } - - function openTheFile(suffix) { - var p = new Promise(function resolver(resolve, reject){ - var options = {}; - if (suffix) { - options.suffix = suffix; - } - temp.open(options, function(err, info) { - if (err) { - reject('Error receiving the data buffer'); - } else { - resolve(info); - } - }); - }); - return p; - } - - function syncTheFile(info, msg) { - var p = new Promise(function resolver(resolve, reject){ - fs.writeFile(info.path, msg.payload, function(err) { - if (err) { - reject('Error processing pdf buffer'); - } - resolve(); - }); - }); - return p; - } - - function createStream(info) { - //var theStream = fs.createReadStream(info.path, 'utf8'); - var theStream = fs.readFileSync(info.path, 'utf8'); - return Promise.resolve(theStream); - } - - function whatName(params, suffix){ - if (params.filename) { - return params.filename; - } - return 'Doc ' + (new Date()).toString() + suffix; - } - - function execute(params, msg, suffix) { - var p = new Promise(function resolver(resolve, reject) { - let discovery = discoveryutils.buildService(username, password, apikey, endpoint); - - // modify as getting addJsonDocument will be deprecated messages - if ('.json' === suffix) { - //method = 'addJsonDocument'; - //params.file = JSON.stringify(params.file); - - params.file = Buffer.from(JSON.stringify(params.file)); - //} else { - //method = 'addDocument'; - } - method = 'addDocument'; - - discovery[method](params) - .then((response) => { - msg.document = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - - }); - return p; - } - - if (dservice) { - sUsername = dservice.username ? dservice.username : ''; - sPassword = dservice.password ? dservice.password : ''; - sApikey = dservice.apikey ? dservice.apikey : ''; - sEndpoint = dservice.url ? dservice.url : ''; - } - - RED.httpAdmin.get('/watson-discovery-docs/vcap', function (req, res) { - res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); - }); - - - function Node (config) { - var node = this; - RED.nodes.createNode(this, config); - - this.on('input', function(msg, send, done) { - var message = '', - fileInfo = '', - fileSuffix = '', - params = {}; - - username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password; - apikey = sApikey || this.credentials.apikey; - - endpoint = sEndpoint; - if (config['service-endpoint']) { - endpoint = config['service-endpoint']; - } - - node.status({}); - initialCheck(username, password, apikey) - .then(function(){ - return verifyPayload(msg); - }) - .then(function(){ - params = discoveryutils.buildParams(msg, config); - return checkParams(params); - }) - .then(function(){ - return determineSuffix(msg); - }) - .then(function(suffix) { - fileSuffix = suffix; - node.status({ fill: 'blue', shape: 'dot', text: 'reading' }); - return openTheFile(suffix); - }) - .then(function(info){ - fileInfo = info; - return syncTheFile(fileInfo, msg); - }) - .then(function(){ - return createStream(fileInfo); - }) - .then(function(theStream){ - //params.file = theStream; - //var fname = 'temp' + fileSuffix; - var fname = whatName(params, fileSuffix); - params.file = { - value: theStream, - options: { - filename: fname - } - }; - - node.status({ fill: 'blue', shape: 'dot', text: 'processing' }); - //return Promise.reject('temp disabled'); - return execute(params, msg, fileSuffix); - }) - .then(function(){ - temp.cleanup(); - node.status({}); - send(msg); - done(); - }) - .catch(function(err){ - temp.cleanup(); - let errMsg = payloadutils.reportError(node, msg, err); - done(errMsg); - }); - }); - } - - RED.nodes.registerType('watson-discovery-v1-document-loader', Node, { - credentials: { - username: {type:'text'}, - password: {type:'password'}, - apikey: {type:'password'} - } - }); -}; diff --git a/services/discovery/v1-exp.html b/services/discovery/v1-exp.html deleted file mode 100644 index 0106afb7..00000000 --- a/services/discovery/v1-exp.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - diff --git a/services/discovery/v1-exp.js b/services/discovery/v1-exp.js deleted file mode 100644 index 8a2b6ac2..00000000 --- a/services/discovery/v1-exp.js +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Copyright 20016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - - const SERVICE_IDENTIFIER = 'discovery'; - var discoveryutils = require('./discovery-utils'), - DiscoveryV1Experimental = require('watson-developer-cloud/discovery/v1-experimental'), - serviceutils = require('../../utilities/service-utils'), - dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), - username = null, - password = null, - sUsername = null, - sPassword = null; - - - function checkParams(method, params){ - var response = ''; - switch (method) { - case 'getEnvironmentDetails': - case 'listCollections': - response = discoveryutils.paramEnvCheck(params); - break; - case 'getCollectionDetails': - response = discoveryutils.paramEnvCheck(params) + - discoveryutils.paramCollectionCheck(params); - break; - } - return response; - } - - function executeListEnvrionments(node, discovery, params, msg) { - discovery.getEnvironments(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.environments = response.environments ? response.environments : []; - } - node.send(msg); - }); - } - - function executeEnvrionmentDetails(node, discovery, params, msg) { - discovery.getEnvironment(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.environment_details = response; - } - node.send(msg); - }); - } - - function executeListCollections(node, discovery, params, msg) { - discovery.getCollections(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.collections = response.collections ? response.collections : []; - } - node.send(msg); - }); - } - - function executeGetCollectionDetails(node, discovery, params, msg) { - discovery.getCollection(params, params.collection_id, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.collection_details = response; - } - node.send(msg); - }); - } - - function executeMethod(node, method, params, msg) { - var discovery = new DiscoveryV1Experimental({ - username: username, - password: password, - version_date: '2016-11-07' - }); - - switch (method) { - case 'listEnvrionments': - executeListEnvrionments(node, discovery, params, msg); - break; - case 'getEnvironmentDetails': - executeEnvrionmentDetails(node, discovery, params, msg); - break; - case 'listCollections': - executeListCollections(node, discovery, params, msg); - break; - case 'getCollectionDetails': - executeGetCollectionDetails(node, discovery, params, msg); - break; - } - - } - - if (dservice) { - sUsername = dservice.username; - sPassword = dservice.password; - } - - RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) { - res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); - }); - - - function Node (config) { - var node = this; - RED.nodes.createNode(this, config); - - this.on('input', function (msg) { - var method = config['discovery-method'], - message = '', - params = {}; - - username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password; - - if (!username || !password) { - message = 'Missing Watson Discovery service credentials'; - } else if (!method || '' === method) { - message = 'Required Discovery method has not been specified'; - } else { - params = discoveryutils.buildParams(msg,config); - message = checkParams(method, params); - } - - if (message) { - discoveryutils.reportError(node,msg,message); - return; - } - - node.status({fill:'blue', shape:'dot', text:'requesting'}); - executeMethod(node, method, params, msg); - }); - } - - RED.nodes.registerType('watson-discovery', Node, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); -}; diff --git a/services/discovery/v1-query-builder.html b/services/discovery/v1-query-builder.html deleted file mode 100644 index 902c5225..00000000 --- a/services/discovery/v1-query-builder.html +++ /dev/null @@ -1,738 +0,0 @@ - - - - - - - diff --git a/services/discovery/v1-query-builder.js b/services/discovery/v1-query-builder.js deleted file mode 100644 index ec4933ff..00000000 --- a/services/discovery/v1-query-builder.js +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Copyright 20016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - - const SERVICE_IDENTIFIER = 'discovery'; - var discoveryutils = require('./discovery-utils'), - serviceutils = require('../../utilities/service-utils'), - dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), - sUsername = null, - sPassword = null, - sApikey = null, - sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; - - - if (dservice) { - sUsername = dservice.username ? dservice.username : ''; - sPassword = dservice.password ? dservice.password : ''; - sApikey = dservice.apikey ? dservice.apikey : ''; - sEndpoint = dservice.url ? dservice.url : ''; - } - - RED.httpAdmin.get('/watson-discovery-v1-query-builder/vcap', function(req, res) { - res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); - }); - - function processResponse(response, field) { - let reply = response; - if (response) { - if (response.result) { - if (response.result[field]) { - reply = response.result[field]; - } else { - reply = response.result; - } - } - } - return reply; - } - - // API used by widget to fetch available environments - RED.httpAdmin.get('/watson-discovery-v1-query-builder/environments', function(req, res) { - - let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, - sPassword ? sPassword : req.query.pwd, - sApikey ? sApikey : req.query.key, - req.query.endpoint ? req.query.endpoint : sEndpoint); - - discovery.listEnvironments({}) - .then((response) => { - res.json(processResponse(response,'environments')); - }) - .catch((err) => { - res.json(err); - }); - }); - - // API used by widget to fetch available collections in environment - RED.httpAdmin.get('/watson-discovery-v1-query-builder/collections', function(req, res) { - let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, - sPassword ? sPassword : req.query.pwd, - sApikey ? sApikey : req.query.key, - req.query.endpoint ? req.query.endpoint : sEndpoint); - - discovery.listCollections({environmentId: req.query.environment_id}) - .then((response) => { - res.json(processResponse(response,'collections')); - }) - .catch((err) => { - res.json(err); - }); - }); - - - // API used by widget to fetch available collections in environment - RED.httpAdmin.get('/watson-discovery-v1-query-builder/schemas', function(req, res) { - let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, - sPassword ? sPassword : req.query.pwd, - sApikey ? sApikey : req.query.key, - req.query.endpoint ? req.query.endpoint : sEndpoint); - - discovery.listCollectionFields({ - environmentId: req.query.environment_id, - collectionId: req.query.collection_id - }) - .then((response) => { - let fieldList = discoveryutils.buildFieldList(response); - res.json(fieldList); - }) - .catch((err) => { - res.json(err); - }); - - }); - - function Node(config) { - var node = this; - RED.nodes.createNode(this, config); - - this.on('input', function(msg) { - // Simply return params for query on msg object - msg.discoveryparams = discoveryutils.buildMsgOverrides(msg, config); - node.send(msg); - }); - } - - RED.nodes.registerType('watson-discovery-v1-query-builder', Node, { - credentials: { - username: { - type: 'text' - }, - password: { - type: 'password' - }, - apikey: { - type: 'password' - } - } - }); -}; diff --git a/services/discovery/v1.html b/services/discovery/v1.html deleted file mode 100644 index d26e6fa2..00000000 --- a/services/discovery/v1.html +++ /dev/null @@ -1,546 +0,0 @@ - - - - - - - diff --git a/services/discovery/v1.js b/services/discovery/v1.js deleted file mode 100644 index 0232bcc6..00000000 --- a/services/discovery/v1.js +++ /dev/null @@ -1,423 +0,0 @@ -/** - * Copyright 2016, 2020 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - - const SERVICE_IDENTIFIER = 'discovery'; - var discoveryutils = require('./discovery-utils'), - serviceutils = require('../../utilities/service-utils'), - payloadutils = require('../../utilities/payload-utils'), - responseutils = require('../../utilities/response-utils'), - dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), - username = null, - password = null, - sUsername = null, - sPassword = null, - apikey = null, - sApikey = null, - endpoint = '', - sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; - -const ExecutionList = { - 'createEnvrionment': executeCreateEnvrionment, - 'listEnvrionments': executeListEnvrionments, - 'getEnvironmentDetails': executeEnvrionmentDetails, - 'createCollection': executeCreateCollection, - 'listCollections': executeListCollections, - 'getCollectionDetails': executeGetCollectionDetails, - 'deleteCollection': executeDeleteCollection, - 'createConfiguration': executeCreateConfiguration, - 'listConfigurations': executeListConfigurations, - 'getConfigurationDetails': executeGetConfigurationDetails, - 'deleteConfiguration': executeDeleteConfiguration, - 'deleteEnvironment': executeDeleteEnvironment, - 'listExpansions': executeListExpansions, - 'listTrainingData': executeListTrainingData, - 'query': executeQuery, - 'queryNotices': executeQueryNotices -}; - - - function checkParams(method, params){ - var response = ''; - switch (method) { - case 'createEnvrionment': - response = discoveryutils.paramNameCheck(params) + - discoveryutils.paramDescriptionCheck(params); - break; - case 'createConfiguration': - response = discoveryutils.paramNameCheck(params) + - discoveryutils.paramEnvCheck(params) + - discoveryutils.paramJSONCheck(params); - break; - case 'getEnvironmentDetails': - case 'listCollections': - response = discoveryutils.paramEnvCheck(params); - break; - case 'getCollectionDetails': - case 'query': - case 'queryNotices': - case 'listExpansions': - case 'listTrainingData': - response = discoveryutils.paramEnvCheck(params) + - discoveryutils.paramCollectionCheck(params); - break; - case 'listConfigurations': - response = discoveryutils.paramEnvCheck(params); - break; - case 'getConfigurationDetails': - response = discoveryutils.paramEnvCheck(params) + - discoveryutils.paramConfigurationCheck(params); - break; - } - if (response) { - return Promise.reject(response); - } else { - return Promise.resolve(); - } - } - - function executeCreateEnvrionment(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.createEnvironment(params) - .then((response) => { - msg.environment = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeListEnvrionments(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.listEnvironments(params) - .then((response) => { - responseutils.parseResponseFor(msg, response, 'environments'); - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeEnvrionmentDetails(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.getEnvironment(params) - .then((response) => { - msg.environment_details = response; - if (response && response.result) { - msg.environment_details = response.result; - } - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeCreateCollection(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - - //params.body = {}; - //['name','description','collection_name' - // 'configuration_id'].forEach(function(f) { - // params.body[f] = params[f]; - // //delete params[f]; - //}); - - discovery.createCollection(params) - .then((response) => { - msg.collection = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeDeleteCollection(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.deleteCollection(params) - .then((response) => { - msg.collection = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeDeleteConfiguration(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.deleteConfiguration(params) - .then((response) => { - msg.configuration = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - - function executeDeleteEnvironment(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.deleteEnvironment(params) - .then((response) => { - msg.environment = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeListCollections(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.listCollections(params) - .then((response) => { - responseutils.parseResponseFor(msg, response, 'collections'); - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeGetCollectionDetails(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.getCollection(params) - .then((response) => { - msg.collection_details = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeListExpansions(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.listExpansions(params) - .then((response) => { - responseutils.parseResponseFor(msg, response, 'expansions'); - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeListTrainingData(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.listTrainingData(params) - .then((response) => { - msg.trainingData = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - - function executeCreateConfiguration(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.createConfiguration(params) - .then((response) => { - msg.configuration = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeListConfigurations(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.listConfigurations(params) - .then((response) => { - responseutils.parseResponseFor(msg, response, 'configurations'); - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeGetConfigurationDetails(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.getConfiguration(params) - .then((response) => { - msg.configuration_details = response.result ? response.result : response; - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeQuery(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.query(params) - .then((response) => { - msg.search_results = response; - if (response && response.result) { - msg.search_results = response.result; - } - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function executeQueryNotices(node, discovery, params, msg) { - var p = new Promise(function resolver(resolve, reject){ - discovery.queryNotices(params) - .then((response) => { - msg.search_results = response; - if (response && response.result) { - msg.search_results = response.result; - } - resolve(); - }) - .catch((err) => { - reject(err); - }); - }); - return p; - } - - function unknownMethod(node, discovery, params, msg) { - return Promise.reject('Unable to process as unknown mode has been specified'); - } - - function executeMethod(node, method, params, msg) { - let discovery = discoveryutils.buildService(username, password, apikey, endpoint); - - let exe = ExecutionList[method]; - if (!exe) { - exe = unknownMethod - } - - return exe(node, discovery, params, msg); - } - - function initialCheck(u, p, k, m) { - var message = ''; - if (!k && (!u || !p)) { - message = 'Missing Watson Discovery service credentials'; - } else if (!m || '' === m) { - message = 'Required Discovery method has not been specified'; - } - if (message){ - return Promise.reject(message); - } - return Promise.resolve(); - } - - if (dservice) { - sUsername = dservice.username ? dservice.username : ''; - sPassword = dservice.password ? dservice.password : ''; - sApikey = dservice.apikey ? dservice.apikey : ''; - sEndpoint = dservice.url ? dservice.url : ''; - } - - RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) { - res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); - }); - - - function Node (config) { - var node = this; - RED.nodes.createNode(this, config); - - this.on('input', function(msg, send, done) { - var method = config['discovery-method'], - message = '', - params = {}; - - username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password; - apikey = sApikey || this.credentials.apikey; - - endpoint = sEndpoint; - if (config['service-endpoint']) { - endpoint = config['service-endpoint']; - } - - node.status({}); - initialCheck(username, password, apikey, method) - .then(function(){ - params = discoveryutils.buildParams(msg,config); - return checkParams(method, params); - }) - .then(function(){ - node.status({fill:'blue', shape:'dot', text:'requesting'}); - return executeMethod(node, method, params, msg); - }) - .then(function(){ - node.status({}); - send(msg); - done(); - }) - .catch(function(err){ - let errMsg = payloadutils.reportError(node, msg, err); - done(errMsg); - }); - }); - } - - RED.nodes.registerType('watson-discovery-v1', Node, { - credentials: { - username: {type:'text'}, - password: {type:'password'}, - apikey: {type:'password'} - } - }); -}; From 47ecfa35fd5ce252d409857c42de4338320e5cf9 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:40:43 +0000 Subject: [PATCH 05/11] undo accidental delete --- services/discovery/discovery-utils.js | 384 +++++++++++ services/discovery/icons/discovery.png | Bin 0 -> 630 bytes services/discovery/v1-document-loader.html | 138 ++++ services/discovery/v1-document-loader.js | 250 +++++++ services/discovery/v1-exp.html | 216 ++++++ services/discovery/v1-exp.js | 164 +++++ services/discovery/v1-query-builder.html | 738 +++++++++++++++++++++ services/discovery/v1-query-builder.js | 133 ++++ services/discovery/v1.html | 546 +++++++++++++++ services/discovery/v1.js | 423 ++++++++++++ 10 files changed, 2992 insertions(+) create mode 100644 services/discovery/discovery-utils.js create mode 100644 services/discovery/icons/discovery.png create mode 100644 services/discovery/v1-document-loader.html create mode 100644 services/discovery/v1-document-loader.js create mode 100644 services/discovery/v1-exp.html create mode 100644 services/discovery/v1-exp.js create mode 100644 services/discovery/v1-query-builder.html create mode 100644 services/discovery/v1-query-builder.js create mode 100644 services/discovery/v1.html create mode 100644 services/discovery/v1.js diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js new file mode 100644 index 00000000..0a5e2fd1 --- /dev/null +++ b/services/discovery/discovery-utils.js @@ -0,0 +1,384 @@ +/** + * Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +const pkg = require('../../package.json'), + DiscoveryV1 = require('ibm-watson/discovery/v1'), + { IamAuthenticator } = require('ibm-watson/auth'); + + +function DiscoveryUtils() {} +DiscoveryUtils.prototype = { + + buildService: function(username, password, apikey, endpoint) { + let authSettings = {}; + let serviceSettings = { + version: '2019-04-30', + headers: { + 'User-Agent': pkg.name + '-' + pkg.version + } + }; + + if (apikey) { + authSettings.apikey = apikey; + } else { + authSettings.username = username; + authSettings.password = password; + } + serviceSettings.authenticator = new IamAuthenticator(authSettings); + + if (endpoint) { + serviceSettings.url = endpoint; + } + + return new DiscoveryV1(serviceSettings); + + }, + + buildParamsForName: function(msg, config, params) { + if (msg.discoveryparams && msg.discoveryparams.environmentname) { + params.name = msg.discoveryparams.environmentname; + } else if (config.environmentname) { + params.name = config.environmentname; + } else if (msg.discoveryparams && msg.discoveryparams.configurationname) { + params.name = msg.discoveryparams.configurationname; + } else if (config.configurationname) { + params.name = config.configurationname; + } else if (msg.discoveryparams && msg.discoveryparams.collection_name) { + params.name = msg.discoveryparams.collection_name; + } else if (config.collection_name) { + params.name = config.collection_name; + } + return params; + }, + + buildParamsForQuery: function(msg, config, params) { + var sourceField = 'query', + targetField = 'query'; + + if (config.nlp_query || (msg.discoveryparams && msg.discoveryparams.nlp_query)) { + targetField = 'naturalLanguageQuery'; + } + 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); + + // Payload (text to be analysed) must be a string (content is either raw string or Buffer) + if (typeof msg.payload === 'string' || isJSON) { + params.file = this.isJsonObject(msg.payload) ? + JSON.stringify(msg.payload) : + msg.payload; + params.fileContentType = 'application/json'; + } + return params; + }, + + buildParamsFor: function(msg, config, params, field) { + if (msg.discoveryparams && msg.discoveryparams[field]) { + params[field] = msg.discoveryparams[field]; + } else if (config[field]) { + params[field] = config[field]; + } + return params; + }, + + buildParamsForPassages: function (me, msg, config, params) { + let passagesFound = false; + + // Allow the passages parameters to be passed in three ways + // 1. As the API was expecting (watson-developer-cloud) + ['passages.fields', 'passages.count', 'passages.characters' + ].forEach(function(f) { + params = me.buildParamsFor(msg, config, params, f); + passagesFound = true; + }); + + // 2. As anyone misreading the documentation might do it. + // (again watson-developer-cloud) + if (msg.discoveryparams && msg.discoveryparams.passages) { + passagesFound = true; + ['fields', 'count', 'characters' + ].forEach(function(f) { + if (msg.discoveryparams.passages[f]) { + params['passages.' + f] = msg.discoveryparams.passages[f]; + } + }); + } + + // 3. As the ibm-watson SDK expects + ['passagesFields', 'passagesCount', 'passagesCharacters' + ].forEach(function(f) { + params = me.buildParamsFor(msg, config, params, f); + passagesFound = true; + }); + + if (passagesFound) { + // Perform autocorrect for watson-developer-cloud to ibm-watson + // differences + ['passages.fields', 'passages.count', 'passages.characters' + ].forEach(function(f) { + if (params[f]) { + let parts = f.split("."); + let secondPart = parts[1] + let reformedField = parts[0] + secondPart[0].toUpperCase() + secondPart.slice(1); + params[reformedField] = params[f]; + } + }); + params.passages = true; + } + + return params; + }, + + buildParamsFromConfig: function(config, params, field) { + if (config[field]) { + params[field] = config[field]; + } + return params; + }, + + // The field to create a new language collection is language, but + // the SDK creates a language_code field which it defaults to 'en-us' + languageCodeFix: function(params) { + if (params.language_code) { + params.language = params.language_code; + } + return params; + }, + + buildParams: function(msg, config) { + var params = {}, + me = this; + + params = me.buildParamsForName(msg, config, params); + params = me.buildParamsForQuery(msg, config, params); + + ['environmentId', 'collectionId', 'configurationId', + 'collection_name', 'language_code', + 'passages', 'description', 'size', 'filename', + 'highlight' + ].forEach(function(f) { + params = me.buildParamsFor(msg, config, params, f); + }); + + params = me.buildParamsForPassages(me, msg, config, params); + + ['count', 'filter', 'aggregation', 'return'].forEach(function(f) { + params = me.buildParamsFromConfig(config, params, f); + }); + + params = me.languageCodeFix(params); + + params = me.buildParamsForPayload(msg, config, params); + + return params; + }, + + buildMsgOverrides: function(msg, config) { + var params = {}; + if (config.environment) { + params.environmentId = config.environment; + } + if (config.collection) { + params.collectionId = config.collection; + } + if (config.passages) { + params.passages = config.passages; + } + if (config.collection) { + params.filename = config.filename; + } + + 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 = this.buildStructuredQuery(msg, config, params); + } + return params; + }, + + buildStructuredQuery: function(msg, config, params) { + if (config.query1 && config.queryvalue1) { + params.query = config.query1 + ':"' + config.queryvalue1 + '"'; + } + if (config.query2 && config.queryvalue2) { + if (params.query) { + params.query += ','; + } + params.query += config.query2 + ':"' + config.queryvalue2 + '"'; + } + if (config.query3 && config.queryvalue3) { + if (params.query) { + params.query += ','; + } + params.query += config.query3 + ':"' + config.queryvalue3 + '"'; + } + return params; + }, + + + paramEnvCheck: function(params) { + var response = ''; + if (!params.environmentId) { + response = 'Missing Environment ID '; + } + return response; + }, + + paramJSONCheck: function(params) { + var response = ''; + if (!params.file) { + response = 'Missing JSON file on payload'; + } + return response; + }, + + paramDocumentCheck: function(params) { + var response = ''; + if (!params.file) { + response = 'Missing document file on payload'; + } + return response; + }, + + paramNameCheck: function(params) { + var response = ''; + if (!params.name) { + response = 'Missing Name '; + } + return response; + }, + + paramDescriptionCheck: function(params) { + var response = ''; + if (!params.description) { + response = 'Missing Description '; + } + return response; + }, + + paramCollectionCheck: function(params) { + var response = ''; + if (!params.collectionId) { + response = 'Missing Collection ID '; + } + return response; + }, + + paramConfigurationCheck: function(params) { + var response = ''; + if (!params.configurationId) { + response = 'Missing Configuration ID '; + } + return response; + }, + + // Looking for Text, Type and label + buildFieldByStep: function(d, fields, txt) { + for (var k in d) { + var t = txt; + if (isNaN(k)) { + t += txt ? '.' : ''; + t += k; + } + + if ('object' === typeof d[k]) { + fields = this.buildFieldByStep(d[k], fields, t); + } else { + switch (k) { + case 'text': + case 'type': + case 'label': + fields.push(t); + break; + } + } + } + return fields; + }, + + // sorting functions + uniqueFilter: function(value, index, self) { + return self.indexOf(value) === index; + }, + + // Looking for Text, Type and label + buildFieldList: function(schemaData) { + var fields = []; + + if (schemaData && + 'object' === typeof schemaData && + schemaData.result && + 'object' === typeof schemaData.result && + schemaData.result['fields'] && + Array.isArray(schemaData.result['fields'])) { + schemaData.result['fields'].forEach((f) => { + if (f['field'] && f['type'] && 'nested' !== f['type']) { + fields.push(f['field']); + } + }); + } + + if (fields.length) { + fields = fields.filter(this.uniqueFilter); + fields.sort(); + } + + return fields; + }, + + // reportError: function (node, msg, message) { + // var messageTxt = message.error ? message.error : message; + // node.status({fill:'red', shape:'dot', text: messageTxt}); + // node.error(message, msg); + // } , + + isJsonString: function(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; + }, + + isJsonObject: function(str) { + if (str instanceof Array || str instanceof Object || + 'object' === typeof str || Array.isArray(str)) { + return true; + } + return false; + } + + +}; + +var discoveryutils = new DiscoveryUtils(); + +module.exports = discoveryutils; diff --git a/services/discovery/icons/discovery.png b/services/discovery/icons/discovery.png new file mode 100644 index 0000000000000000000000000000000000000000..b1666923e6fc55edb5403ec2db524da21e708c7a GIT binary patch literal 630 zcmV-+0*U>JP)P000>X1^@s6#OZ}&0006#NklbSUDUH zB^HY*v)N45>vih;`eA_SVr?`Upin4?=Yzq39b~asFebHFERas8A(P2K zC=??0X*?c7DwP6*!Eo`Z)oR#ox6B~%c$`Si<#M4?sesGnBK)yf45U)&rK?CJf(y8g z>G%80AUqzA2n+-Q#G23NLo^!2cBj)JItm7ZL~J-5rh}|jDL95lmw!`6o(}APymC>A`qjfSGjfl#M z#Uc@-R4Q3PghC-5WW8R~D)sq%7h5Ki;VC+=o6RQfRFxfpy z?(ukFxm?1nymSpCdPydeV7J@x_eVFO*XzY&jF@}3+u@DA*8P4D|K1PD54%oNUu0G} Q3jhEB07*qoM6N<$f+5H)pa1{> literal 0 HcmV?d00001 diff --git a/services/discovery/v1-document-loader.html b/services/discovery/v1-document-loader.html new file mode 100644 index 00000000..cf6e942a --- /dev/null +++ b/services/discovery/v1-document-loader.html @@ -0,0 +1,138 @@ + + + + + + + diff --git a/services/discovery/v1-document-loader.js b/services/discovery/v1-document-loader.js new file mode 100644 index 00000000..2182bdb1 --- /dev/null +++ b/services/discovery/v1-document-loader.js @@ -0,0 +1,250 @@ +/** + * Copyright 20016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function (RED) { + + const SERVICE_IDENTIFIER = 'discovery'; + var fs = require('fs'), + temp = require('temp'), + fileType = require('file-type'), + isDocx = require('is-docx'), + discoveryutils = require('./discovery-utils'), + serviceutils = require('../../utilities/service-utils'), + payloadutils = require('../../utilities/payload-utils'), + dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), + username = null, + password = null, + sUsername = null, + sPassword = null, + apikey = null, + sApikey = null, + endpoint = '', + sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; + + temp.track(); + + function initialCheck(u, p, k) { + var message = ''; + if (!k && (!u || !p)) { + message = 'Missing Watson Discovery service credentials'; + } + if (message) { + return Promise.reject(message); + } + return Promise.resolve(); + } + + function checkParams(params){ + var response = discoveryutils.paramEnvCheck(params) + + discoveryutils.paramCollectionCheck(params); + if (response) { + return Promise.reject(response); + } + return Promise.resolve(); + } + + function verifyPayload(msg) { + if (!msg.payload) { + return Promise.reject('Missing property: msg.payload'); + } else if ( (msg.payload instanceof Buffer) || + (discoveryutils.isJsonObject(msg.payload)) ) { + return Promise.resolve(); + } + return Promise.reject('msg.payload should be a data buffer or json object'); + } + + function determineSuffix(msg) { + // Let's assume that if we can't determine the suffix that + // its a word doc. + let ext = '.json'; + if (! discoveryutils.isJsonObject(msg.payload)) { + let ext = '.json', + ft = fileType(msg.payload); + + if (ft && ft.ext) { + ext = '.' + ft.ext; + } + + if (isDocx(msg.payload)) { + ext = '.docx'; + } + } + + return Promise.resolve(ext); + } + + function openTheFile(suffix) { + var p = new Promise(function resolver(resolve, reject){ + var options = {}; + if (suffix) { + options.suffix = suffix; + } + temp.open(options, function(err, info) { + if (err) { + reject('Error receiving the data buffer'); + } else { + resolve(info); + } + }); + }); + return p; + } + + function syncTheFile(info, msg) { + var p = new Promise(function resolver(resolve, reject){ + fs.writeFile(info.path, msg.payload, function(err) { + if (err) { + reject('Error processing pdf buffer'); + } + resolve(); + }); + }); + return p; + } + + function createStream(info) { + //var theStream = fs.createReadStream(info.path, 'utf8'); + var theStream = fs.readFileSync(info.path, 'utf8'); + return Promise.resolve(theStream); + } + + function whatName(params, suffix){ + if (params.filename) { + return params.filename; + } + return 'Doc ' + (new Date()).toString() + suffix; + } + + function execute(params, msg, suffix) { + var p = new Promise(function resolver(resolve, reject) { + let discovery = discoveryutils.buildService(username, password, apikey, endpoint); + + // modify as getting addJsonDocument will be deprecated messages + if ('.json' === suffix) { + //method = 'addJsonDocument'; + //params.file = JSON.stringify(params.file); + + params.file = Buffer.from(JSON.stringify(params.file)); + //} else { + //method = 'addDocument'; + } + method = 'addDocument'; + + discovery[method](params) + .then((response) => { + msg.document = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + + }); + return p; + } + + if (dservice) { + sUsername = dservice.username ? dservice.username : ''; + sPassword = dservice.password ? dservice.password : ''; + sApikey = dservice.apikey ? dservice.apikey : ''; + sEndpoint = dservice.url ? dservice.url : ''; + } + + RED.httpAdmin.get('/watson-discovery-docs/vcap', function (req, res) { + res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); + }); + + + function Node (config) { + var node = this; + RED.nodes.createNode(this, config); + + this.on('input', function(msg, send, done) { + var message = '', + fileInfo = '', + fileSuffix = '', + params = {}; + + username = sUsername || this.credentials.username; + password = sPassword || this.credentials.password; + apikey = sApikey || this.credentials.apikey; + + endpoint = sEndpoint; + if (config['service-endpoint']) { + endpoint = config['service-endpoint']; + } + + node.status({}); + initialCheck(username, password, apikey) + .then(function(){ + return verifyPayload(msg); + }) + .then(function(){ + params = discoveryutils.buildParams(msg, config); + return checkParams(params); + }) + .then(function(){ + return determineSuffix(msg); + }) + .then(function(suffix) { + fileSuffix = suffix; + node.status({ fill: 'blue', shape: 'dot', text: 'reading' }); + return openTheFile(suffix); + }) + .then(function(info){ + fileInfo = info; + return syncTheFile(fileInfo, msg); + }) + .then(function(){ + return createStream(fileInfo); + }) + .then(function(theStream){ + //params.file = theStream; + //var fname = 'temp' + fileSuffix; + var fname = whatName(params, fileSuffix); + params.file = { + value: theStream, + options: { + filename: fname + } + }; + + node.status({ fill: 'blue', shape: 'dot', text: 'processing' }); + //return Promise.reject('temp disabled'); + return execute(params, msg, fileSuffix); + }) + .then(function(){ + temp.cleanup(); + node.status({}); + send(msg); + done(); + }) + .catch(function(err){ + temp.cleanup(); + let errMsg = payloadutils.reportError(node, msg, err); + done(errMsg); + }); + }); + } + + RED.nodes.registerType('watson-discovery-v1-document-loader', Node, { + credentials: { + username: {type:'text'}, + password: {type:'password'}, + apikey: {type:'password'} + } + }); +}; diff --git a/services/discovery/v1-exp.html b/services/discovery/v1-exp.html new file mode 100644 index 00000000..0106afb7 --- /dev/null +++ b/services/discovery/v1-exp.html @@ -0,0 +1,216 @@ + + + + + + + diff --git a/services/discovery/v1-exp.js b/services/discovery/v1-exp.js new file mode 100644 index 00000000..8a2b6ac2 --- /dev/null +++ b/services/discovery/v1-exp.js @@ -0,0 +1,164 @@ +/** + * Copyright 20016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function (RED) { + + const SERVICE_IDENTIFIER = 'discovery'; + var discoveryutils = require('./discovery-utils'), + DiscoveryV1Experimental = require('watson-developer-cloud/discovery/v1-experimental'), + serviceutils = require('../../utilities/service-utils'), + dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), + username = null, + password = null, + sUsername = null, + sPassword = null; + + + function checkParams(method, params){ + var response = ''; + switch (method) { + case 'getEnvironmentDetails': + case 'listCollections': + response = discoveryutils.paramEnvCheck(params); + break; + case 'getCollectionDetails': + response = discoveryutils.paramEnvCheck(params) + + discoveryutils.paramCollectionCheck(params); + break; + } + return response; + } + + function executeListEnvrionments(node, discovery, params, msg) { + discovery.getEnvironments(params, function (err, response) { + node.status({}); + if (err) { + discoveryutils.reportError(node, msg, err.error); + } else { + msg.environments = response.environments ? response.environments : []; + } + node.send(msg); + }); + } + + function executeEnvrionmentDetails(node, discovery, params, msg) { + discovery.getEnvironment(params, function (err, response) { + node.status({}); + if (err) { + discoveryutils.reportError(node, msg, err.error); + } else { + msg.environment_details = response; + } + node.send(msg); + }); + } + + function executeListCollections(node, discovery, params, msg) { + discovery.getCollections(params, function (err, response) { + node.status({}); + if (err) { + discoveryutils.reportError(node, msg, err.error); + } else { + msg.collections = response.collections ? response.collections : []; + } + node.send(msg); + }); + } + + function executeGetCollectionDetails(node, discovery, params, msg) { + discovery.getCollection(params, params.collection_id, function (err, response) { + node.status({}); + if (err) { + discoveryutils.reportError(node, msg, err.error); + } else { + msg.collection_details = response; + } + node.send(msg); + }); + } + + function executeMethod(node, method, params, msg) { + var discovery = new DiscoveryV1Experimental({ + username: username, + password: password, + version_date: '2016-11-07' + }); + + switch (method) { + case 'listEnvrionments': + executeListEnvrionments(node, discovery, params, msg); + break; + case 'getEnvironmentDetails': + executeEnvrionmentDetails(node, discovery, params, msg); + break; + case 'listCollections': + executeListCollections(node, discovery, params, msg); + break; + case 'getCollectionDetails': + executeGetCollectionDetails(node, discovery, params, msg); + break; + } + + } + + if (dservice) { + sUsername = dservice.username; + sPassword = dservice.password; + } + + RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) { + res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); + }); + + + function Node (config) { + var node = this; + RED.nodes.createNode(this, config); + + this.on('input', function (msg) { + var method = config['discovery-method'], + message = '', + params = {}; + + username = sUsername || this.credentials.username; + password = sPassword || this.credentials.password; + + if (!username || !password) { + message = 'Missing Watson Discovery service credentials'; + } else if (!method || '' === method) { + message = 'Required Discovery method has not been specified'; + } else { + params = discoveryutils.buildParams(msg,config); + message = checkParams(method, params); + } + + if (message) { + discoveryutils.reportError(node,msg,message); + return; + } + + node.status({fill:'blue', shape:'dot', text:'requesting'}); + executeMethod(node, method, params, msg); + }); + } + + RED.nodes.registerType('watson-discovery', Node, { + credentials: { + username: {type:'text'}, + password: {type:'password'} + } + }); +}; diff --git a/services/discovery/v1-query-builder.html b/services/discovery/v1-query-builder.html new file mode 100644 index 00000000..902c5225 --- /dev/null +++ b/services/discovery/v1-query-builder.html @@ -0,0 +1,738 @@ + + + + + + + diff --git a/services/discovery/v1-query-builder.js b/services/discovery/v1-query-builder.js new file mode 100644 index 00000000..ec4933ff --- /dev/null +++ b/services/discovery/v1-query-builder.js @@ -0,0 +1,133 @@ +/** + * Copyright 20016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + + const SERVICE_IDENTIFIER = 'discovery'; + var discoveryutils = require('./discovery-utils'), + serviceutils = require('../../utilities/service-utils'), + dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), + sUsername = null, + sPassword = null, + sApikey = null, + sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; + + + if (dservice) { + sUsername = dservice.username ? dservice.username : ''; + sPassword = dservice.password ? dservice.password : ''; + sApikey = dservice.apikey ? dservice.apikey : ''; + sEndpoint = dservice.url ? dservice.url : ''; + } + + RED.httpAdmin.get('/watson-discovery-v1-query-builder/vcap', function(req, res) { + res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); + }); + + function processResponse(response, field) { + let reply = response; + if (response) { + if (response.result) { + if (response.result[field]) { + reply = response.result[field]; + } else { + reply = response.result; + } + } + } + return reply; + } + + // API used by widget to fetch available environments + RED.httpAdmin.get('/watson-discovery-v1-query-builder/environments', function(req, res) { + + let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, + sPassword ? sPassword : req.query.pwd, + sApikey ? sApikey : req.query.key, + req.query.endpoint ? req.query.endpoint : sEndpoint); + + discovery.listEnvironments({}) + .then((response) => { + res.json(processResponse(response,'environments')); + }) + .catch((err) => { + res.json(err); + }); + }); + + // API used by widget to fetch available collections in environment + RED.httpAdmin.get('/watson-discovery-v1-query-builder/collections', function(req, res) { + let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, + sPassword ? sPassword : req.query.pwd, + sApikey ? sApikey : req.query.key, + req.query.endpoint ? req.query.endpoint : sEndpoint); + + discovery.listCollections({environmentId: req.query.environment_id}) + .then((response) => { + res.json(processResponse(response,'collections')); + }) + .catch((err) => { + res.json(err); + }); + }); + + + // API used by widget to fetch available collections in environment + RED.httpAdmin.get('/watson-discovery-v1-query-builder/schemas', function(req, res) { + let discovery = discoveryutils.buildService(sUsername ? sUsername : req.query.un, + sPassword ? sPassword : req.query.pwd, + sApikey ? sApikey : req.query.key, + req.query.endpoint ? req.query.endpoint : sEndpoint); + + discovery.listCollectionFields({ + environmentId: req.query.environment_id, + collectionId: req.query.collection_id + }) + .then((response) => { + let fieldList = discoveryutils.buildFieldList(response); + res.json(fieldList); + }) + .catch((err) => { + res.json(err); + }); + + }); + + function Node(config) { + var node = this; + RED.nodes.createNode(this, config); + + this.on('input', function(msg) { + // Simply return params for query on msg object + msg.discoveryparams = discoveryutils.buildMsgOverrides(msg, config); + node.send(msg); + }); + } + + RED.nodes.registerType('watson-discovery-v1-query-builder', Node, { + credentials: { + username: { + type: 'text' + }, + password: { + type: 'password' + }, + apikey: { + type: 'password' + } + } + }); +}; diff --git a/services/discovery/v1.html b/services/discovery/v1.html new file mode 100644 index 00000000..d26e6fa2 --- /dev/null +++ b/services/discovery/v1.html @@ -0,0 +1,546 @@ + + + + + + + diff --git a/services/discovery/v1.js b/services/discovery/v1.js new file mode 100644 index 00000000..0232bcc6 --- /dev/null +++ b/services/discovery/v1.js @@ -0,0 +1,423 @@ +/** + * Copyright 2016, 2020 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function (RED) { + + const SERVICE_IDENTIFIER = 'discovery'; + var discoveryutils = require('./discovery-utils'), + serviceutils = require('../../utilities/service-utils'), + payloadutils = require('../../utilities/payload-utils'), + responseutils = require('../../utilities/response-utils'), + dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), + username = null, + password = null, + sUsername = null, + sPassword = null, + apikey = null, + sApikey = null, + endpoint = '', + sEndpoint = 'https://gateway.watsonplatform.net/discovery/api'; + +const ExecutionList = { + 'createEnvrionment': executeCreateEnvrionment, + 'listEnvrionments': executeListEnvrionments, + 'getEnvironmentDetails': executeEnvrionmentDetails, + 'createCollection': executeCreateCollection, + 'listCollections': executeListCollections, + 'getCollectionDetails': executeGetCollectionDetails, + 'deleteCollection': executeDeleteCollection, + 'createConfiguration': executeCreateConfiguration, + 'listConfigurations': executeListConfigurations, + 'getConfigurationDetails': executeGetConfigurationDetails, + 'deleteConfiguration': executeDeleteConfiguration, + 'deleteEnvironment': executeDeleteEnvironment, + 'listExpansions': executeListExpansions, + 'listTrainingData': executeListTrainingData, + 'query': executeQuery, + 'queryNotices': executeQueryNotices +}; + + + function checkParams(method, params){ + var response = ''; + switch (method) { + case 'createEnvrionment': + response = discoveryutils.paramNameCheck(params) + + discoveryutils.paramDescriptionCheck(params); + break; + case 'createConfiguration': + response = discoveryutils.paramNameCheck(params) + + discoveryutils.paramEnvCheck(params) + + discoveryutils.paramJSONCheck(params); + break; + case 'getEnvironmentDetails': + case 'listCollections': + response = discoveryutils.paramEnvCheck(params); + break; + case 'getCollectionDetails': + case 'query': + case 'queryNotices': + case 'listExpansions': + case 'listTrainingData': + response = discoveryutils.paramEnvCheck(params) + + discoveryutils.paramCollectionCheck(params); + break; + case 'listConfigurations': + response = discoveryutils.paramEnvCheck(params); + break; + case 'getConfigurationDetails': + response = discoveryutils.paramEnvCheck(params) + + discoveryutils.paramConfigurationCheck(params); + break; + } + if (response) { + return Promise.reject(response); + } else { + return Promise.resolve(); + } + } + + function executeCreateEnvrionment(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.createEnvironment(params) + .then((response) => { + msg.environment = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeListEnvrionments(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.listEnvironments(params) + .then((response) => { + responseutils.parseResponseFor(msg, response, 'environments'); + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeEnvrionmentDetails(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.getEnvironment(params) + .then((response) => { + msg.environment_details = response; + if (response && response.result) { + msg.environment_details = response.result; + } + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeCreateCollection(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + + //params.body = {}; + //['name','description','collection_name' + // 'configuration_id'].forEach(function(f) { + // params.body[f] = params[f]; + // //delete params[f]; + //}); + + discovery.createCollection(params) + .then((response) => { + msg.collection = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeDeleteCollection(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.deleteCollection(params) + .then((response) => { + msg.collection = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeDeleteConfiguration(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.deleteConfiguration(params) + .then((response) => { + msg.configuration = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + + function executeDeleteEnvironment(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.deleteEnvironment(params) + .then((response) => { + msg.environment = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeListCollections(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.listCollections(params) + .then((response) => { + responseutils.parseResponseFor(msg, response, 'collections'); + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeGetCollectionDetails(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.getCollection(params) + .then((response) => { + msg.collection_details = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeListExpansions(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.listExpansions(params) + .then((response) => { + responseutils.parseResponseFor(msg, response, 'expansions'); + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeListTrainingData(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.listTrainingData(params) + .then((response) => { + msg.trainingData = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + + function executeCreateConfiguration(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.createConfiguration(params) + .then((response) => { + msg.configuration = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeListConfigurations(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.listConfigurations(params) + .then((response) => { + responseutils.parseResponseFor(msg, response, 'configurations'); + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeGetConfigurationDetails(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.getConfiguration(params) + .then((response) => { + msg.configuration_details = response.result ? response.result : response; + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeQuery(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.query(params) + .then((response) => { + msg.search_results = response; + if (response && response.result) { + msg.search_results = response.result; + } + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function executeQueryNotices(node, discovery, params, msg) { + var p = new Promise(function resolver(resolve, reject){ + discovery.queryNotices(params) + .then((response) => { + msg.search_results = response; + if (response && response.result) { + msg.search_results = response.result; + } + resolve(); + }) + .catch((err) => { + reject(err); + }); + }); + return p; + } + + function unknownMethod(node, discovery, params, msg) { + return Promise.reject('Unable to process as unknown mode has been specified'); + } + + function executeMethod(node, method, params, msg) { + let discovery = discoveryutils.buildService(username, password, apikey, endpoint); + + let exe = ExecutionList[method]; + if (!exe) { + exe = unknownMethod + } + + return exe(node, discovery, params, msg); + } + + function initialCheck(u, p, k, m) { + var message = ''; + if (!k && (!u || !p)) { + message = 'Missing Watson Discovery service credentials'; + } else if (!m || '' === m) { + message = 'Required Discovery method has not been specified'; + } + if (message){ + return Promise.reject(message); + } + return Promise.resolve(); + } + + if (dservice) { + sUsername = dservice.username ? dservice.username : ''; + sPassword = dservice.password ? dservice.password : ''; + sApikey = dservice.apikey ? dservice.apikey : ''; + sEndpoint = dservice.url ? dservice.url : ''; + } + + RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) { + res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); + }); + + + function Node (config) { + var node = this; + RED.nodes.createNode(this, config); + + this.on('input', function(msg, send, done) { + var method = config['discovery-method'], + message = '', + params = {}; + + username = sUsername || this.credentials.username; + password = sPassword || this.credentials.password; + apikey = sApikey || this.credentials.apikey; + + endpoint = sEndpoint; + if (config['service-endpoint']) { + endpoint = config['service-endpoint']; + } + + node.status({}); + initialCheck(username, password, apikey, method) + .then(function(){ + params = discoveryutils.buildParams(msg,config); + return checkParams(method, params); + }) + .then(function(){ + node.status({fill:'blue', shape:'dot', text:'requesting'}); + return executeMethod(node, method, params, msg); + }) + .then(function(){ + node.status({}); + send(msg); + done(); + }) + .catch(function(err){ + let errMsg = payloadutils.reportError(node, msg, err); + done(errMsg); + }); + }); + } + + RED.nodes.registerType('watson-discovery-v1', Node, { + credentials: { + username: {type:'text'}, + password: {type:'password'}, + apikey: {type:'password'} + } + }); +}; From 1ed0d7458486a8aa646e8c4945ec7489b84cbc48 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:43:10 +0000 Subject: [PATCH 06/11] Remove redundant nodes --- services/dialog/icons/dialog-icon25x25.png | Bin 1329 -> 0 bytes services/dialog/v1.html | 191 ---------- services/dialog/v1.js | 343 ------------------ .../icons/DocumentConversion.png | Bin 2126 -> 0 bytes services/document_conversion/icons/temp.txt | 17 - services/document_conversion/icons/v1.png | Bin 899 -> 0 bytes services/document_conversion/v1.html | 157 -------- services/document_conversion/v1.js | 200 ---------- .../icons/language.png | Bin 435 -> 0 bytes services/language_identification/v1.html | 84 ----- services/language_identification/v1.js | 82 ----- 11 files changed, 1074 deletions(-) delete mode 100644 services/dialog/icons/dialog-icon25x25.png delete mode 100644 services/dialog/v1.html delete mode 100644 services/dialog/v1.js delete mode 100644 services/document_conversion/icons/DocumentConversion.png delete mode 100644 services/document_conversion/icons/temp.txt delete mode 100644 services/document_conversion/icons/v1.png delete mode 100644 services/document_conversion/v1.html delete mode 100644 services/document_conversion/v1.js delete mode 100644 services/language_identification/icons/language.png delete mode 100644 services/language_identification/v1.html delete mode 100644 services/language_identification/v1.js diff --git a/services/dialog/icons/dialog-icon25x25.png b/services/dialog/icons/dialog-icon25x25.png deleted file mode 100644 index 5aa063915c90430a7e856c025f7c2fb7586b038a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1329 zcmV-11P000>X1^@s6#OZ}&000E|Nkl|sa5J4$*dOGj@v9m0&#GQHP&Yt_8^StLg=Y7s{ z+!#-U?f$DVLU))!l+z7@e3ITbV?=o<#;!a!h|-|Ju3R-DTle}1WHdys6N+^lNSe2apoab5)g|+2W(_AQhIvz6;MHq!!Fjw~AyWbum>6<(5 z9Hns)u*TcY)xO5ipFdG$Ubq`vk{(YMdw0}NU9x{1rZ&Rd;k%-Ep(D@%vyUC zQ;g|q1}wwyoO776D8mI1XiP#?Z38w}p2gx_BRh^4l`@WQ^X*|=6m_T|Q3Y3_E51P) z2w1rN0z#7ZV(RkE_+V+43t%d5!v5p+Fj8yld@ ztc1Pc0aotrf}b(X1>h683R$)TNZYXo??%R9p?Mob+PA#S14NJpiId^7!A>8NydP2d zR}h?7hOCMf^geuo>W0h6C@RO2b-4&$l1v~JI3W{$+SMxPCuSS=H$Q~<%L7kdo-^VH z+>LSN3Sze&LAa#>0kPX*C}_pvtbK?~%*2ZHJZ#xjiG##JUGsUARDKV0t_>Rcwlx0~ z(!T9QYv&Wsa`m%vwYwV&e!7q1acp#4p+H+HE~$HHV0dG zA4E;l@3?*MDLQ-p!Jei*4-n}Rb(eC`-S}(AW296$5&Gp}yr)e-MEnNilvbgwqZ7qn zA9I1Yz_ez}w=|8ZXF5T$Q+G)Tq_|I+;Zq{5%`t>zy1m - - - - - - - - diff --git a/services/dialog/v1.js b/services/dialog/v1.js deleted file mode 100644 index b010c954..00000000 --- a/services/dialog/v1.js +++ /dev/null @@ -1,343 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - - var request = require('request'); - var cfenv = require('cfenv'); - var fs = require('fs'); - var temp = require('temp'); - var async = require('async'); - var watson = require('watson-developer-cloud'); - temp.track(); - - // Require the Cloud Foundry Module to pull credentials from bound service - // If they are found then they are stored in sUsername and sPassword, as the - // service credentials. This separation from sUsername and username to allow - // the end user to modify the node credentials when the service is not bound. - // Otherwise, once set username would never get reset, resulting in a frustrated - // 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; - - var username, password, sUsername, sPassword; - var service = cfenv.getAppEnv().getServiceCreds(/dialog/i); - - if (service) { - sUsername = service.username; - sPassword = service.password; - } - - RED.httpAdmin.get('/service-dialog/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - - // This is the Dialog Node. - // The node supports six modes - // create a dialog from a dialog template - // delete a dialog : the Watson Dialog service Instance is limited to 10 dialog instances - // list - retrieves a list of the Dialogs - // start conversation - initiates a conversation with an existing conversation - // continue a conversation - continues with a started conversation - // get profile variable - GETs the profile variables associated with the dialog - - function WatsonDialogNode (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.log('Watson Developer Cloud Contribution - Dialog Node Instantiated') ; - - this.on('input', function (msg) { - this.log('Watson Developer Cloud Contribution - Input received'); - - var message = ''; - if (!msg.payload) { - message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - var username = sUsername || this.credentials.username; - var password = sPassword || this.credentials.password; - this.status({}); - - if (!username || !password) { - this.status({fill:'red', shape:'ring', text:'missing credentials'}); - message = 'Missing Watson Dialog service credentials'; - this.error(message, msg); - return; - } - - var dialog = watson.dialog({ - username: username, - password: password, - version: 'v1' - }); - - var params = {}; - if (config.mode === 'create') { - performCreate(node,dialog,msg); - } - else if (config.mode === 'delete') { - performDelete(node,dialog,msg,config); - } - else if (config.mode === 'deleteall') { - performDeleteAll(node,dialog,msg,config); - } - else if (config.mode === 'list') { - performList(node,dialog,msg); - } else if (config.mode === 'startconverse' || config.mode === 'converse' || config.mode === 'getprofile') { - var dialogid = config.dialog; - var clientid = config.clientid; - var converseid = config.converse; - - if (!dialogid || '' == dialogid) { - if (msg.dialog_params && 'dialog_id' in msg.dialog_params) { - dialogid = msg.dialog_params['dialog_id']; - } - } - - if (!dialogid || '' == dialogid) { - message = 'Missing Dialog ID'; - node.status({fill:'red', shape:'dot', text:message}); - node.error(message, msg); - } - - if (config.mode === 'converse' || config.mode === 'getprofile') { - if (!clientid || '' == clientid) { - if (msg.dialog_params && 'client_id' in msg.dialog_params) { - clientid = msg.dialog_params['client_id']; - } - } - if (!converseid || '' === converseid) { - if (msg.dialog_params && 'converse_id' in msg.dialog_params) { - converseid = msg.dialog_params['converse_id']; - } - } - if (!clientid || '' === clientid) { - message = 'Missing Client ID'; - node.status({fill:'red', shape:'dot', text:message}); - node.error(message, msg); - } - if (!converseid || '' === converseid) { - var message = 'Missing Conversation ID'; - node.status({fill:'red', shape:'dot', text:message}); - node.error(message, msg); - } - params.client_id = clientid; - params.conversation_id = converseid; - } - - params.dialog_id = dialogid; - params.input = msg.payload; - - if (config.mode === 'startconverse' || config.mode === 'converse') { - node.status({fill:'blue', shape:'dot', text:'Starting Dialog Conversation'}); - dialog.conversation (params, function (err, dialog_data) { - node.status({}); - if (err) { - node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); - console.log('Error:', msg, err); - node.error(err, msg); - } else { - msg.dialog = dialog_data; - msg.payload = 'Check msg.dialog dialog data'; - node.send(msg); - } - }); - } - else { - node.status({fill:'blue', shape:'dot', text:'Requesting dialog profile variables'}); - dialog.getProfile (params, function (err, dialog_data) { - node.status({}); - if (err) { - node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); - node.error(err, msg); - } else { - msg.dialog = dialog_data; - msg.payload = 'Check msg.dialog dialog data'; - node.send(msg); - } - }); - } - } - }); - } - - // This function creates a new dialog template. The name must be unique, the file can be in any - // accepted format, and be either a text file or a binary buffer. - function performCreate(node,dialog,msg) { - var params = {} - node.status({fill:'blue', shape:'dot', text:'requesting create of new dialog template'}); - //if ('file' in msg.dialog_params && 'dialog_name' in msg.dialog_params) { - if ('dialog_name' in msg.dialog_params) { - // extension supported : only XML - // TODO : support other API format (json and encrypted crt) - temp.open({suffix: '.xml'}, function (err, info) { - if (err) throw err; - //var fileBuffer = msg.dialog_params['file']; - var fileBuffer = msg.payload; - fs.writeFile(info.path, fileBuffer, function (err) { - if (err) { - console.error(err); - throw err; - } - var aFileStream = fs.createReadStream(info.path); - params.file = aFileStream; - params.name = msg.dialog_params['dialog_name']; - // Watson SDK call - dialog.createDialog(params, function(err, dialog_data){ - node.status({}); - if (err) { - node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); - node.error(err, msg); - } else { - msg.dialog = dialog_data; - msg.payload = 'Check msg.dialog dialog data'; - node.send(msg); - } - }); - }); - }); - } /* else if (! 'file' in msg.dialog_params) { - var errtxt = 'Missing Dialog template file'; - node.status({fill:'red', shape:'ring', text:errtxt}); - node.error(errtxt, msg); - }*/ - else { - errtxt = 'dialog_name not specified'; - node.status({fill:'red', shape:'ring', text:errtxt}); - node.error(errtxt, msg); - } - } - -// This function delete an existing dialog instance. - function performDelete(node,dialog,msg, config) { - var params = {}; - var message = ''; - node.status({fill:'blue', shape:'dot', text:'requesting delete of a dialog instance'}); - - if (!config.dialog || '' != config.dialog) { - - params.dialog_id = config.dialog; - - dialog.deleteDialog(params, function(err, dialog_data){ - node.status({}); - if (!err) { - message='Dialog deleted successfully'; - msg.dialog = dialog_data; - msg.payload = message; - node.send(msg); - } else if (err && err.code==404) { - message='Dialog already deleted or not existing (404)'; - node.status({fill:'green', shape:'dot', text:message}); - msg.payload = message; - console.log(err); - node.error(message, msg); - } else { - node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); - node.error(err, msg); - console.log(err); - } - }); - } else { - message = 'Dialog Id not specified'; - node.status({fill:'red', shape:'ring', text:message}); - node.error(errmessage, msg); - } - } - - // This function performs the operation to fetch a list of all dialog templates - function performList(node,dialog,msg) { - - node.status({fill:'blue', shape:'dot', text:'requesting list of dialogs'}); - dialog.getDialogs({}, function(err, dialogs){ - node.status({}); - if (err) { - node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); - node.error(err, msg); - } else { - msg.dialog = dialogs; - msg.payload = 'Check msg.dialog for list of dialogs'; - node.send(msg); - } - }); - } - - // This function performs the operation to Delete ALL Dialogs - function performDeleteAll(node,dialog,msg) { - - node.status({fill:'blue', shape:'dot', text:'requesting Delete All dialogs'}); - dialog.getDialogs({}, function(err, dialogs){ - node.status({}); - if (err) { - node.status({fill:'red', shape:'ring', text:'Delete All : call to getDialogs service failed'}); - node.error(err, msg); - } else { - // Array to hold async tasks - var asyncTasks = []; - var nb_todelete = dialogs.dialogs.length; - var nbdeleted = 0; - dialogs.dialogs.forEach(function (aDialog) { - - asyncTasks.push(function (cb) { - var parms = {}; - parms.dialog_id=aDialog.dialog_id;; - dialog.deleteDialog(parms, function(err, dialog_data){ - node.status({}); - if (err) { - node.error(err, msg); - console.log('Error with the removal of Dialog ID '+parms.dialog_id +' : ' + err); - } else { - console.log('Dialog ID '+ aDialog.dialog_id + ' deleted successfully.'); - nbdeleted++; - } - cb(); - }); - }); - }); - - } // else - - async.parallel(asyncTasks, function(){ - // All tasks are done now - console.log('Deleted ' + nbdeleted + ' dialog objects on ' + nb_todelete ); - if (nbdeleted==nb_todelete) - msg.payload = 'All Dialogs have been deleted'; - else - msg.payload = 'Some Dialogs could have not been deleted; See node-RED log for errors.'; - console.log(msg.payload); - node.send(msg); - }); - - }); - - } // delete all func - - - //Register the node as service-dialog to nodeRED - RED.nodes.registerType('service-dialog', - WatsonDialogNode, - {credentials: { username: {type:'text'}, - password: {type:'password'} - } - }); - -}; - - diff --git a/services/document_conversion/icons/DocumentConversion.png b/services/document_conversion/icons/DocumentConversion.png deleted file mode 100644 index b00c2487a045ebbcc4eddf9a95062befa3ad3316..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2126 zcmZuyd0Z0M7Djs-V&amcgIOZEJT<|zCP5%IL}XmwXZgDVKLyeL#$vrT)PP&DUID9RIu{~E5aFtBhQkBveg_6> z7GY~^tw30FW0^dfz?#Y3`X$L9d2n=Y2q%Kgi(oOKYk6tGtY{tv23sri=la?wgZ*bA zCig2V1wVv<#zt(1+aUffh!+w1S9|{zwRZC*>@%w`#n6h;p!RU+G#-oN&0OPh zRQltgupkR~I|cwyH6-Gkya^ha!sWvh7v1KusnLPR46||zZ?C=iRwSIwH9g&vK#-4j zTGLCb)8Fhkb>g*Vu)zvxzmwD6Ri%6nbqz}wV_^MF3!rgssYZc+x54Z&^O_?c<2#3{ zrmXOq@$cKRkvEXsDM?KSV-M|HvyVE%F>Fx0Mx~?iiy#hoUQgCsd63+imld_T?`?ifCX*?)S#EbKD=QwAcrYP1Tu0wOLRBUThMgcHtqcJF4ZArUjcuE=m|Erud)B zh?2|YYB3|sm-UQ9(itO+FefLcK+@kY+_i8{+sMGc@;vQnUW11X>r$%WuAjNq*49-` zP58r=B9Z78G*kI;md<@X#jmAALwMo$)YFap$7(MvNZ*;eE9jt=46cv*lO6o6)q4e-c9#9z3WCuO&y?HB2nNxy&81t7g|W#Go-4xtW<6g+xl0dn#Rj zfuv?Fzn|tWFUaSbyG%lO^R3UF_oW^fI10}Jjihc{wa@po;7%pAIEMH*W`_T8%NGlI zc?!Z?!5D4;gUP2a=xc1)@R%Gkv;CKz{LX7&9}qU7#G_)`rX}Uo$oHdh6$6_!)$vQSm}iCsOWz^&#>plrr0w(9*w<@nmXBmsZzkQDQw;}P4^oyTIi86inO^cT z&ErRd*OUE+nuW5&W<7oV(z%(ix?ESURFfMXS1x!H5GrD^_}AEIXej8uSHmz4?ws&?uAA^UK7FQ=?4Qo3uR|MTBjH}<3@k-M8B~r_r>@&}`3ICd* zy>-ySY-#Z(s-NA~*Xyrc9!@`1*Z|bhShw0-LI~X0=ieA1MI`FOVwa|16K5gPhELY_ z-`$zflcmnT<1Ff}DD|)zj;ngnzsfv%TwjWJbOS5vA*P000>X1^@s6#OZ}&0009@NklU6rP}quDb6sErRMM&7d+7iz17lPx_FOzNo}pcUDTmf(jy{f}o4&4|Ew)w|bM7 zA8YG=%YP0545Zm`DCPuHn1TZi_^w`=@-jG z-H#XCXbf|aDt^CWkh!#7Uv%s~daUTCem`l~8cW0(gabqo#!n!O?ma0VOUYEJ$ggQcYMpFB7-{nA9@T?&0# zBpcTr`|U*5SlkDiOu7C;wFvJwBMfeo^TZLIq_;Hyhsn*au zAw~VnI~@&(hEdEDjR#Kni%C_ZyJ;$J5wHT;%M2NE0OMrTW;|uY1IIk$?Xc~aI3y0J zM4Z8r{;lvt - - - - - - - - - diff --git a/services/document_conversion/v1.js b/services/document_conversion/v1.js deleted file mode 100644 index 93a3114d..00000000 --- a/services/document_conversion/v1.js +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ -module.exports = function(RED) { - var pkg = require('../../package.json'), - temp = require('temp'), - fs = require('fs'), - isDocx = require('is-docx'), - serviceutils = require('../../utilities/service-utils'), - payloadutils = require('../../utilities/payload-utils'), - converts = []; - - const DocumentConversionV1 = require('watson-developer-cloud/document-conversion/v1'); - const SERVICE_IDENTIFIER = 'document-conversion'; - - converts = serviceutils.getAllServiceDetails(SERVICE_IDENTIFIER); - temp.track(); - - // GNF: This method provides service credentials when prompted from the node editor - RED.httpAdmin.get('/convert/vcap', function(req, res) { - res.send(JSON.stringify(converts)); - }); - - function ConvertNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - const configFields = ['name', 'username', 'password', 'service', 'target']; - for (var i in configFields) { - node[configFields[i]] = config[configFields[i]]; - } - - // Perform the Conversion, invoking the conver method - // on the service. - node.performConversion = function(msg, filename) { - var p = new Promise(function resolver(resolve, reject){ - var document_conversion = new DocumentConversionV1({ - username: node.username, - password: node.password, - version_date: '2015-12-01', - headers: { - 'User-Agent': pkg.name + '-' + pkg.version - } - }); - - document_conversion.convert({ - file: fs.createReadStream(filename), - conversion_target: msg.target || node.target, - word: msg.word, - pdf: msg.pdf, - normalized_html: msg.normalized_html - }, function(err, response) { - if (err) { - reject(err); - } else { - resolve(response); - } - }); - - }); - return p; - }; - - // Docx files are seen as zips, and require special processing on - // the temp file extension so that they seen correctly by the - // Document Conversion service. - node.checkForZip = function(pd) { - var p = new Promise(function resolver(resolve, reject){ - if ('zip' === pd.format) { - var f = fs.readFileSync(pd.info.path); - if (isDocx(f)) { - var newfilename = pd.info.path + '.docx'; - fs.rename(pd.info.path, newfilename, function(err){ - if (err) { - reject('Unable to handle docx file.'); - } else { - resolve(newfilename); - } - }); - } - } else { - resolve(null); - } - }); - return p; - }; - - // Open up the stream, done in a seperate process as makes use - // of callback - node.openStream = function(pd, msg) { - var p = new Promise(function resolver(resolve, reject){ - pd.stream_payload(pd.info.path, msg.payload, function(format) { - resolve(format); - }); - }); - return p; - }; - - // Sanity check on the payload, as subsequent process will fail - // if all is not ok - node.payloadCheck = function(pd, msg) { - if (!msg.payload) { - return Promise.reject('Payload is required'); - } - var stream_payload = (typeof msg.payload === 'string') ? - payloadutils.stream_url_format : - payloadutils.stream_buffer; - if ('number' === typeof msg.payload) { - return Promise.reject('Invalid input - expecting a url or a stream buffer'); - } - else if (typeof msg.payload === 'string' && !payloadutils.urlCheck(msg.payload)) { - return Promise.reject('Invalid URI, make sure to include the "http(s)" at the beginning.'); - } - else { - pd.stream_payload = stream_payload; - return Promise.resolve(); - } - }; - - // Standard temp file open - node.openTemp = function() { - var p = new Promise(function resolver(resolve, reject){ - temp.open({ - //suffix: '.docx' - }, function(err, info) { - if (err) { - reject(err); - } else { - resolve(info); - } - }); - }); - return p; - }; - - // Perform basic check to see that credentials - // are provided, altough they may still be - // invalid - node.verifyCredentials = function(msg) { - if (node && node.username && node.password) { - return Promise.resolve(); - } - return Promise.reject('missing credentials'); - }; - - // Invoked when required to act on msg as part of a flow. - this.on('input', function(msg) { - var processData = {}; - node.verifyCredentials(msg) - .then(function(){ - return node.openTemp(); - }) - .then(function(info){ - processData.info = info; - return node.payloadCheck(processData, msg); - }) - .then(function(){ - return node.openStream(processData, msg); - }) - .then(function(format){ - processData.format = format; - return node.checkForZip(processData); - }) - .then(function(newfilename){ - node.status({ - fill: 'blue', - shape: 'dot', - text: 'converting, this might take some time' - }); - return node.performConversion(msg, newfilename ? - newfilename : - processData.info.path); - }) - .then(function(response){ - node.status({}); - msg.payload = response; - node.send(msg); - }) - .catch(function(err){ - var messageTxt = err.error ? err.error : err; - node.status({fill:'red', shape:'dot', text: messageTxt}); - node.error(messageTxt, msg); - }); - }); - - } - RED.nodes.registerType('convert', ConvertNode); -}; diff --git a/services/language_identification/icons/language.png b/services/language_identification/icons/language.png deleted file mode 100644 index ace60d5da4a9586bd4fdfbb5d829a1bac7fbd6f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 435 zcmeAS@N?(olHy`uVBq!ia0vp^B0wz1!3HFCgzU0`6kC$Fy9wy$!fk$L9 z0|U1(2s1Lwnj--eWH0gbb!ETDDb8!5S$R4)2Ph<2;u=xnoS&PUnpeW$T$GwvlA5AW zo>`Ki;O^-g5Z=fq&cMJZ?djqe;&J@#R9o*O4gwDM^&ZU(}r*AKg4s^ zIg4cGxamo|Jd88n@O#G0zY;S9y92LQ zDzKVdW8I^AKyCxC#}WfZKcNJUo~l(98Nc5>T+jWry&`Mj%2iqJF3)-lmsy_Fcv#Hw z@Q!7;=|{&kAJlv=Pv7`M$4f)$I>Wu+rh<_{SKS}1>keR?Q+%AkbJCrv_u*@{u0N0} zzL4>oJ#%syd-Fl($zNT6?+rLxI!UX=AnRuF()h{s(;u$f`fa7oY1dF)`>=L_Ym8ls zZe&$o5WZ5H+i+Ir^t9u*lh)b_O>|C3yfta}r2qfVFPwbg>x*KyQ1gbX^U_ZJ&GGr~ bc#qK}_jZ|Qy3{IQSTcCJ`njxgN@xNAi*u}A diff --git a/services/language_identification/v1.html b/services/language_identification/v1.html deleted file mode 100644 index 5e8a6910..00000000 --- a/services/language_identification/v1.html +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - diff --git a/services/language_identification/v1.js b/services/language_identification/v1.js deleted file mode 100644 index 0855cce3..00000000 --- a/services/language_identification/v1.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright 2013,2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'), - LanguageTranslatorV2 = require('watson-developer-cloud/language-translator/v2'), - service = cfenv.getAppEnv().getServiceCreds(/language translation/i) - username = null, - password = null, - sUsername = null, - sPassword = null, - endpointUrl = 'https://gateway.watsonplatform.net/language-translation/api'; - - if (service) { - sUsername = service.username; - sPassword = service.password; - } - - RED.httpAdmin.get('/watson-language-identification/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function Node (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password; - - if (!username || !password) { - var message = 'Missing Language Identification service credentials'; - node.error(message, msg); - return; - } - - var language_translation = new LanguageTranslatorV2({ - username: username, - password: password, - version: 'v2', - url: endpointUrl - }); - - node.status({fill:"blue", shape:"dot", text:"requesting"}); - language_translation.identify({text: msg.payload}, function (err, response) { - node.status({}) - if (err) { - node.error(err, msg); - } else { - msg.lang = response.languages[0]; - } - - node.send(msg); - }); - }); - } - RED.nodes.registerType('watson-language-identification', Node, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); -}; From b7442b692e31f72b293d7a012ded4a9e8da296a4 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:44:50 +0000 Subject: [PATCH 07/11] Remove redundant nodes --- .../icons/relationship_extraction.png | Bin 4561 -> 0 bytes services/relationship_extraction/v1.html | 111 --- services/relationship_extraction/v1.js | 84 --- .../retrieve_and_rank/icons/RetrieveRank.png | Bin 1638 -> 0 bytes services/retrieve_and_rank/v1.html | 704 ------------------ services/retrieve_and_rank/v1.js | 627 ---------------- .../icons/VR-v3-25x25-old.png | Bin 1164 -> 0 bytes .../similarity_search/icons/VR-v3-pink.png | Bin 8809 -> 0 bytes services/similarity_search/icons/visual2.png | Bin 876 -> 0 bytes .../icons/visual_recognition.png | Bin 3720 -> 0 bytes services/similarity_search/v3.html | 334 --------- services/similarity_search/v3.js | 223 ------ 12 files changed, 2083 deletions(-) delete mode 100644 services/relationship_extraction/icons/relationship_extraction.png delete mode 100644 services/relationship_extraction/v1.html delete mode 100644 services/relationship_extraction/v1.js delete mode 100644 services/retrieve_and_rank/icons/RetrieveRank.png delete mode 100644 services/retrieve_and_rank/v1.html delete mode 100644 services/retrieve_and_rank/v1.js delete mode 100644 services/similarity_search/icons/VR-v3-25x25-old.png delete mode 100644 services/similarity_search/icons/VR-v3-pink.png delete mode 100644 services/similarity_search/icons/visual2.png delete mode 100644 services/similarity_search/icons/visual_recognition.png delete mode 100644 services/similarity_search/v3.html delete mode 100644 services/similarity_search/v3.js diff --git a/services/relationship_extraction/icons/relationship_extraction.png b/services/relationship_extraction/icons/relationship_extraction.png deleted file mode 100644 index 765dac8eb0116e9dd98b3341a6902c142e122826..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4561 zcmZuz2RK~Y+8#`zw?yj+}>UZO=eNJNx~Q3fFh8G=ES7&RhM zg6Kqv=;F#b=iYn%^WXhEYwxwc^}gTtz3*Djvv-2Nt~w-{T?J& zFYmauSbG3~OwmnbLjV=&-zYeE@ez$Vfv#WlHdF-pL85 zexyP;eukCJ%PZIDsXzD*iEwEBa;sgR$M@q!csf{8nd>TmOm*V6Oc)Qt5@D86eK(Wn z1+afVn_o0eM3laWw73eqh^z59c)2Xt+Lw#s`BubiHpKK+{8@6V{%k(?d`U8}$TFAv zt8+;Ru_M-4Gas;Y$Tv22^i&5ROqXXfxWZH9kszu{$Mij6j}SnTg@e8Ip-MW2xjX{| zlsSJ(1SV+0%V;NaU6)qhJDu#-8y&+%1hcyC&OZv!!S6RvJQik%s6phY5^$S&=DDPA zRkLnwnSES#Ic}etV-GVrmwg{}dT*C!6aP#x`I*_A$7U52OAk2UGJnEW-vKefonv&ciwbw?M&5p0v5?;Y(2H4iQ|HJS~hu^tZ>s4)X@SpPERQ zF~~>W)Vv|)sJc}4vP@fLaFBuug?BhVq`6pp2Xp<<*LCY@;X8)i*wuRmt68Km2`;U% zGLfcf5C^iD@QL|w#@oEaOkoA?bS@8V0HLuk{bo(#_Xt^l@=YQxFZm$C&YkX5hgMO`?aFAOjdd=%7f{m6BC{i7KxQlNwmCVI>bP!%kBldevCLRe9CcI@! z$r>T%O*9Jv#6)P&5akd-GzeW4fUgwgK3yI`kxvBv(Qe*=@yMWIpl;M{@2i%;`|l{d z$tfb#70BW`w1o*~BV9?Nc4%%CD^{e@mr~~`eWYPACka$m)W1VV)UBM5Mw6j%Jj_$h zC=gvyq^vKyf76e-g~TfQ#$Nc`$KL1+wZF5#FR(BG*3GM2BJdwiAt5l2X;!MmGkne5=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A!)X0Dsz$mK)A^wAY6np>&PJx9Hw#FJCANcGSh>boavUweT^tstnA%7A($WEEga%XWAm+O=hE`KLSMol+B zg*{=DF5&CPaOSUI7f>|nCNMF5N3Hc-PTs2Sq^NSm>T%YTdomn#tB!*NVmfRN|bZ9 zeTby;csQnixd56)GDgu6loC~}5De$|Cw0Lfj~637TO@2MwhNlAY1ZqwPC+duuLR6b z#?X=iE#Fg>$kl9gUC)jTXMsqh%yU303(0AS9<1Le z^#sSs{s0Ev?QS>{f-Si1DKtt4{FI6DhX*oL@rPONRB|JCds-;mZTQ*brh|oHiUnSw z7+4O|JWspjH%b%#-Sd4_+5IWCMk+c?$AE-K`WM_DXORE^ diff --git a/services/relationship_extraction/v1.html b/services/relationship_extraction/v1.html deleted file mode 100644 index 011fd1d0..00000000 --- a/services/relationship_extraction/v1.html +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - diff --git a/services/relationship_extraction/v1.js b/services/relationship_extraction/v1.js deleted file mode 100644 index f7e386e2..00000000 --- a/services/relationship_extraction/v1.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'); - - var services = cfenv.getAppEnv().services, - service; - - var username, password; - - var service = cfenv.getAppEnv().getServiceCreds(/relationship extraction/i) - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-relationship-extraction/vcap', function (req, res) { - res.json(service ? service.sids : null); - }); - - function Node(config) { - RED.nodes.createNode(this,config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - username = username || this.credentials.username; - password = password || this.credentials.password; - - if (!username || !password) { - var message = 'Missing Relationship Extraction service credentials'; - node.error(message, msg); - return; - } - - var watson = require('watson-developer-cloud'); - - var relationship_extraction = watson.relationship_extraction({ - username: username, - password: password, - version: 'v1-beta' - }); - - node.status({fill:"blue", shape:"dot", text:"requesting"}); - relationship_extraction.extract({text: msg.payload, dataset: config.dataset }, function (err, response) { - node.status({}) - if (err) { - node.error(err, msg); - node.send(msg); - return; - } - - msg.relationships = response; - node.send(msg); - }); - }); - } - RED.nodes.registerType("watson-relationship-extraction",Node, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); -}; diff --git a/services/retrieve_and_rank/icons/RetrieveRank.png b/services/retrieve_and_rank/icons/RetrieveRank.png deleted file mode 100644 index 142436ef48f82ec9e40a4d77ed118156f3ebe25b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1638 zcmeAS@N?(olHy`uVBq!ia0vp^azHG>!3HGXX8P_2QjEnx?oJHr&dIz4aySb-B8wRq z^pruEv0|xx8BoFL%#etZ2wxwolpi<;HsXMd|v6mX?>NR1r{I~Jn4TJxnwU~)qmQlv;Zhrrkyidi znW;d(f_!9WXrqrI232pP5ArUO_aR{m76k^b9T(6hSVY-zY3iM|Wnf@2@pN$v@!*|1 z%{LG3&{r~TRlMCJ2WPY68DgXRV z@%f$K_Z=}1xV?=zq3W&Gt=$XQ)fT>Znf*dOq4$l-7TxVzJL2as?~{I;TOe+yqCfLb z;k@&UnzS!7EOKa%e4}3P_@y~%V+H$PrbEjz>$={t#Gku-qc@*1UO4uP`l@Rd??O`i z;}(3MQk=F&IIlt9{&Zg->(+#@&ZQyt$I2PP4hsL6b@%`M`}hA>>N?$CvvTFe^z`)4 zj~_pt>7w*8GCTWqXMu%|ednA1WwWpT*ZL56roUS6{>BqeA3l7jedNxplPR0H&de$1 z-!d^qFFj(~Qr;OX{15;0%$CbB5@?m$uy9hw-Yrb_O9k6s>um76*4*6uU0PcDy05># zbjs?WtQ!~SY@K-idGD`ZRg2fIU3=ieBE9Kl%NI<_UZ=FzAt9lts7Up1rdQ0af&~E@ zH*V&bop{=vp?qR}0i)6fHanG~6B--#zdpW6&3g0p?dA2s!Iu-o>ei=(+?JA+o%{0L zJHHJFSMM-6D3QCjVU=s+^Lrbgry<#U;Jx_>(p17c|aBNQBPXIB%xV4Ef_> z3CqJ?_&Wr7s7)?i8M3N(Qk{z$quylS+ZT263VAeN^tdh7juC$z`l91fTz%sq_tQEn z<^i2Muc3a%pCCDBXXpBh_Z(MlE)kz&_*m_^T*vXpt<$E7?Y*m%ygzYy>6DH06DNEt z-f^O4oyiU(JJ$UN+|<4&mCX9q7NL_i;i}N4rQVS{T+T?oEV=by&f90t(tI^UL*FdO z(ejXg%?Yq;r- z99Jt}0Bh~mE!C{k-lcqWEV;Ur8p`O~@o+gXxXzZ?H=`lh==W6B@1$@NWU+Le#BelHPTbxPiTfywN$|64X* z5c@SdQTB=>+oS^FbxG!pXYFpeCy2iADXsj%YRx8;y6eH6kEbn-|5!9$O;p_fA^V*;<84&h-i`pCAnA= zw$z))U7j|lN#TTh_RCA5VmxymOw~Pg{(*Swe}_q>Q~%ahzUEqN@iJawwO7h(8^;nJ zHU}f-T}xIiFq(dM(WF%ye9LFJ&h>7KW3DRtrD1tI?A%A)O9y@hK0P6P2~_xdy85}S Ib4q9e0AhH-7ytkO diff --git a/services/retrieve_and_rank/v1.html b/services/retrieve_and_rank/v1.html deleted file mode 100644 index 6156827f..00000000 --- a/services/retrieve_and_rank/v1.html +++ /dev/null @@ -1,704 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/retrieve_and_rank/v1.js b/services/retrieve_and_rank/v1.js deleted file mode 100644 index 595cc2ed..00000000 --- a/services/retrieve_and_rank/v1.js +++ /dev/null @@ -1,627 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var pkg = require('../../package.json'), - cfenv = require('cfenv'), - fs = require('fs'), - temp = require('temp'), - qs = require('qs'), - request = require('request'), - fileType = require('file-type'), - watson = require('watson-developer-cloud'), - username, password, - service = cfenv.getAppEnv().getServiceCreds(/retrieve and rank/i); - - temp.track(); - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-retrieve-and-rank/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function serviceCredentialsConfigurationNode(config) { - RED.nodes.createNode(this,config); - this.username = config.username; - this.password = config.password; - } - - function createRankerNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - if (!msg.payload instanceof String) { - var message = 'Invalid property: msg.payload, must be a String.'; - node.error(message, msg); - return; - } - var rankername, params = { - training_data: msg.payload - }; - - (config.rankername !== '') ? rankername = config.rankername : rankername = msg.ranker_name; - if (rankername) { - params.training_metadata = '{\"name\": \"'+rankername+'\"}'; - } - node.status({fill:'blue',shape:'ring',text:'Uploading training data'}); - retrieve_and_rank.createRanker(params, function(err, res) { - handleWatsonCallback(null,node,msg,err,res,function() { - node.status({fill:'blue',shape:'ring',text:'Training data uploaded. Ranker is training'}); - //Now check the status of the ranker - var ranker_id = res.ranker_id; - checkRankerStatus(retrieve_and_rank,msg,node,ranker_id); - });; - }); - }); - }); - } - - function rankerSettingsNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - var rankerid; - (config.rankerid !== '') ? rankerid = config.rankerid : rankerid = msg.ranker_id; - var params = { - ranker_id: rankerid - } - switch (config.mode) { - case 'list': - retrieve_and_rank.listRankers({},function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - break; - case 'info': - if (params.ranker_id) { - retrieve_and_rank.rankerStatus(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'No ranker id specified'; - node.error(message, msg) - return; - } - break; - case 'delete': - if (params.ranker_id) { - retrieve_and_rank.deleteRanker(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'No ranker id specified'; - node.error(message, msg) - return; - } - break; - } - }); - }); - } - - function searchAndRankNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - - var clusterid; - (config.clusterid !== '') ? clusterid = config.clusterid : clusterid = msg.cluster_id; - var collectionname; - (config.collectionname !== '') ? collectionname = config.collectionname - : collectionname = msg.collection_name; - var params = { - cluster_id: clusterid, - collection_name: collectionname - }; - //Get a Solr client for indexing and searching documents. - var solrClient = retrieve_and_rank.createSolrClient(params); - - var rankerid; - (config.rankerid !== '') ? rankerid = config.rankerid : rankerid = msg.ranker_id; - var question = msg.payload; - - var query; - - if(config.searchmode === 'search') { - query = qs.stringify({q: question, fl: 'id,title,body'}); - } else { - query = qs.stringify({q: question, ranker_id: rankerid, fl: 'id,title,body'}); - } - - solrClient.get('fcselect', query, function(err, searchResponse) { - handleWatsonCallback(null,node,msg,err,searchResponse); - }); - - }); - }); - } - - function createClusterNode(config) { - RED.nodes.createNode(this, config) - var node = this - - this.on('input', function(msg) { - setupRankRetrieveNode(msg, config, this, function (retrieve_and_rank) { - - //Cluster name can be passed into msg.payload, but the cluster name - //specified in the config takes priority - var clustername; - (config.clustername !== '') ? clustername = config.clustername : clustername = msg.payload; - var params = { - cluster_name: clustername, - cluster_size: config.clustersize !== 'free' ? config.clustersize : null, - } - - node.status({ fill: 'blue', shape: 'ring', text: 'Creating cluster' }); - - retrieve_and_rank.createCluster(params, function(err, res) { - - if (err) { - node.status({}); - var message = ''; - (err.error) ? message = err.error : message = err.message; - return node.error(message, msg); - } - - node.status({fill: 'blue', shape: 'ring', text: 'Preparing cluster' }); - handleWatsonCallback(null, node, msg, err, res, function() { - // Now check the status of the cluster - var cluster_id = res.solr_cluster_id; - checkClusterStatus(retrieve_and_rank, msg, node, cluster_id) - }) - }) - }) - }) - } - - function clusterSettingsNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - var clusterid; - (config.clusterid !== '') ? clusterid = config.clusterid : clusterid = msg.cluster_id; - var params = { - cluster_id: clusterid - } - switch (config.mode) { - case 'list': - node.status({fill: 'blue', shape: 'ring', text: 'Getting clusters...' }); - retrieve_and_rank.listClusters({},function(err,res) { - node.status({}); - handleWatsonCallback(config.mode,node,msg,err,res); - }); - break; - case 'info': - if (params.cluster_id) { - retrieve_and_rank.pollCluster(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'No cluster id specified'; - node.error(message, msg) - return; - } - break; - case 'delete': - if (params.cluster_id) { - retrieve_and_rank.deleteCluster(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'No cluster id specified'; - node.error(message, msg) - return; - } - break; - } - }); - }); - } - - function uploadSolrConfigurationNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - - //zip file comes in on msg.payload as buffer - if (!msg.payload instanceof Buffer) { - var message = 'Invalid property: msg.payload, must be a Buffer.'; - node.error(message, msg); - return; - } - - var uploadConfig = function(filePath,cb) { - var clusterid; - (config.clusterid !== '') ? clusterid = config.clusterid : clusterid = msg.cluster_id; - var configname; - (config.configname !== '') ? configname = config.configname - : configname = msg.configuration_name; - var params = { - cluster_id: clusterid, - config_name: configname, - config_zip_path: filePath - }; - if (!params.cluster_id || !params.config_name) { - var message = 'No cluster id or configuration name specified'; - return node.error(message, msg); - } - node.status({fill: 'blue', shape: 'ring', text: 'Uploading solr configuration...' }); - retrieve_and_rank.uploadConfig(params, function (err, res) { - node.status({}); - handleWatsonCallback(null,node,msg,err,res); - }); - } - - var stream_buffer = function (file, contents, cb) { - fs.writeFile(file, contents, function (err) { - if (err) throw err; - cb(file); - }); - }; - temp.open({suffix: '.zip'}, function (err, info) { - if (err) throw err; - stream_buffer(info.path, msg.payload, function (file) { - uploadConfig(file, temp.cleanup); - }); - }); - }); - }); - } - - function solrConfigurationSettingsNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - var clusterid; - (config.clusterid !== '') ? clusterid = config.clusterid : clusterid = msg.cluster_id; - var configname; - (config.configname !== '') ? configname = config.configname : configname = msg.configuration_name; - var params = { - cluster_id: clusterid, - config_name: configname - } - switch (config.mode) { - case 'list': - node.status({fill: 'blue', shape: 'ring', text: 'Getting solr configurations...' }); - retrieve_and_rank.listConfigs(params,function(err,res) { - node.status({}); - handleWatsonCallback(config.mode,node,msg,err,res); - }); - break; - case 'info': - if (params.cluster_id && params.config_name) { - - //Note. temporary workaround until bug is fixed in Node SDK - //Stream zip file from watson api to temp directory, - //read from temp directory and pass on in msg.payload as buffer - var url = 'https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/'+params.cluster_id+'/config/'+params.config_name; - var sendToPayload = function(zipFile, cb) { - msg.payload = zipFile; - node.send(msg); - if (cb) cb(); - } - - var stream_url = function (file, location, cb) { - var wstream = fs.createWriteStream(file); - wstream.on('finish', function () { - fs.readFile(file, function (err, buf) { - if (err) console.error(err); - cb(buf); - }) - }); - request(location).auth(username,password) - .pipe(wstream); - }; - - temp.open({suffix: '.zip'}, function (err, info) { - if (err) throw err; - stream_url(info.path, url, function (content) { - sendToPayload(content, temp.cleanup); - }); - }); - } else { - var message = 'Missing cluster id or config name'; - node.error(message, msg) - return; - } - break; - case 'delete': - if (params.cluster_id && params.config_name) { - retrieve_and_rank.deleteConfig(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'Missing cluster id or config name'; - node.error(message, msg) - return; - } - break; - } - }); - }); - } - - function solrCollectionNode(config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function(msg) { - setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) { - var clusterid; - (config.clusterid !== '') ? clusterid = config.clusterid : clusterid = msg.cluster_id; - var collectionname; - (config.collectionname !== '') ? collectionname = config.collectionname : collectionname = msg.collection_name; - - var params = { - cluster_id: clusterid, - collection_name: collectionname - } - if (!params.cluster_id || !params.collection_name) { - var message = 'Missing cluster id or collection name'; - node.error(message, msg) - return; - } - - switch (config.mode) { - case 'create': - var configname; - (config.configname !== '') ? configname = config.configname : configname = msg.configuration_name; - params.config_name = configname; - if (!configname) { - var message = 'Missing configuration name'; - return node.error(message, msg); - } else { - node.status({fill: 'blue', shape: 'ring', text: 'Creating solr collection' }); - retrieve_and_rank.createCollection(params,function(err,res) { - node.status({}); - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } - break; - case 'delete': - retrieve_and_rank.deleteCollection(params,function(err,res) { - handleWatsonCallback(config.mode,node,msg,err,res); - }); - break; - case 'index': - - if (msg.payload && typeof(msg.payload) == 'string') { - - var solrClient = retrieve_and_rank.createSolrClient(params); - node.status({fill: 'blue', shape: 'ring', text: 'Indexing document' }); - solrClient.add(JSON.parse(msg.payload),function(err,res) { - node.status({}); - handleWatsonCallback(config.mode,node,msg,err,res,function(){ - solrClient.commit(function(err) { - if (err) { - var message = 'Error committing change: ' + err; - return node.error(message, msg); - } else { - msg.payload = 'Document indexed successfully'; - node.send(msg); - } - }); - }); - }); - } else { - var message = 'Missing or invalid document object'; - return node.error(message, msg); - } - break; - - case 'search': - if (msg.payload && typeof(msg.payload) == 'string') { - var solrClient = retrieve_and_rank.createSolrClient(params); - var query = qs.stringify({q: msg.payload}); - node.status({fill: 'blue', shape: 'ring', text: 'Searching' }); - solrClient.search(query,function(err,res) { - node.status({}); - handleWatsonCallback(config.mode,node,msg,err,res); - }); - } else { - var message = 'Missing or invalid search query'; - return node.error(message, msg); - } - break; - } - }); - }); - } - - RED.nodes.registerType('watson-retrieve-rank-credentials', serviceCredentialsConfigurationNode); - RED.nodes.registerType('watson-retrieve-rank-create-cluster', createClusterNode); - - RED.nodes.registerType('watson-retrieve-rank-cluster-settings', clusterSettingsNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-upload-solr-configuration', uploadSolrConfigurationNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-solr-configuration-settings', solrConfigurationSettingsNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-solr-collection', solrCollectionNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-create-ranker', createRankerNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-ranker-settings', rankerSettingsNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - RED.nodes.registerType('watson-retrieve-rank-search-and-rank', searchAndRankNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - - function setupRankRetrieveNode(msg,config,node,callback) { - //Check for payload - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg) - return; - } - - //Check credentials - this.credentials = RED.nodes.getNode(config.servicecreds); - username = username || this.credentials.username; - password = password || this.credentials.password; - - if (!username || !password) { - message = 'Missing Retrieve and Rank service credentials'; - return node.error(message, msg); - } - - //Connect to Watson - var retrieve_and_rank = watson.retrieve_and_rank({ - username: username, - password: password, - version: 'v1', - headers: { - 'User-Agent': pkg.name + '-' + pkg.version - } - }); - - callback(retrieve_and_rank); - } - - function handleWatsonCallback(mode,node,msg,err,res,cb) { - if (err) { - var message = ''; - if (err.description) { - message = err.description; - } else if (err.message) { - message = err.message; - } else if (err.error) { - message = err.error; - } - node.status({}); - return node.error(message, msg); - } else { - (mode == 'delete' && Object.keys(res).length == 0) ? msg.payload = 'Ranker deleted' : msg.payload = res; - if (mode != 'index') { - node.send(msg); - } - if (cb) cb(); - } - } - - function checkRankerStatus(retrieve_and_rank,msg,node,ranker_id) { - var interval = 10000; - //Loop and check the status of the ranker - var statusInterval = setInterval(function(){ - var params = { - ranker_id: ranker_id - }; - retrieve_and_rank.rankerStatus(params, function(err, res) { - if (err) { - node.status({}); - console.log(err); - var message = 'Ranker training state error: '+err.error; - clearInterval(statusInterval); - return node.error(message, msg); - } else { - switch (res.status) { - case 'Available': - node.status({fill:'green',shape:'ring',text:'Ranker available'}); - return clearInterval(statusInterval); - break; - - case 'Training': - break; - - default: - node.status({}); - var message = 'Ranker training status: '+res.status+', description: '+res.status_description; - clearInterval(statusInterval); - return node.error(message, msg); - } - } - }); - },interval); - } - - - function checkClusterStatus(retrieve_and_rank,msg,node,cluster_id) { - var interval = 60000; - //Loop and check the status of the ranker - var statusInterval = setInterval(function(){ - var params = { - cluster_id: cluster_id - }; - retrieve_and_rank.pollCluster(params, function(err, res) { - if (err) { - node.status({}); - var message = 'Cluster creation state error: '+err.error; - clearInterval(statusInterval); - return node.error(message, msg); - } else { - - switch (res.solr_cluster_status) { - case 'READY': - node.status({fill:'green',shape:'ring',text:'Cluster available'}); - return clearInterval(statusInterval); - break; - - case 'NOT_AVAILABLE': - break; - - default: - node.status({}); - var message = 'Cluster status: '+res.status+', description: '+res.status_description; - clearInterval(statusInterval); - return node.error(message, msg); - } - } - }); - },interval); - } -}; diff --git a/services/similarity_search/icons/VR-v3-25x25-old.png b/services/similarity_search/icons/VR-v3-25x25-old.png deleted file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000b diff --git a/services/similarity_search/icons/VR-v3-pink.png b/services/similarity_search/icons/VR-v3-pink.png deleted file mode 100644 index a9f654d41794bd7154a2bf170d46f640eee32f7b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8809 zcmXwf2|QHo_xMGrM449W?wI&Z{hoQ~W~?LicLcf@1XwgVvRcv zK>GPrdVQLjSqWNo$-JB}ArYaWe=Fj5_~*Iy=>?CFotU)GbKkx!{QGD%=Hy6cwdaKW zxb@$`mmxBTigU9}A?UrTjvUzWuYYIZBPi4ts81Q=zeoMuzG2UHTZ4^WwtDR~Mh!Q!>u@Vr&juj=9 zliiien3A*RvvzxW11|hTg1{_C^DX|_2z842Y<-$O%A`UKbCL9N-TXt@;tRGrC=;Wt zo7;FX5m!Sb#4ujL%6tRgciyX4o1dT4P-X2v67oZz@X!nj8D8iAE=`YrEwCs}(nW1) z_-BAKf0qvHqWnK5hPBncxZ8QIzkpdr0AgfR=4cdqcu1TB74L; zEI$#WHCY*>Qlq2R-c(sjExUY;xj}SbwHmLG&l^sew0gr&EcUJzV`H)mO!Bv2$cWM& zX>T%-@>t4a+ccU)nI!Jm6X0-$Cj*o6QNkP|{j{us5C{uBK@x&^0_dhi^~2{Jg&32a z`bWWs?tFMI3Vt z&EKYiPsHJ+3Ht;WT~)6OfuUK6g=)VCwYBJeUhcHA)({l6xS`l=%EcU-@v^!7l9mZt zN=bl|-a{irYLHh#%2+fouoCVuSVL8{$m4=iik^ubJ8#>pKG7EIXWv62synZFHe%K2%EndsjxF zxc!pu2zUV?T=8goX0=pk)SBR+)f}t+{!xDy5czI_E-sCqklFweFFhHo z^h(-%0(ivhCXeoW#6sva3G8?Ce_X5)vjx@!SWJmYSyiU79I7+t12cHCS)FJ?J0ysW zV>`e2Lg|NgxCOe4k6_^s0M4zUE_{cC5rPR2EsZwOr3=+|w&?=e5~Cq>094X6_mnp= z1)whLqlPDgs7b-CKz%V8pf2O1xhJD2>c&6Kk75}C$)~FgQ%L!93&m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(d(H%O5UixIr`T2ZRcd@(^xB>_oNB=7(L1MNvf zK~zW$tyar#OmP(c?#!K;JJJ^IG?*5xN{C8OuLvu47Gf*JE3pz*Y*=_Dx|U#LODrT- zR^kt!iP%W%of46Hm9})IGo87<@7#OGosy=dC;8p`yXWzJ=bYbT#@Tpp)Zf;SKw}c{ z5r`AM|K$~7BpCdo0`&c?!ri|pi9_8Uz88H|eIJScVFg8pTN;x&9&!zF-+i$J!=e zB^)60MPj7&P04U{kl;PD8)9&tp0YD(3tFIxD?WB-9jwk-uJBw3n-|L?6lF{aNP@Xl zp{(c8xRhg%ed}#^ak?dm58QoAV%|Skg+Lz^d_4W6D4;~rz9G&-@aRkgDVR&p7PX;; zPR|(JyVS+Wo-BTntng?YSHD%Uf(!AMtsNmrs}kY7w|@eIBUOyB>dPM{ks^7SYZXZy zi8e-#V}JygSi$iPSH^LXPHTUrYQB`duy1>?z9u{zut-HG}gFUMW`B~K=s4A(UhjI1oqB5MSMtUp74YgB|vQoEk%j@O2>sOVY3Gm`IGBYobh*v>v+R4ZK$JOzL3F6d7YDbafjp zZSFV~oeL9qvOR0eR=|{?*?uZlZHUfh7XxgcTVh!{eCy*^>}*k|@z>hAwpGa*we8;; zRL`PHbQYuY=(^kqwU4=AsORH8;2()GUU0(&_Kft}5Ocw!N`#~2h41w6&)r)7dvIup mj8l@C^=E{`UwQQNx8@fT;$lVphS3TD0000 - - - - - - - - - - - - diff --git a/services/similarity_search/v3.js b/services/similarity_search/v3.js deleted file mode 100644 index 25921d3c..00000000 --- a/services/similarity_search/v3.js +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Copyright 2013,2015, 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'visual-recognition'; - var pkg = require('../../package.json'), - serviceutils = require('../../utilities/service-utils'), - watson = require('watson-developer-cloud'), - imageType = require('image-type'), - temp = require('temp'), - fileType = require('file-type'), - fs = require('fs'), - sAPIKey = null, - service = null; - - // temp is being used for file streaming to allow the file to arrive so it can be processed. - temp.track(); - - service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER); - - if (service) { - sAPIKey = service.api_key; - } - - RED.httpAdmin.get('/watson-similarity-search/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function imageCheck(data) { - return data instanceof Buffer && imageType(data) !== null; - } - - function stream_buffer(file, contents, cb) { - fs.writeFile(file, contents, function (err) { - if (err) { - throw err; - } - cb(); - }); - } - - function verifyServiceCredentials(node, msg) { - // If it is present the newly provided user entered key - // takes precedence over the existing one. - node.apikey = sAPIKey || node.credentials.apikey; - if (!node.apikey) { - node.status({fill:'red', shape:'ring', text:'missing credentials'}); - node.error('Missing Watson Visual Recognition API service credentials', msg); - return false; - } - node.service = watson.visual_recognition({ - api_key: node.apikey, - version: 'v3', - version_date: '2016-05-20', - headers: { - 'User-Agent': pkg.name + '-' + pkg.version - } - }); - return true; - } - - function processResponse(err, body, feature, node, msg) { - if (err != null && body == null) { - node.status({fill:'red', shape:'ring', - text:'call to watson similarity search v3 service failed'}); - msg.payload = {}; - if (err.code === null) { - msg.payload.error = err; - } else { - msg.payload.error_code = err.code; - if (!err.error) { - msg.payload.error = err.error; - } - } - node.error(err); - return; - } else if (err == null && body != null && body.images != null && - body.images[0] && body.images[0].error) { - node.status({fill:'red', shape:'ring', - text:'call to watson visual recognition v3 service failed'}); - msg.payload = {}; - msg.payload.error_id = body.images[0].error.error_id; - msg.payload.error = body.images[0].error.description; - node.send(msg); - } else { - if (feature === 'deleteClassifier') { - msg.payload = 'Successfully deleted classifier_id: ' + msg.params.classifier_id ; - } else { - msg.payload = body; - } - node.send(msg); - node.status({}); - } - } - - function processImage(params, node, feature, cb, msg) { - var image = params.image_file; - if (imageCheck(image)) { - temp.open({suffix: '.' + fileType(image).ext}, function (err, info) { - if (err) { - this.status({fill:'red', shape:'ring', text:'unable to open image stream'}); - node.error('Node has been unable to open the image stream', msg); - return cb(feature, params); - } - - stream_buffer(info.path, image, function () { - params.image_file = fs.createReadStream(info.path); - cb(feature, params); - }); - }); - } else { - node.status({fill:'red', shape:'ring', text:'payload is invalid'}); - node.error('Payload must be an image buffer', msg); - } - } - - function addParams(params, msg, paramsToAdd) { - var i = null, - param = null; - - for (i in paramsToAdd) { - if (paramsToAdd.hasOwnProperty(i)) { - param = paramsToAdd[i]; - if (param === 'image_file') { - params.image_file = msg.payload; - } else { - params[param] = msg.params[param]; - } - } - } - return params; - } - - function executeService(feature, params, node, msg) { - var requiredParams = { - findSimilar: ['collection_id', 'image_file'], - createCollection: ['name'], - getCollection: ['collection_id'], - listCollections: [], - deleteCollection: ['collection_id'], - addImage: ['collection_id','image_file'], - listImages: ['collection_id'], - getImage: ['collection_id','image_id'], - deleteImage: ['collection_id','image_id'], - setImageMetadata: ['collection_id', 'image_id', 'metadata'], - getImageMetadata: ['collection_id', 'image_id'], - deleteImageMetadata: ['collection_id', 'image_id'] - }, - optionalParams = { - findSimilar: ['limit'], - addImage: ['metadata'] - }; - params = addParams(params, msg, requiredParams[feature]); - - if (feature in optionalParams) { - params = addParams(params, msg, optionalParams[feature]); - } - - function callWatson(feature, params) { - node.service[feature](params, function (err, body) { - processResponse(err, body, feature, node, msg); - }); - } - - if ('image_file' in params) { - processImage(params, node, feature, callWatson, msg); - } else { - callWatson(feature, params); - } - } - - function execute(feature, params, node, msg) { - node.status({fill:'blue', shape:'dot' , text:'Calling ' + feature + ' ...'}); - executeService(feature, params, node, msg); - } - - // This is the Watson Visual Recognition V3 Node - function SimilaritySearchV3Node (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 = {}; - - node.status({}); - // so there is at most 1 temp file at a time (did not found a better solution...) - temp.cleanup(); - - b = verifyServiceCredentials(node, msg); - if (!b) { - return; - } - execute(feature,params,node,msg); - }); - } - - RED.nodes.registerType('similarity-search-v3', SimilaritySearchV3Node, { - credentials: { - apikey: {type:'password'} - } - }); - - RED.nodes.registerType('similarity-search-util-v3', SimilaritySearchV3Node, { - credentials: { - apikey: {type:'password'} - } - }); - -}; From 6426fba9ebf0a8295106d1cba358a552de38f275 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:45:57 +0000 Subject: [PATCH 08/11] Remove redundant nodes --- .../icons/tradeoff_analytics.png | Bin 3719 -> 0 bytes services/tradeoff_analytics/v1.html | 89 ------------------ services/tradeoff_analytics/v1.js | 87 ----------------- services/visual_insights/icons/temp.txt | 17 ---- services/visual_insights/temp.txt | 17 ---- 5 files changed, 210 deletions(-) delete mode 100644 services/tradeoff_analytics/icons/tradeoff_analytics.png delete mode 100644 services/tradeoff_analytics/v1.html delete mode 100644 services/tradeoff_analytics/v1.js delete mode 100644 services/visual_insights/icons/temp.txt delete mode 100644 services/visual_insights/temp.txt diff --git a/services/tradeoff_analytics/icons/tradeoff_analytics.png b/services/tradeoff_analytics/icons/tradeoff_analytics.png deleted file mode 100644 index f7ac7670f5fa14a6dc60a66a41d8734bee701bdc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3719 zcmV;24tVj2P)P000#T1^@s6vnxdy000U>X+uL$Nkc;* zP;zf(X>4Tx07wm;mUmQB*%pV-y*Itk5+Wca^cs2zAksTX6$DXM^`x7XQc?|s+0 z08spb1j2M!0f022SQPH-!CVp(%f$Br7!UytSOLJ{W@ZFO_(THK{JlMynW#v{v-a*T zfMmPdEWc1DbJqWVks>!kBnAKqMb$PuekK>?0+ds;#ThdH1j_W4DKdsJG8Ul;qO2n0 z#IJ1jr{*iW$(WZWsE0n`c;fQ!l&-AnmjxZO1uWy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M(RhcN6(D;jNN*%^u_SYjF;2ng}*8Ow)d6M ztDk;%`@Lsk$;9w$(d(H%O5UixIr`T2ZRcd@(^xB>_oNB=7(L1MEpe zK~zW$omER~6j>Dhs_IsEI^F4XUdH$cj+zmCAZ|p_m5X7P^CJfQ8zQ*z2Z*?EBe*mU zZd6 z@NpMLphNs7iE52=zRLTF56Qj3ztoPYxU>lT^*1nDOw_cu_#DU$1IJD<$}ZdtkDC0J zgBayjj7k_=ql${^gGE3dX{zl2Z{GqVq)4KDmpAh?uv`X$wx!ecbr=D+j`(2zeg|4gi^~)e|e2$U4@5=DCam+9efTEQLUkfXdJAh_p$- zYz{biDmkpyNKXK4lfsb^=Hqxm9V2sapC!yZ+&`7Y`Taf~{TpC$Gs4gN4W6uYaQ%IR zY2U$`Sdka~q8zNf1K#|@yiiRDspa#G!9M9fKp^o68v-yxXU0+o95!5-Y0~^J{ za)7IAtROnK&ijtTI9!3rATuRz+wAfbv`xBHQHB?W=y++8a|3hxb%?of4|{2B{#6?b z^#~WAweZu60FT=Qa}CDG0O+1A+SNHZ@;yjNlwIT&vq9Ja=$!JC=9n zn1cm^7JL_Vh8>3yoG3u4-N0s}4nxpb;Y(DS0vl$M<+0DTXiFnhuh_m3kF4C82i155 zR0unm>9+BKZ;?+=iv+KRA?oDa6=XeTA>=RIkxkS?YF0pijd9F&;hmAdgB@ z@CfQ;5>VG(=Ds+Wm!fKWgSp_VTVn-HvTT+7|3d!4m=U+$!J~ - - - - - - diff --git a/services/tradeoff_analytics/v1.js b/services/tradeoff_analytics/v1.js deleted file mode 100644 index c9ea6cb2..00000000 --- a/services/tradeoff_analytics/v1.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - var cfenv = require('cfenv'); - - var services = cfenv.getAppEnv().services, - service; - - var username, password; - - var service = cfenv.getAppEnv().getServiceCreds(/tradeoff analytics/i) - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-tradeoff-analytics/vcap', function(req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function Node(config) { - RED.nodes.createNode(this,config); - var node = this; - - this.on('input', function(msg) { - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - username = username || this.credentials.username; - password = password || this.credentials.password; - - if (!username || !password) { - var message = 'Missing Tradeoff Analytics service credentials'; - node.error(message, msg); - return; - } - - var watson = require('watson-developer-cloud'); - - var tradeoff_analytics = watson.tradeoff_analytics({ - username: username, - password: password, - version: 'v1' - }); - - node.status({fill:"blue", shape:"dot", text:"requesting"}); - tradeoff_analytics.dilemmas({ - subject: msg.payload, - columns: msg.columns, - options: msg.options - }, function (err, response) { - node.status({}); - if (err) - node.error(err, msg); - else - msg.resolution = response.resolution; - - console.log(JSON.stringify(msg.resolution)) - node.send(msg); - }); - }); - } - RED.nodes.registerType("watson-tradeoff-analytics",Node, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); -}; diff --git a/services/visual_insights/icons/temp.txt b/services/visual_insights/icons/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/visual_insights/icons/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/visual_insights/temp.txt b/services/visual_insights/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/visual_insights/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - From 2414fd8f497ca66626a6a82c745f7f3d5426ef55 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:54:36 +0000 Subject: [PATCH 09/11] Remove dependancy on watson-developer-cloud --- ChangeHistory.md | 52 +++++++++++++++++++++++++++++++++++ README.md | 47 ------------------------------- package.json | 1 - services/speech_to_text/v1.js | 8 +++--- 4 files changed, 56 insertions(+), 52 deletions(-) diff --git a/ChangeHistory.md b/ChangeHistory.md index ff41f978..bd051b11 100644 --- a/ChangeHistory.md +++ b/ChangeHistory.md @@ -1,3 +1,55 @@ +## 0.8.x + +### New in version 0.8.2 +- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of + - Document Translator node + - Discovery node + - Discovery Document Loader node + - Discovery Query Builder node + - Assistant V1 Workspace Manager node +- List Expansion list, and List Training data modes added to Discovery node +- Fix to Create Classifier mode in NLC node + +### New in version 0.8.1 +- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of + - Speech to Text node + - Speech to Text Corpus Builder node + - Natural Language Understanding node + - Natural Language Classifier node + - Language Identifier node + - Language Translator node + - Translator Util node +- New NLU Model Manager node. +- NLC CreateClassifier is broken until defect on ibm-watson is fixed. +- Remove X-Watson-Technology-Preview Neural translation option for Language Translator node +- Remove monolingual corpus option from Language Translator mode +- Added new modes to Language Translator mode + - List Custom models + - List Default models + +### New in version 0.8.0 +- In the 0.8.x releases the nodes are migrated to a node-red 1.0.x input +event callback function signature. +and migrated off watson-developer-cloud to ibm-watson as a npm dependancy. +Migrated nodes will not be compatible with pre 1.0.0 versions of node-red. +During the migration there will be a dependancy on both modules. +- Bump dependancy on node to >=10.0.0 +- Bump dependancy on cfenv, request, file-type +- Bump dependancy on ibm-cloud-sdk-core to 0.3.7 (need to stay on 0.x, for STT Streaming to work) +- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of + - Tone Analyzer node. + - Personality Insights node. + - Visual Recognition V3 node + - Text to Speech node + - Text to Speech Corpus Builder node +- New Visual Recognition V4 node. +- Drop faces detect option from Visual Recognition V3 node. +- Fix to URL parsing for bound services. +- STT token manager no longer in ibm-cloud-sdk-core +- Update language lists for STT, TTS, Language Translator and Document Translator Nodes + + + ## 0.7.x ### New in version 0.7.8 diff --git a/README.md b/README.md index 6a8e7945..103a535b 100644 --- a/README.md +++ b/README.md @@ -15,53 +15,6 @@ Node-RED Watson Nodes for IBM Cloud - Remove watson-developer-cloud dependancy - Remove code for redundant nodes -### New in version 0.8.2 -- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of - - Document Translator node - - Discovery node - - Discovery Document Loader node - - Discovery Query Builder node - - Assistant V1 Workspace Manager node -- List Expansion list, and List Training data modes added to Discovery node -- Fix to Create Classifier mode in NLC node - -### New in version 0.8.1 -- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of - - Speech to Text node - - Speech to Text Corpus Builder node - - Natural Language Understanding node - - Natural Language Classifier node - - Language Identifier node - - Language Translator node - - Translator Util node -- New NLU Model Manager node. -- NLC CreateClassifier is broken until defect on ibm-watson is fixed. -- Remove X-Watson-Technology-Preview Neural translation option for Language Translator node -- Remove monolingual corpus option from Language Translator mode -- Added new modes to Language Translator mode - - List Custom models - - List Default models - -### New in version 0.8.0 -- In the 0.8.x releases the nodes are migrated to a node-red 1.0.x input -event callback function signature. -and migrated off watson-developer-cloud to ibm-watson as a npm dependancy. -Migrated nodes will not be compatible with pre 1.0.0 versions of node-red. -During the migration there will be a dependancy on both modules. -- Bump dependancy on node to >=10.0.0 -- Bump dependancy on cfenv, request, file-type -- Bump dependancy on ibm-cloud-sdk-core to 0.3.7 (need to stay on 0.x, for STT Streaming to work) -- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of - - Tone Analyzer node. - - Personality Insights node. - - Visual Recognition V3 node - - Text to Speech node - - Text to Speech Corpus Builder node -- New Visual Recognition V4 node. -- Drop faces detect option from Visual Recognition V3 node. -- Fix to URL parsing for bound services. -- STT token manager no longer in ibm-cloud-sdk-core -- Update language lists for STT, TTS, Language Translator and Document Translator Nodes ### Watson Nodes for Node-RED A collection of nodes to interact with the IBM Watson services in [IBM Cloud](http://cloud.ibm.com). diff --git a/package.json b/package.json index f818672f..dfc706c0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "temp": "^0.9.0", "qs": "6.x", "image-type": "^2.0.2", - "watson-developer-cloud": "^3.18.3", "ibm-watson": "^5.2.1", "word-count": "^0.2.2", "is-docx": "^0.0.3", diff --git a/services/speech_to_text/v1.js b/services/speech_to_text/v1.js index d9c2b06c..874daf8d 100644 --- a/services/speech_to_text/v1.js +++ b/services/speech_to_text/v1.js @@ -27,7 +27,7 @@ module.exports = function (RED) { payloadutils = require('../../utilities/payload-utils'), iamutils = require('../../utilities/iam-utils'), sttutils = require('./stt-utils'), - AuthV1 = require('watson-developer-cloud/authorization/v1'), + //AuthV1 = require('watson-developer-cloud/authorization/v1'), //AuthIAMV1 = require('ibm-cloud-sdk-core/iam-token-manager/v1'), //AuthIAMV1 = require('ibm-cloud-sdk-core/auth/iam-token-manager-v1'), //AuthIAMV1 = require('ibm-cloud-sdk-core/auth/token-managers/iam-token-manager'), @@ -342,9 +342,9 @@ module.exports = function (RED) { tokenService = new IamTokenManager({apikey : apikey}); //tokenService = new iamutils(apikey); - } else { - tokenService = new AuthV1(stt.getCredentials()); - } + } //else { + //tokenService = new AuthV1(stt.getCredentials()); + //} // Streaming - IAM Key fudge. // Check if the token service options have the header set. If not then From d6025008e21a1459e5416f3ea4f58898f4be0d65 Mon Sep 17 00:00:00 2001 From: chughts Date: Thu, 23 Jan 2020 22:56:13 +0000 Subject: [PATCH 10/11] Remove dependancy on watson-developer-cloud --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 103a535b..6b5accd8 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,4 @@ before doing so. ### Copyright and license -Copyright 2018 IBM Corp. under [the Apache 2.0 license](LICENSE). +Copyright 2018, 2019, 2020 IBM Corp. under [the Apache 2.0 license](LICENSE). From 4f331c00c44fe45edffb82bd0cc520e4923d6ba9 Mon Sep 17 00:00:00 2001 From: chughts Date: Fri, 24 Jan 2020 15:29:06 +0000 Subject: [PATCH 11/11] Remove redundant nodes --- services/assistant/v1-exp.html | 116 -------- services/assistant/v1-exp.js | 146 --------- services/authorization/temp.txt | 17 -- services/discovery/v1-exp.html | 216 -------------- services/discovery/v1-exp.js | 164 ---------- services/personality_insights/v1.html | 98 ------ services/personality_insights/v1.js | 94 ------ services/tone_analyzer/v3-beta.html | 102 ------- services/tone_analyzer/v3-beta.js | 110 ------- services/visual_recognition/v1.html | 411 -------------------------- services/visual_recognition/v1.js | 368 ----------------------- 11 files changed, 1842 deletions(-) delete mode 100644 services/assistant/v1-exp.html delete mode 100644 services/assistant/v1-exp.js delete mode 100644 services/authorization/temp.txt delete mode 100644 services/discovery/v1-exp.html delete mode 100644 services/discovery/v1-exp.js delete mode 100644 services/personality_insights/v1.html delete mode 100644 services/personality_insights/v1.js delete mode 100644 services/tone_analyzer/v3-beta.html delete mode 100644 services/tone_analyzer/v3-beta.js delete mode 100644 services/visual_recognition/v1.html delete mode 100644 services/visual_recognition/v1.js diff --git a/services/assistant/v1-exp.html b/services/assistant/v1-exp.html deleted file mode 100644 index ef6803a1..00000000 --- a/services/assistant/v1-exp.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - diff --git a/services/assistant/v1-exp.js b/services/assistant/v1-exp.js deleted file mode 100644 index d0fd1604..00000000 --- a/services/assistant/v1-exp.js +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'), watson = require('watson-developer-cloud'), service = null, - sUsername = null, sPassword = null; - - service = cfenv.getAppEnv().getServiceCreds(/conversation/i); - - if (service) { - sUsername = service.username; - sPassword = service.password; - } - - RED.httpAdmin.get('/watson-conversation/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - - function verifyPayload(node, msg) { - if (!msg.payload) { - this.status({fill:'red', shape:'ring', text:'missing payload'}); - node.error('Missing property: msg.payload', msg); - return false; - } - return true; - } - - function verifyInputs(node, msg, config) { - // workspaceid can be either configured in the node, - // or sent into msg.params.workspace_id - if (config.workspaceid && config.workspaceid) { - node.workspaceid = config.workspaceid; - console.log('node.workspaceid', node.workspaceid); - return true; - } - if (msg.params && msg.params.workspace_id) { - node.workspaceid = msg.params.workspace_id; - console.log('node.workspaceid', node.workspaceid); - return true; - } - node.error('Missing workspace_id. check node documentation.',msg); - return false; - } - - function verifyServiceCredentials(node, msg) { - // If it is present the newly provided user entered key - // takes precedence over the existing one. - var userName = sUsername || node.credentials.username, - passWord = sPassword || node.credentials.password; - - if (!userName || !passWord) { - node.status({fill:'red', shape:'ring', text:'missing credentials'}); - node.error('Missing Watson Conversation API service credentials', msg); - return false; - } - node.service = watson.conversation({ - username: userName, - password: passWord, - version_date: '2016-05-19', - version: 'v1-experimental' - }); - return true; - } - - function processResponse(err, body, node, msg) { - if (err != null && body == null) { - node.status({fill:'red', shape:'ring', - text:'call to watson conversation service failed'}); - msg.result = {}; - if (err.code == null) { - msg.result['error'] = err; - } else { - msg.result['error_code'] = err.code; - if (!err.error) { - msg.result['error'] = err.error; - } - } - node.error(err); - return; - } - msg.result = body; - msg.payload = 'see msg.result'; - node.send(msg); - node.status({}); - } - - function execute(params, node, msg) { - node.status({fill:'blue', shape:'dot' , text:'Calling Conversation service ...'}); - params.workspace_id = node.workspaceid; - params.input = {text:msg.payload}; - // call POST /message through SDK - node.service.message(params, function(err, body) { - processResponse(err,body,node,msg); - }); - } - - // This is the Watson Visual Recognition V3 Node - function WatsonConversationV1ExpNode (config) { - var node = this, b = false; - - RED.nodes.createNode(this, config); - - node.on('input', function (msg) { - var params = {}; - - node.status({}); - - b = verifyPayload(node, msg); - if (!b) { - return; - } - b = verifyInputs(node, msg, config); - if (!b) { - return; - } - b = verifyServiceCredentials(node, msg); - if (!b) { - return; - } - execute(params,node,msg); - }); - } - - RED.nodes.registerType('watson-conversation-v1-experimental', WatsonConversationV1ExpNode, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); - - -}; diff --git a/services/authorization/temp.txt b/services/authorization/temp.txt deleted file mode 100644 index 5435a16f..00000000 --- a/services/authorization/temp.txt +++ /dev/null @@ -1,17 +0,0 @@ -temp text file - - - - - - - - - - - - - - - - diff --git a/services/discovery/v1-exp.html b/services/discovery/v1-exp.html deleted file mode 100644 index 0106afb7..00000000 --- a/services/discovery/v1-exp.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - diff --git a/services/discovery/v1-exp.js b/services/discovery/v1-exp.js deleted file mode 100644 index 8a2b6ac2..00000000 --- a/services/discovery/v1-exp.js +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Copyright 20016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - - const SERVICE_IDENTIFIER = 'discovery'; - var discoveryutils = require('./discovery-utils'), - DiscoveryV1Experimental = require('watson-developer-cloud/discovery/v1-experimental'), - serviceutils = require('../../utilities/service-utils'), - dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), - username = null, - password = null, - sUsername = null, - sPassword = null; - - - function checkParams(method, params){ - var response = ''; - switch (method) { - case 'getEnvironmentDetails': - case 'listCollections': - response = discoveryutils.paramEnvCheck(params); - break; - case 'getCollectionDetails': - response = discoveryutils.paramEnvCheck(params) + - discoveryutils.paramCollectionCheck(params); - break; - } - return response; - } - - function executeListEnvrionments(node, discovery, params, msg) { - discovery.getEnvironments(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.environments = response.environments ? response.environments : []; - } - node.send(msg); - }); - } - - function executeEnvrionmentDetails(node, discovery, params, msg) { - discovery.getEnvironment(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.environment_details = response; - } - node.send(msg); - }); - } - - function executeListCollections(node, discovery, params, msg) { - discovery.getCollections(params, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.collections = response.collections ? response.collections : []; - } - node.send(msg); - }); - } - - function executeGetCollectionDetails(node, discovery, params, msg) { - discovery.getCollection(params, params.collection_id, function (err, response) { - node.status({}); - if (err) { - discoveryutils.reportError(node, msg, err.error); - } else { - msg.collection_details = response; - } - node.send(msg); - }); - } - - function executeMethod(node, method, params, msg) { - var discovery = new DiscoveryV1Experimental({ - username: username, - password: password, - version_date: '2016-11-07' - }); - - switch (method) { - case 'listEnvrionments': - executeListEnvrionments(node, discovery, params, msg); - break; - case 'getEnvironmentDetails': - executeEnvrionmentDetails(node, discovery, params, msg); - break; - case 'listCollections': - executeListCollections(node, discovery, params, msg); - break; - case 'getCollectionDetails': - executeGetCollectionDetails(node, discovery, params, msg); - break; - } - - } - - if (dservice) { - sUsername = dservice.username; - sPassword = dservice.password; - } - - RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) { - res.json(serviceutils.checkServiceBound(SERVICE_IDENTIFIER)); - }); - - - function Node (config) { - var node = this; - RED.nodes.createNode(this, config); - - this.on('input', function (msg) { - var method = config['discovery-method'], - message = '', - params = {}; - - username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password; - - if (!username || !password) { - message = 'Missing Watson Discovery service credentials'; - } else if (!method || '' === method) { - message = 'Required Discovery method has not been specified'; - } else { - params = discoveryutils.buildParams(msg,config); - message = checkParams(method, params); - } - - if (message) { - discoveryutils.reportError(node,msg,message); - return; - } - - node.status({fill:'blue', shape:'dot', text:'requesting'}); - executeMethod(node, method, params, msg); - }); - } - - RED.nodes.registerType('watson-discovery', Node, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); -}; diff --git a/services/personality_insights/v1.html b/services/personality_insights/v1.html deleted file mode 100644 index 9ba4a626..00000000 --- a/services/personality_insights/v1.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - diff --git a/services/personality_insights/v1.js b/services/personality_insights/v1.js deleted file mode 100644 index 8c5a792c..00000000 --- a/services/personality_insights/v1.js +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright 2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'), - payloadutils = require('../../utilities/payload-utils'); - - var services = cfenv.getAppEnv().services, - service; - - var username, password; - - var service = cfenv.getAppEnv().getServiceCreds(/personality insights/i) - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-personality-insights/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function Node(config) { - RED.nodes.createNode(this,config); - var node = this, - wc = payloadutils.word_count(config.lang); - - this.on('input', function (msg) { - var self = this; - - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg) - return; - } - wc(msg.payload, function (length) { - if (length < 100) { - var message = 'Personality insights requires a minimum of one hundred words.'; - node.error(message, msg); - return; - } - - username = username || self.credentials.username; - password = password || self.credentials.password; - - if (!username || !password) { - var message = 'Missing Personality Insights service credentials'; - node.error(message, msg); - return; - } - - var PersonalityInsightsV2 = require('watson-developer-cloud/personality-insights/v2'); - - var personality_insights = new PersonalityInsightsV2({ - username: username, - password: password - }); - - node.status({fill:"blue", shape:"dot", text:"requesting"}); - personality_insights.profile({text: msg.payload, language: config.lang}, function (err, response) { - node.status({}) - if (err) { - node.error(err, msg); - } else{ - msg.insights = response.tree; - } - - node.send(msg); - }); - - }); - }); - } - RED.nodes.registerType("watson-personality-insights",Node,{ - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); -}; diff --git a/services/tone_analyzer/v3-beta.html b/services/tone_analyzer/v3-beta.html deleted file mode 100644 index 3a31aa23..00000000 --- a/services/tone_analyzer/v3-beta.html +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - diff --git a/services/tone_analyzer/v3-beta.js b/services/tone_analyzer/v3-beta.js deleted file mode 100644 index 8b415491..00000000 --- a/services/tone_analyzer/v3-beta.js +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright 2013,2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function (RED) { - var cfenv = require('cfenv'); - - var services = cfenv.getAppEnv().services, - service; - - var username, password; - - var service = cfenv.getAppEnv().getServiceCreds(/tone analyzer/i) - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-tone-analyzer/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function Node (config) { - RED.nodes.createNode(this, config); - var node = this; - - this.on('input', function (msg) { - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - username = username || this.credentials.username; - password = password || this.credentials.password; - - if (!username || !password) { - var message = 'Missing Tone Analyzer service credentials'; - node.error(message, msg); - return; - } - - var watson = require('watson-developer-cloud'); - - var tone_analyzer = watson.tone_analyzer({ - username: username, - password: password, - version: 'v3-beta', - version_date: '2016-02-11' - }); - - var hasJSONmethod = (typeof msg.payload.toJSON === 'function') ; - var isBuffer = false; - if (hasJSONmethod==true) - { - if (msg.payload.toJSON().type == 'Buffer') - isBuffer=true; - } - - // Payload (text to be analysed) must be a string (content is either raw string or Buffer) - if (typeof msg.payload == 'string' || isBuffer == true ) - { - var options = { - text: msg.payload, - sentences: config.sentences - }; - - if (config.tones !== 'all') { - options.tones = config.tones; - } - - node.status({fill:'blue', shape:'dot', text:'requesting'}); - tone_analyzer.tone(options, function (err, response) { - node.status({}) - if (err) { - node.error(err, msg); - } else { - msg.response = response; - } - - node.send(msg); - }); - } - else { - var message = 'The payload must be either a string or a Buffer'; - node.status({fill:'red', shape:'dot', text:message}); - node.error(message, msg); - } - }); - } - RED.nodes.registerType('watson-tone-analyzer', Node, { - credentials: { - username: {type:'text'}, - password: {type:'password'} - } - }); -}; diff --git a/services/visual_recognition/v1.html b/services/visual_recognition/v1.html deleted file mode 100644 index 16b0400c..00000000 --- a/services/visual_recognition/v1.html +++ /dev/null @@ -1,411 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/services/visual_recognition/v1.js b/services/visual_recognition/v1.js deleted file mode 100644 index e3344893..00000000 --- a/services/visual_recognition/v1.js +++ /dev/null @@ -1,368 +0,0 @@ -/** - * Copyright 2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - var request = require('request'); - var cfenv = require('cfenv'); - var fs = require('fs'); - var temp = require('temp'); - var fileType = require('file-type'); - var watson = require('watson-developer-cloud'); - - temp.track(); - - var username, password; - - var service = cfenv.getAppEnv().getServiceCreds(/visual recognition/i) - - if (service) { - username = service.username; - password = service.password; - } - - RED.httpAdmin.get('/watson-visual-recognition/vcap', function(req, res) { - res.json(service ? {bound_service: true} : null); - }); - - function Node(config) { - RED.nodes.createNode(this,config); - var node = this; - - this.on('input', function(msg) { - if (!msg.payload) { - var message = 'Missing property: msg.payload'; - node.error(message, msg); - return; - } - - if (!msg.payload instanceof Buffer || !typeof msg.payload === 'string') { - var message = 'Invalid property: msg.payload, must be a URL or a Buffer.'; - node.error(message, msg); - return; - } - - username = username || this.credentials.username; - password = password || this.credentials.password; - - if (!username || !password) { - var message = 'Missing Visual Recognition service credentials'; - node.error(message, msg) - return; - } - - var watson = require('watson-developer-cloud'); - - var visual_recognition = watson.visual_recognition({ - username: username, - password: password, - version: 'v1-beta' - }); - - var file_extension = function (file) { - var ext = '.jpeg'; - - // For URLs, look for file extension in the path, default to JPEG. - if (typeof file === 'string') { - var match = file.match(/\.[\w]{3,4}$/i) - ext = match && match[0] - // ...for Buffers, we can look at the file header. - } else if (file instanceof Buffer) { - ext = '.' + fileType(file).ext; - } - - return ext; - } - - var recognize = function (image, cb) { - node.status({fill:"blue", shape:"dot", text:"requesting"}); - visual_recognition.recognize({image_file: image}, function(err, res) { - node.status({}) - if (err) { - node.error(err, msg); - } else { - msg.labels = res.images && res.images[0].labels; - } - - node.send(msg); - if (cb) cb(); - }); - } - - var stream_buffer = function (file, contents, cb) { - fs.writeFile(file, contents, function (err) { - if (err) throw err; - cb(); - }); - }; - - var stream_url = function (file, location, cb) { - var wstream = fs.createWriteStream(file) - wstream.on('finish', cb); - - request(location) - .pipe(wstream); - }; - - temp.open({suffix: file_extension(msg.payload)}, function (err, info) { - if (err) throw err; - - var stream_payload = (typeof msg.payload === 'string') ? stream_url : stream_buffer; - - stream_payload(info.path, msg.payload, function () { - recognize(fs.createReadStream(info.path), temp.cleanup); - }); - }); - }); - } - - RED.nodes.registerType("watson-visual-recognition",Node, { - credentials: { - username: {type:"text"}, - password: {type:"password"} - } - }); - - var appenv = cfenv.getAppEnv(); - var visual = []; - for (var i in appenv.services) { - if (i.match(/^(visual_recognition)/i)) { - visual = visual.concat(appenv.services[i].map(function(v) { - return { - name: v.name, - label: v.label, - username: v.credentials.username, - password: v.credentials.password, - }; - })); - } - } - - RED.httpAdmin.get('/watson-visual-recognition/vcap', function(req,res) { - res.send(JSON.stringify(visual)); - }); - - RED.httpAdmin.get('/watson-visual-recognition/list/:service', function(req,res) { - - var username,password; - var service = req.params.service; - - for (var i2=0; i2 < visual.length; i2++) { - if (visual[i2].name===service) { - username = visual[i2].username; - password = visual[i2].password; - } - } - - var visual_recognition = watson.visual_recognition({ - username: username, - password: password, - version: 'v2-beta', - version_date: '2015-12-02' - }); - - visual_recognition.listClassifiers({}, - function(err, response) { - if (err) - res.send(err); - else - res.send(JSON.stringify(response)); - } - ); - }); - - function VisualUtilNode(config) { - - RED.nodes.createNode(this,config); - - this.name = config.name; - this.classifier = config.classifier; - this.command = config.command; - this.username = config.username; - this.password = config.password; - this.service = config.service; - - var node = this; - - this.doDelete = function(msg) { - var visual_recognition = watson.visual_recognition({ - username: node.username, - password: node.password, - version: 'v2-beta', - version_date: '2015-12-02' - }); - - visual_recognition.deleteClassifier({ - classifier_id: node.classifier }, - function(err, response) { - if (err) - node.error(err); - else - node.send({"payload": response}); - } - ); - }; - - this.doList = function(msg) { - - var visual_recognition = watson.visual_recognition({ - - username: node.username, - password: node.password, - version: 'v2-beta', - version_date: '2015-12-02' - }); - - visual_recognition.listClassifiers({}, - function(err, response) { - if (err) { - node.error(err); - } else { - node.send({"payload": response}); - } - } - ); - - }; - - this.doDetails = function(msg) { - var visual_recognition = watson.visual_recognition({ - username: node.username, - password: node.password, - version: 'v2-beta', - version_date: '2015-12-02' - }); - - visual_recognition.getClassifier({ - classifier_id: node.classifier }, - function(err, response) { - if (err) - node.error(err); - else - node.send({"payload": response}); - } - ); - }; - - this.on('input', function (msg) { - switch(this.command) { - case "list": - this.doList(msg); - break; - case "details": - this.doDetails(msg); - break; - case "delete": - this.doDelete(msg); - break; - } - }); - - } - - RED.nodes.registerType("watson-visual-util",VisualUtilNode); - - function VisualTrainingNode(config) { - - RED.nodes.createNode(this,config); - - this.name = config.name; - this.classifier = config.classifier; - this.username = config.username; - this.password = config.password; - this.service = config.service; - - var node = this; - - this.doCall = function(msg) { - - var visual_recognition = watson.visual_recognition({ - username: node.username, - password: node.password, - version: 'v2-beta', - version_date: '2015-12-02' - }); - - var stream_buffer = function (file, contents, cb) { - fs.writeFile(file, contents, function (err) { - if (err) { - throw err; - } - cb(fileType(contents).ext); - }); - }; - - var stream_url = function (file, location, cb) { - var wstream = fs.createWriteStream(file); - wstream.on('finish', function () { - fs.readFile(file, function (err, buf) { - if (err) { - throw err; - } - cb(fileType(buf).ext); - }); - }); - request(location).pipe(wstream); - }; - - var stream_positive = (typeof msg.positive === 'string') ? stream_url : stream_buffer; - var stream_negative = (typeof msg.negative === 'string') ? stream_url : stream_buffer; - - temp.open({suffix: '.zip'}, function (err, info) { - if (err) { - throw err; - } - - stream_positive(info.path, msg.positive, function (format) { - - temp.open({suffix: '.zip'}, function (err2, info2) { - if (err2) { - throw err2; - } - - stream_negative(info2.path, msg.negative, function (format) { - - var params = { - name: node.classifier, - positive_examples: fs.createReadStream(info.path), - negative_examples: fs.createReadStream(info2.path) - }; - - node.status({fill:"blue", shape:"dot", text:"training"}); - visual_recognition.createClassifier(params, - function(err, response) { - node.status({}); - if (err) { - node.error(err); - } else { - node.send({"payload" : response}); - } - temp.cleanup(); - } - ); - }); - }); - }); - }); - }; - - this.on('input', function (msg) { - this.doCall(msg); - }); - - } - - RED.nodes.registerType("watson-visual-training",VisualTrainingNode); -};