Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Oct 6, 2016
2 parents dc81941 + 31fc839 commit 0e25536
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 174 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ This is the Rosette API client binding for node.js.
## Getting Started
Install the module with: `npm install rosette-api`

## Docker ##
A Docker image for running the examples against the compiled source library is available on Docker Hub.

Command: `docker run -e API_KEY=api-key -v "<binding root directory>:/source" rosetteapi/docker-nodejs`

Additional environment settings:
`-e ALT_URL=<alternative URL>`
`-e FILENAME=<single filename>`


## Example using the Rosette API language detection endpoint
```javascript
Expand Down
19 changes: 0 additions & 19 deletions docker/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions docker/README.md

This file was deleted.

122 changes: 0 additions & 122 deletions docker/runAll.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var args = parser.parseArgs();
var api = new Api(args.key, args.url);
var endpoint = "relationships";

var relationships_text_data = "The Ghostbusters movie was filmed in Boston.";
var relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist.";
var content = relationships_text_data;

api.parameters.content = content;
Expand Down
26 changes: 26 additions & 0 deletions examples/syntax_dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

var Api = require("../lib/Api");
var ArgumentParser = require("argparse").ArgumentParser;

var parser = new ArgumentParser({
addHelp: true,
description: "Get the syntactic dependencies 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 = "syntax_dependencies";
var syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday.";

api.parameters.content = syntax_dependencies_data;
api.parameters.genre = "social-media";
api.rosette(endpoint, function(err, res){
if(err){
console.log(err);
} else {
console.log(JSON.stringify(res, null, 2));
}
});
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ module.exports.tokens = require("./lib/tokens");

module.exports.translatedName = require("./lib/nameTranslation");

module.exports.syntax_dependencies = require("./lib/syntax_dependencies");
3 changes: 2 additions & 1 deletion lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var sentiment = require("./sentiment");
var textEmbedding = require("./textEmbedding");
var translatedName = require("./nameTranslation");
var tokens = require("./tokens");
var syntax_dependencies = require("./syntax_dependencies");

/**
* @class
Expand Down Expand Up @@ -80,7 +81,7 @@ function Api(userKey, serviceURL) {
} else {
this.serviceURL = "https://api.rosette.com/rest/v1/";
}
var urlParts = URL.parse(serviceURL);
var urlParts = URL.parse(this.serviceURL);
if (urlParts.protocol === "http:") {
this.protocol = http;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ parameters.prototype.loadParams = function() {
"options": this.options,
"explain": this.explain,
"short-string": this.shortString,
"_maxRetries": this.maxRetries,
"_msInterval": this.msInterval,
"_customHeaders": this.customHeaders
};

Expand Down
18 changes: 2 additions & 16 deletions lib/rosetteRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var RosetteException = require("./rosetteExceptions");
*
* @type string
*/
var BINDING_VERSION = "1.3.0";
var BINDING_VERSION = "1.4.0";

/**
* @class
Expand All @@ -49,14 +49,6 @@ rosetteRequest.prototype.bindingVersion = function() { return BINDING_VERSION; }
* @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete
*/
rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, urlParts, parameters, callback) {
var maxRetries = 5;
var interval = 500;

if (parameters != null) {
maxRetries = parameters._maxRetries || maxRetries;
interval = parameters._microInterval || interval;
}

var headers = {
"accept": "application/json",
"accept-encoding": "gzip",
Expand Down Expand Up @@ -89,9 +81,6 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol,
options.port = urlParts.port;
}

var retries = 5;
var retry = 0;

var requestTask = function(callback) {
var result = new Buffer("");
// execute the http/https request
Expand All @@ -115,10 +104,7 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol,

if (res.statusCode === 200) {
return callback(null, JSON.parse(result.toString()));
} else if (res.statusCode === 429 && retry++ < maxRetries) {
req.end();
setTimeout(requestTask(callback), interval);
} else if (res.statusCode != 200) {
} else {
return callback(new RosetteException(res.statusCode, result.toString()));
}
});
Expand Down
64 changes: 64 additions & 0 deletions lib/syntax_dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Rosette API.
*
* @copyright 2014-2015 Basis Technology Corporation.
*
* 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
* @license 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.
**/
"use strict";

var URL = require("url");

var rosetteConstants = require("./rosetteConstants");
var RosetteException = require("./rosetteExceptions");
var rosetteRequest = require("./rosetteRequest");

/**
* @class
*
* @copyright 2014-2015 Basis Technology Corporation.
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
function syntax_dependencies() {

};

/**
* Makes an HTTP request to the specified Rosette API endpoint and returns the result
* @param {string} parameters - The Rosette API endpoint parameters
* @param {string} userKey - The Rosette API user access key
* @param {string} serviceURL - The base service URL to be used to access the Rosette API
* @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete
*/
syntax_dependencies.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) {

if (parameters.documentFile != null) {
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "syntax/dependencies", callback);

} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
var urlParts = URL.parse(serviceURL + "syntax/dependencies");
}


var req = new rosetteRequest();
req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback);

}

};

module.exports = syntax_dependencies;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rosette-api",
"version": "1.3.0",
"version": "1.4.0",
"description": "Rosette API Node.js client SDK",
"main": "index",
"directories": {
Expand Down
Loading

0 comments on commit 0e25536

Please sign in to comment.