forked from rosette-api/nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentiment.js
More file actions
33 lines (26 loc) · 1.21 KB
/
sentiment.js
File metadata and controls
33 lines (26 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
var Api = require("../lib/Api");
var ArgumentParser = require("argparse").ArgumentParser;
var tmp = require("temporary");
var parser = new ArgumentParser({
addHelp: true,
description: "Get the sentiment of the text in a local file"
});
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false});
var args = parser.parseArgs();
var file = new tmp.File();
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>";
var fileContents = sentiment_file_data;
file.writeFileSync(fileContents);
var api = new Api(args.key, args.url);
var endpoint = "sentiment";
api.parameters.documentFile = file.path;
api.parameters.language = "eng";
api.rosette(endpoint, function(err, res){
if(err){
console.log(err);
} else {
console.log(JSON.stringify(res, null, 2));
}
});