Skip to content

Commit a6b66c2

Browse files
authored
Merge pull request #58 from kbailey-basistech/RCB-473_Syntax-Dependencies
syntax dependencies added
2 parents f38cdb6 + 3883d44 commit a6b66c2

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

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 entities 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 = "Sony Pictures is planning to shoot a good portion of the new \"Ghostbusters\" in Boston as well.";
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: 1 addition & 0 deletions
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

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;

tests/unittests.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var tokens = require("../lib/tokens");
1818
var sentences = require("../lib/sentences");
1919
var info = require("../lib/info");
2020
var ping = require("../lib/ping");
21+
var syntax_dependencies = require("../lib/syntax_dependencies");
2122
var paramObj = require("../lib/parameters");
2223
var rosetteException = require("../lib/rosetteExceptions");
2324

@@ -669,6 +670,65 @@ describe("Text Embedding Endpoint", function() {
669670

670671
});
671672

673+
describe("Syntactic Dependencies Endpoint", function() {
674+
beforeEach(function(done) {
675+
var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true});
676+
677+
nock('https://api.rosette.com', {"encodedQueryParams": true })
678+
.post('/rest/v1/info')
679+
.query({"clientVersion": "1.1"})
680+
.reply(200, JSON.parse(mockResponse));
681+
682+
nock('https://api.rosette.com', {"encodedQueryParams": true })
683+
.post('/rest/v1/syntax/dependencies')
684+
.query({"clientVersion": "1.1"})
685+
.reply(200, JSON.parse(mockResponse));
686+
done();
687+
});
688+
689+
afterEach(function(done) {
690+
nock.cleanAll();
691+
done();
692+
});
693+
694+
it("successfully calls the syntactic dependencies endpoint", function(done) {
695+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
696+
api.parameters.content = "Some Content";
697+
698+
api.rosette("syntax_dependencies", function(err, res) {
699+
chai.expect(err).to.be.null;
700+
chai.expect(res.name).to.equal('Rosette API');
701+
done();
702+
});
703+
704+
});
705+
706+
it("detects content and contentUri are defined", function(done) {
707+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
708+
api.parameters.content = "Sample Content";
709+
api.parameters.contentUri = "http://some.url.com";
710+
711+
api.rosette("syntax_dependencies", function(err, res) {
712+
chai.expect(err).to.not.be.null;
713+
chai.expect(err.name).to.equal('RosetteException');
714+
chai.expect(err.message).to.contain('badArgument');
715+
done();
716+
});
717+
});
718+
719+
it("detects neither content nor contentUri are defined", function(done) {
720+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
721+
722+
api.rosette("syntax_dependencies", function(err, res) {
723+
chai.expect(err).to.not.be.null;
724+
chai.expect(err.name).to.equal('RosetteException');
725+
chai.expect(err.message).to.contain('badArgument');
726+
done();
727+
});
728+
});
729+
730+
});
731+
672732
describe("Info Endpoint", function() {
673733
beforeEach(function(done) {
674734
var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true});

0 commit comments

Comments
 (0)