Skip to content

Commit

Permalink
Adding Targeted Sentement Method
Browse files Browse the repository at this point in the history
  • Loading branch information
framingeinstein committed Jun 14, 2015
1 parent f767931 commit 98c8c66
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ Sentiment Analysis
// Do something with data
});

Targeted Sentiment Analysis
------------------
var AlchemyAPI = require('alchemy-api');
var alchemy = new AlchemyAPI('<YOUR API KEY>');
alchemy.sentiment_targeted('<URL|HTML|TEXT>', '<Target>', {}, function(err, response) {
if (err) throw err;

// See http://www.alchemyapi.com/api/sentiment/htmlc.html for format of returned object
var sentiment = response.docSentiment;

// Do something with data
});

Relation Extraction
-------------------
var AlchemyAPI = require('alchemy-api');
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,15 @@ AlchemyAPI.prototype.apiKeyInfo = function(options, cb) {
* @return {Object}
*/
AlchemyAPI.prototype.sentiment = function(data, options, cb) {
this._doRequest(this._getQuery(data, options, "GetTextSentiment"), cb);
this._doRequest(this._getQuery(data, options, "GetTextSentiment"), cb);
};

AlchemyAPI.prototype.sentiment_targeted = function(data, target, options, cb) {
if(typeof target !== 'Object'){
options.target = target;
}
this._doRequest(this._getQuery(data, options, "GetTargetedSentiment"), cb);
};
/**
* Function to return relations in the data passed in
* @param {String} data The text to be passed to Alchemy can either a url, html text or plain text
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alchemy-api",
"description": "An Alchemy API library for Node.js",
"tags": ["Alchemy", "Natural Language Processing", "util"],
"version": "1.1.2",
"version": "1.2.0",
"author": "Jason Morgan <jason@framingeinstein.com>",
"contributors": [
],
Expand Down
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ module.exports = {
test.done();
});
},
'get sentiment_targeted': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.sentiment_targeted("Guy Somethington is an candidate but Hillary is not", "Guy Somethington", {}, function(error, result) {
test.ifError(error);

//console.log(result);
test.deepEqual(result.docSentiment.type, "positive");
test.done();
});
},
'get sentiment_targeted 2': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.sentiment_targeted("Guy Somethington is an awesome candidate but Billary is not", "Billary", {}, function(error, result) {
test.ifError(error);
test.deepEqual(result.docSentiment.type, "negative");
//console.log(result);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get relations': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.relations(testURL, {sentiment: 1}, function(error, result) {
Expand Down

0 comments on commit 98c8c66

Please sign in to comment.