Skip to content

Commit c1d4988

Browse files
author
unknown
committed
Updated dockerfile, gruntfile, and helper script.
1 parent 75ac586 commit c1d4988

File tree

9 files changed

+257
-48
lines changed

9 files changed

+257
-48
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ RUN apt-get -y update && apt-get install -y git && apt-get install -y vim && apt
66

77
#install necesary npm packages
88
RUN npm install -g mocha
9+
RUN npm install -g istanbul
10+
RUN npm install -g grunt-cli
911

1012
#set the working directory
1113
WORKDIR /source

Gruntfile.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@ module.exports = function(grunt) {
44

55
// Project configuration.
66
grunt.initConfig({
7-
clean: ["node_modules", "target"],
8-
mochaTest: {
9-
test: {
10-
options: {
11-
reporter: 'spec',
12-
quiet: false, // Optionally suppress output to standard out (defaults to false)
13-
clearRequireCache: false // Optionally clear the require cache before running tests (defaults to false)
14-
},
15-
src: ['test/**/*.js']
16-
}
17-
},
7+
clean: ["target"],
188
eslint: {
199
lib: {
2010
src: ["lib/**/*.js"]
2111
},
22-
test: {
23-
src: ["tests/**/*.js"]
24-
},
2512
options: {
2613
configFile: "conf/eslint.json"
2714
},
@@ -44,50 +31,27 @@ module.exports = function(grunt) {
4431
basePath: "target/instrumented"
4532
}
4633
},
47-
storeCoverage: {
48-
options: {
49-
dir: "target"
50-
}
51-
},
52-
makeReport: {
53-
src: "target/coverage.json",
54-
options: {
55-
type: "lcov",
56-
dir: "target/reports",
57-
print: "detail"
58-
}
59-
},
6034
watch: {
6135
gruntfile: {
6236
files: "<%= eslint.gruntfile.lib %>",
6337
tasks: ["eslint:gruntfile"]
6438
},
6539
lib: {
6640
files: "<%= eslint.lib.src %>",
67-
tasks: ["eslint:lib", "nodeunit"]
68-
},
69-
test: {
70-
files: "<%= eslint.test.src %>",
71-
tasks: ["eslint:test", "nodeunit"]
41+
tasks: ["eslint:lib"]
7242
}
7343
}
7444
});
7545

7646
// These plugins provide necessary tasks.
7747
grunt.loadNpmTasks("grunt-contrib-clean");
78-
grunt.loadNpmTasks("grunt-contrib-nodeunit");
7948
grunt.loadNpmTasks("grunt-contrib-watch");
8049
grunt.loadNpmTasks("grunt-eslint");
81-
grunt.loadNpmTasks("grunt-istanbul");
8250
grunt.loadNpmTasks("grunt-jsdoc");
83-
grunt.loadNpmTasks('grunt-mocha-test');
8451

8552
// Task definitions.
8653
// run `grunt <task>` in command line and it will run the sequence in brackets
87-
grunt.registerTask("default", ["jsdoc", "eslint", "test"]);
54+
grunt.registerTask("default", ["clean","jsdoc", "eslint"]);
8855
grunt.registerTask("doc", ["jsdoc"]);
8956
grunt.registerTask("lint", ["eslint"]);
90-
grunt.registerTask("test", ["instrument", "nodeunit", "storeCoverage", "makeReport"]); // with coverage report
91-
grunt.registerTask("nock", ["instrument", "nodeunit:nock", "storeCoverage", "makeReport"]);
92-
grunt.registerTask('default', 'mochaTest');
9357
};

conf/eslint.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"no-extra-bind": 0,
3535
"no-extra-boolean-cast": 2,
3636
"no-extra-parens": 0,
37-
"no-extra-semi": 2,
3837
"no-fallthrough": 2,
3938
"no-floating-decimal": 0,
4039
"no-func-assign": 2,
@@ -100,7 +99,6 @@
10099
"no-unneeded-ternary": 0,
101100
"no-unreachable": 2,
102101
"no-unused-expressions": 0,
103-
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
104102
"no-use-before-define": 0,
105103
"no-useless-call": 0,
106104
"no-useless-concat": 0,

examples/all.js

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
"use strict";
2+
3+
var Api = require("../lib/Api");
4+
var ArgumentParser = require("argparse").ArgumentParser;
5+
var tmp = require("temporary");
6+
7+
var parser = new ArgumentParser({
8+
addHelp: true,
9+
description: "Determine the language of a piece of text"
10+
});
11+
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
12+
var args = parser.parseArgs();
13+
var api = new Api(args.key);
14+
var endpoint = "language";
15+
16+
var content = "Por favor Señorita, says the man.";
17+
18+
api.parameters.content = content;
19+
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+
var spi = new Api(args.key);
26+
endpoint = "categories";
27+
var categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/";
28+
spi.parameters.contentUri = categories_url_data;
29+
spi.parameters.content = null;
30+
31+
spi.rosette(endpoint, function(err, res){
32+
if(err){
33+
console.log(err);
34+
} else {
35+
console.log(JSON.stringify(res, null, 2));
36+
endpoint = "entities";
37+
var dpi = new Api(args.key);
38+
dpi.parameters.content = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS";
39+
dpi.parameters.contentUri = null;
40+
41+
dpi.rosette(endpoint, function(err, res){
42+
if(err){
43+
console.log(err);
44+
} else {
45+
console.log(JSON.stringify(res, null, 2));
46+
47+
endpoint = "entities";
48+
var fpi = new Api(args.key);
49+
fpi.parameters.content = "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.";
50+
fpi.parameters.linked = true;
51+
52+
fpi.rosette(endpoint, function(err, res){
53+
if(err){
54+
console.log(err);
55+
} else {
56+
console.log(JSON.stringify(res, null, 2));
57+
var gpi = new Api(args.key);
58+
endpoint = "info";
59+
gpi.parameters.linked = false;
60+
61+
gpi.rosette(endpoint, function(err, res){
62+
if(err){
63+
console.log(err);
64+
} else {
65+
console.log(JSON.stringify(res, null, 2));
66+
var hpi = new Api(args.key);
67+
endpoint = "matchedName";
68+
69+
var matched_name_data1 = "Michael Jackson";
70+
var matched_name_data2 = "迈克尔·杰克逊";
71+
72+
hpi.parameters.name1 = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"};
73+
hpi.parameters.name2 = {"text": matched_name_data2, "entityType": "PERSON"};
74+
75+
hpi.rosette(endpoint, function(err, res){
76+
if(err){
77+
console.log(err);
78+
} else {
79+
console.log(JSON.stringify(res, null, 2));
80+
var jpi = new Api(args.key);
81+
jpi.parameters.name1 = null;
82+
jpi.parameters.name2 = null;
83+
84+
endpoint = "morphology";
85+
86+
var morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did.";
87+
var content = morphology_complete_data;
88+
89+
jpi.parameters.content = content;
90+
jpi.parameters.morphology = "complete";
91+
92+
jpi.rosette(endpoint, function(err, res){
93+
if(err){
94+
console.log(err);
95+
} else {
96+
console.log(JSON.stringify(res, null, 2));
97+
var kpi = new Api(args.key);
98+
var morphology_han_readings_data = "北京大学生物系主任办公室内部会议";
99+
content = morphology_han_readings_data;
100+
101+
kpi.parameters.content = content;
102+
kpi.parameters.morphology = "han-readings";
103+
104+
kpi.rosette(endpoint, function(err, res){
105+
if(err){
106+
console.log(err);
107+
} else {
108+
console.log(JSON.stringify(res, null, 2));
109+
var lpi = new Api(args.key);
110+
var morphology_lemmas_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon";
111+
content = morphology_lemmas_data;
112+
113+
lpi.parameters.content = content;
114+
lpi.parameters.morphology = "lemmas";
115+
116+
lpi.rosette(endpoint, function(err, res){
117+
if(err){
118+
console.log(err);
119+
} else {
120+
console.log(JSON.stringify(res, null, 2));
121+
var zpi = new Api(args.key);
122+
var morphology_parts_of_speech_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon";
123+
content = morphology_parts_of_speech_data;
124+
125+
zpi.parameters.content = content;
126+
zpi.parameters.morphology = "parts-of-speech";
127+
128+
zpi.rosette(endpoint, function(err, res){
129+
if(err){
130+
console.log(err);
131+
} else {
132+
console.log(JSON.stringify(res, null, 2));
133+
var xpi = new Api(args.key);
134+
endpoint = "ping";
135+
136+
xpi.rosette(endpoint, function(err, res){
137+
if(err){
138+
console.log(err)
139+
} else {
140+
console.log(JSON.stringify(res, null, 2));
141+
var cpi = new Api(args.key);
142+
endpoint = "relationships";
143+
144+
var relationships_text_data = "Bill Murray is in the new Ghostbusters film!";
145+
var content = relationships_text_data;
146+
147+
cpi.parameters.content = content;
148+
cpi.parameters.accuracyMode = "precision";
149+
150+
cpi.rosette(endpoint, function(err, res){
151+
if(err){
152+
console.log(err);
153+
} else {
154+
console.log(JSON.stringify(res, null, 2));
155+
var vpi = new Api(args.key);
156+
endpoint = "sentences";
157+
158+
var sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me.";
159+
var content = sentences_data;
160+
161+
vpi.parameters.content = content;
162+
163+
vpi.rosette(endpoint, function(err, res){
164+
if(err){
165+
console.log(err);
166+
} else {
167+
console.log(JSON.stringify(res, null, 2));
168+
var bpi = new Api(args.key);
169+
var file = new tmp.File();
170+
var sentiment_file_data = "<html><head><title>New Ghostbusters Film</title></head><body><p>Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”</p></body></html>";
171+
var fileContents = sentiment_file_data;
172+
173+
file.writeFileSync(fileContents);
174+
175+
endpoint = "sentiment";
176+
177+
bpi.parameters.documentFile = file.path;
178+
179+
bpi.rosette(endpoint, function(err, res){
180+
if(err){
181+
console.log(err);
182+
} else {
183+
console.log(JSON.stringify(res, null, 2));
184+
var npi = new Api(args.key);
185+
endpoint = "tokens";
186+
187+
var tokens_data = "北京大学生物系主任办公室内部会议";
188+
content = tokens_data;
189+
npi.parameters.content = content;
190+
191+
npi.rosette(endpoint, function(err, res){
192+
if(err){
193+
console.log(err);
194+
} else {
195+
console.log(JSON.stringify(res, null, 2));
196+
var mpi = new Api(args.key);
197+
endpoint = "translatedName";
198+
199+
var translated_name_data = "معمر محمد أبو منيار القذاف";
200+
mpi.parameters.name = translated_name_data;
201+
mpi.parameters.entityType = "PERSON";
202+
mpi.parameters.targetLanguage = "eng";
203+
204+
mpi.rosette(endpoint, function(err, res){
205+
if(err){
206+
console.log(err);
207+
} else {
208+
console.log(JSON.stringify(res, null, 2));
209+
}
210+
});
211+
}
212+
});
213+
}
214+
});
215+
216+
217+
}
218+
});
219+
}
220+
});
221+
}
222+
});
223+
}
224+
});
225+
}
226+
});
227+
}
228+
});
229+
}
230+
});
231+
}
232+
});
233+
}
234+
});
235+
}
236+
});
237+
}
238+
});
239+
}
240+
});
241+
}
242+
});

lib/Api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function Api(userKey, serviceURL) {
7474
Api.prototype.rosette = function(endpoint, callback) {
7575

7676
var api = this;
77-
var endpoint = require("./" + endpoint);
77+
endpoint = require("./" + endpoint);
7878
var e = new endpoint();
7979
var c = new checkVersion();
8080

lib/entities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ entities.prototype.getResults = function(parameters, userKey, serviceURL, callba
5555
if (parameters.loadParams().linked == true) {
5656
var urlParts = URL.parse(serviceURL + "entities/linked");
5757
} else {
58-
var urlParts = URL.parse(serviceURL + "entities");
58+
urlParts = URL.parse(serviceURL + "entities");
5959
}
6060

6161
var protocol = https;

moveFiles.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ find . -name "checkVersion.json" -exec mv {} ../other \;
1212
find . -name "retry-fail.json" -exec mv {} ../other \;
1313
find . -name "bad_info.json" -exec mv {} ../other \;
1414
cd ../../tests
15-
mocha unittests.js
15+
istanbul cover _mocha unittests.js
16+
mv coverage ../target
17+
cd ..
18+
grunt

0 commit comments

Comments
 (0)