From 98c8c666071e658f90f2cd63170d6d9dcaeaacc8 Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Sat, 13 Jun 2015 21:51:33 -0400 Subject: [PATCH] Adding Targeted Sentement Method --- README.md | 13 +++++++++++++ index.js | 8 +++++++- package.json | 2 +- test/index.js | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f45fd87..e5e9310 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,19 @@ Sentiment Analysis // Do something with data }); +Targeted Sentiment Analysis +------------------ + var AlchemyAPI = require('alchemy-api'); + var alchemy = new AlchemyAPI(''); + alchemy.sentiment_targeted('', '', {}, 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'); diff --git a/index.js b/index.js index 5109f6b..6048639 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/package.json b/package.json index a97e987..e638a52 100644 --- a/package.json +++ b/package.json @@ -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 ", "contributors": [ ], diff --git a/test/index.js b/test/index.js index 3f1241a..7b1eb9e 100644 --- a/test/index.js +++ b/test/index.js @@ -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) {