From b0e1fe6fcaaf9bd5e1484870004f4aa89e968e19 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Tue, 29 Nov 2016 12:58:55 -0500 Subject: [PATCH 1/9] Removed entities/linked (#60) - Removed entities_linked example - Removed linked parameter - Updated entities.js - Updated README - unit tests pass --- README.md | 1 - examples/entities_linked.js | 28 ---------------------------- lib/entities.js | 16 +--------------- lib/parameters.js | 3 --- 4 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 examples/entities_linked.js diff --git a/README.md b/README.md index 8493a43..77c4bab 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ api.rosette(endpoint, function(err, res){ | targetScheme | name translation | No | | options | relationships | No | | accuracyMode | relationships | Yes | -| linked (deprecated) | entities | No | | linkEntities | entities | No | | explain | sentiment | No | | morphology | morphology | Yes | diff --git a/examples/entities_linked.js b/examples/entities_linked.js deleted file mode 100644 index fee129c..0000000 --- a/examples/entities_linked.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; - -var Api = require("../lib/Api"); -var ArgumentParser = require("argparse").ArgumentParser; - -var parser = new ArgumentParser({ - addHelp: true, - description: "Get linked entities from a piece of text" -}); -parser.addArgument(["--key"], {help: "Rosette API key", required: true}); -parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false}); -var args = parser.parseArgs(); -var api = new Api(args.key, args.url); -var endpoint = "entities"; -var entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon."; - -api.parameters.content = entities_linked_text_data; -// this parameter is deprecated -api.parameters.linked = true; -api.parameters.genre = "social-media"; - -api.rosette(endpoint, function(err, res){ - if(err){ - console.log(err); - } else { - console.log(JSON.stringify(res, null, 2)); - } -}); diff --git a/lib/entities.js b/lib/entities.js index 4e4878c..cbd7391 100644 --- a/lib/entities.js +++ b/lib/entities.js @@ -39,15 +39,7 @@ function entities() { entities.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) { if (parameters.documentFile != null) { - if (parameters.loadParams().linked == true) { - console.warn("entities/linked endpoint has been combined with /entities. Do not specify the linked parameter."); - parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "entities/linked", callback); - } else { parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "entities", callback); - } - - - } else { // validate parameters @@ -57,13 +49,7 @@ entities.prototype.getResults = function(parameters, userKey, protocol, serviceU return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments")); } else { // configure URL - if (parameters.loadParams().linked == true) { - console.warn("entities/linked endpoint is deprecated and has been combined with entities. No need to specify linked parameter."); - var urlParts = URL.parse(serviceURL + "entities/linked"); - } else { - urlParts = URL.parse(serviceURL + "entities"); - } - + var urlParts = URL.parse(serviceURL + "entities"); var req = new rosetteRequest(); req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback); diff --git a/lib/parameters.js b/lib/parameters.js index 4860f05..672d88d 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -63,9 +63,6 @@ function parameters() { this.options = null; this.accuracyMode = null; - //entities parameters - this.linked = null; - //sentiment parameters this.explain = null; this.shortString = null; From 6ec54f79bdfbf3c11bedc5ffc3caa9563b8a36be Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 14:07:14 -0500 Subject: [PATCH 2/9] First pass of adding url parameters - Use querystring to build the query string from the object - parameters.urlParameters holds the key value pair - Processing in both parameters (multi-part) and rosetteRequest --- lib/parameters.js | 22 ++++++++++++++++++++-- lib/rosetteRequest.js | 10 +++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/parameters.js b/lib/parameters.js index 672d88d..7545848 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -23,6 +23,8 @@ var http = require("http"); var https = require("https"); var zlib = require("zlib"); +const querystring = require('querystring'); + /** * Compatible server version. * @@ -73,6 +75,9 @@ function parameters() { //headers this.customHeaders = null; + //URL parameters + this.urlParameters = null; + } /** @@ -99,7 +104,8 @@ parameters.prototype.loadParams = function() { "options": this.options, "explain": this.explain, "short-string": this.shortString, - "_customHeaders": this.customHeaders + "_customHeaders": this.customHeaders, + "_urlParameters": this.urlParameters }; for (var key in paramJSON) { @@ -152,11 +158,23 @@ parameters.prototype.loadFile = function(filePath, loadedParameters, userKey, pr } headers["X-RosetteAPI-Key"] = userKey; + if (parameters.customHeaders != null) { + parameters.customHeaders.forEach(function(element, index) { + headers[element[0]] = element[1]; + }); + } + + var path = urlParts.path; + + if (parameters.urlParameters != null) { + path + '?' + querystring.stringify(parameters.urlParameters); + } + var result = new Buffer(""); var options = { hostname: urlParts.hostname, - path: urlParts.path, + path: path, method: 'POST', headers: headers, agent: false diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 13b470c..01d9d02 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -21,6 +21,8 @@ var zlib = require("zlib"); var rosetteConstants = require("./rosetteConstants"); var RosetteException = require("./rosetteExceptions"); +const querystring = require('querystring'); + /** * Compatible server version. * @@ -69,9 +71,15 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, } + var path = urlParts.path; + + if (parameters.urlParameters != null) { + path + '?' + querystring.stringify(parameters.urlParameters); + } + var options = { hostname: urlParts.hostname, - path: urlParts.path, + path: path, method: requestType, headers: headers, agent: false From 2f4976973e25609eae84a90335985e3e8e32b25a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 14:44:10 -0500 Subject: [PATCH 3/9] Support for query parameters added - Added parameters.urlParameters, which takes JSON, e.g. { output: 'rosette' } - Added logic to rosetteRequest.js and parameters.js (multi-part) --- lib/parameters.js | 2 +- lib/rosetteRequest.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/parameters.js b/lib/parameters.js index 7545848..adff260 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -167,7 +167,7 @@ parameters.prototype.loadFile = function(filePath, loadedParameters, userKey, pr var path = urlParts.path; if (parameters.urlParameters != null) { - path + '?' + querystring.stringify(parameters.urlParameters); + path = path + '?' + querystring.stringify(parameters.urlParameters); } var result = new Buffer(""); diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 01d9d02..2548c9b 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -74,7 +74,7 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, var path = urlParts.path; if (parameters.urlParameters != null) { - path + '?' + querystring.stringify(parameters.urlParameters); + path = path + '?' + querystring.stringify(parameters.urlParameters); } var options = { From 59dcc243118b962eb0215e478b0f81589e05cda6 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 15:08:34 -0500 Subject: [PATCH 4/9] Replaced const with var per STRICT check --- lib/parameters.js | 3 +-- lib/rosetteRequest.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/parameters.js b/lib/parameters.js index adff260..d191c18 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -22,8 +22,7 @@ var URL = require("url"); var http = require("http"); var https = require("https"); var zlib = require("zlib"); - -const querystring = require('querystring'); +var querystring = require('querystring'); /** * Compatible server version. diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 2548c9b..bb2637b 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -21,7 +21,7 @@ var zlib = require("zlib"); var rosetteConstants = require("./rosetteConstants"); var RosetteException = require("./rosetteExceptions"); -const querystring = require('querystring'); +var querystring = require('querystring'); /** * Compatible server version. From da46a7b05b832435b426d1548646a92b8364d12c Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 15:11:55 -0500 Subject: [PATCH 5/9] Minor formatting change --- lib/parameters.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/parameters.js b/lib/parameters.js index d191c18..8c1d737 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -22,6 +22,7 @@ var URL = require("url"); var http = require("http"); var https = require("https"); var zlib = require("zlib"); + var querystring = require('querystring'); /** From d5f8bf1c81b40cb6be9f06467d789639a128e351 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 15:13:21 -0500 Subject: [PATCH 6/9] Triggering push after git error From 7212d0b6a8587673b00dc42771def55705daf8a1 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 15:16:14 -0500 Subject: [PATCH 7/9] Trigger From c24d8874ac79f6d2c07229da0d58796c76a48982 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 15:35:51 -0500 Subject: [PATCH 8/9] Trigger From c3e3e97d98adde9cd405c768baf18ce22c5a78c6 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 19 Dec 2016 15:21:22 +0000 Subject: [PATCH 9/9] Version 1.5.0 --- lib/rosetteRequest.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index bb2637b..309d1ef 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -28,7 +28,7 @@ var querystring = require('querystring'); * * @type string */ -var BINDING_VERSION = "1.4.0"; +var BINDING_VERSION = "1.5.0"; /** * @class diff --git a/package.json b/package.json index c6a0248..289286f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rosette-api", - "version": "1.4.0", + "version": "1.5.0", "description": "Rosette API Node.js client SDK", "main": "index", "directories": {