Skip to content

Commit 0e25536

Browse files
author
Chris Park
committed
Merge branch 'develop'
2 parents dc81941 + 31fc839 commit 0e25536

13 files changed

+166
-174
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ This is the Rosette API client binding for node.js.
77
## Getting Started
88
Install the module with: `npm install rosette-api`
99

10+
## Docker ##
11+
A Docker image for running the examples against the compiled source library is available on Docker Hub.
12+
13+
Command: `docker run -e API_KEY=api-key -v "<binding root directory>:/source" rosetteapi/docker-nodejs`
14+
15+
Additional environment settings:
16+
`-e ALT_URL=<alternative URL>`
17+
`-e FILENAME=<single filename>`
18+
1019

1120
## Example using the Rosette API language detection endpoint
1221
```javascript

docker/Dockerfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

docker/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker/runAll.sh

Lines changed: 0 additions & 122 deletions
This file was deleted.

examples/relationships.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var args = parser.parseArgs();
1414
var api = new Api(args.key, args.url);
1515
var endpoint = "relationships";
1616

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

2020
api.parameters.content = content;

examples/syntax_dependencies.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
3+
var Api = require("../lib/Api");
4+
var ArgumentParser = require("argparse").ArgumentParser;
5+
6+
var parser = new ArgumentParser({
7+
addHelp: true,
8+
description: "Get the syntactic dependencies from a piece of text"
9+
});
10+
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
11+
parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false});
12+
var args = parser.parseArgs();
13+
14+
var api = new Api(args.key, args.url);
15+
var endpoint = "syntax_dependencies";
16+
var syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday.";
17+
18+
api.parameters.content = syntax_dependencies_data;
19+
api.parameters.genre = "social-media";
20+
api.rosette(endpoint, function(err, res){
21+
if(err){
22+
console.log(err);
23+
} else {
24+
console.log(JSON.stringify(res, null, 2));
25+
}
26+
});

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ module.exports.tokens = require("./lib/tokens");
2828

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

31+
module.exports.syntax_dependencies = require("./lib/syntax_dependencies");

lib/Api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var sentiment = require("./sentiment");
3434
var textEmbedding = require("./textEmbedding");
3535
var translatedName = require("./nameTranslation");
3636
var tokens = require("./tokens");
37+
var syntax_dependencies = require("./syntax_dependencies");
3738

3839
/**
3940
* @class
@@ -80,7 +81,7 @@ function Api(userKey, serviceURL) {
8081
} else {
8182
this.serviceURL = "https://api.rosette.com/rest/v1/";
8283
}
83-
var urlParts = URL.parse(serviceURL);
84+
var urlParts = URL.parse(this.serviceURL);
8485
if (urlParts.protocol === "http:") {
8586
this.protocol = http;
8687
}

lib/parameters.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ parameters.prototype.loadParams = function() {
102102
"options": this.options,
103103
"explain": this.explain,
104104
"short-string": this.shortString,
105-
"_maxRetries": this.maxRetries,
106-
"_msInterval": this.msInterval,
107105
"_customHeaders": this.customHeaders
108106
};
109107

lib/rosetteRequest.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var RosetteException = require("./rosetteExceptions");
2626
*
2727
* @type string
2828
*/
29-
var BINDING_VERSION = "1.3.0";
29+
var BINDING_VERSION = "1.4.0";
3030

3131
/**
3232
* @class
@@ -49,14 +49,6 @@ rosetteRequest.prototype.bindingVersion = function() { return BINDING_VERSION; }
4949
* @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete
5050
*/
5151
rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, urlParts, parameters, callback) {
52-
var maxRetries = 5;
53-
var interval = 500;
54-
55-
if (parameters != null) {
56-
maxRetries = parameters._maxRetries || maxRetries;
57-
interval = parameters._microInterval || interval;
58-
}
59-
6052
var headers = {
6153
"accept": "application/json",
6254
"accept-encoding": "gzip",
@@ -89,9 +81,6 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol,
8981
options.port = urlParts.port;
9082
}
9183

92-
var retries = 5;
93-
var retry = 0;
94-
9584
var requestTask = function(callback) {
9685
var result = new Buffer("");
9786
// execute the http/https request
@@ -115,10 +104,7 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol,
115104

116105
if (res.statusCode === 200) {
117106
return callback(null, JSON.parse(result.toString()));
118-
} else if (res.statusCode === 429 && retry++ < maxRetries) {
119-
req.end();
120-
setTimeout(requestTask(callback), interval);
121-
} else if (res.statusCode != 200) {
107+
} else {
122108
return callback(new RosetteException(res.statusCode, result.toString()));
123109
}
124110
});

lib/syntax_dependencies.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Rosette API.
3+
*
4+
* @copyright 2014-2015 Basis Technology Corporation.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at
8+
* @license http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
11+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and limitations under the License.
13+
**/
14+
"use strict";
15+
16+
var URL = require("url");
17+
18+
var rosetteConstants = require("./rosetteConstants");
19+
var RosetteException = require("./rosetteExceptions");
20+
var rosetteRequest = require("./rosetteRequest");
21+
22+
/**
23+
* @class
24+
*
25+
* @copyright 2014-2015 Basis Technology Corporation.
26+
* @license http://www.apache.org/licenses/LICENSE-2.0
27+
*/
28+
function syntax_dependencies() {
29+
30+
};
31+
32+
/**
33+
* Makes an HTTP request to the specified Rosette API endpoint and returns the result
34+
* @param {string} parameters - The Rosette API endpoint parameters
35+
* @param {string} userKey - The Rosette API user access key
36+
* @param {string} serviceURL - The base service URL to be used to access the Rosette API
37+
* @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete
38+
*/
39+
syntax_dependencies.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) {
40+
41+
if (parameters.documentFile != null) {
42+
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "syntax/dependencies", callback);
43+
44+
} else {
45+
46+
// validate parameters
47+
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
48+
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
49+
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
50+
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
51+
} else {
52+
// configure URL
53+
var urlParts = URL.parse(serviceURL + "syntax/dependencies");
54+
}
55+
56+
57+
var req = new rosetteRequest();
58+
req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback);
59+
60+
}
61+
62+
};
63+
64+
module.exports = syntax_dependencies;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rosette-api",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Rosette API Node.js client SDK",
55
"main": "index",
66
"directories": {

0 commit comments

Comments
 (0)