ibm-watson-cognitive AlchemyLanguage Sentiment Analysis: get sentiment information for specific phrases in text (Node.js)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

AlchemyLanguage's Targeted Sentiment feature can search your content for target phrases and return sentiment information for each result.

This example requires AlchemyLanguage service credentials and Node.js

  1. Use a command-line interface to install the Watson Developer Cloud Node.js SDK:
$ npm install watson-developer-cloud
  1. Save the following code to an app.js file in the same directory. Make sure you replace API_KEY with your AlchemyAPI key:
var AlchemyLanguageV1 = require('watson-developer-cloud/alchemy-language/v1');
var alchemy_language = new AlchemyLanguageV1({
  api_key: 'API_KEY'
})

var parameters = {
  text: 'Grapes are the best! I hate peaches.',
  targets: [
    'grapes',
    'peaches'
  ]
};

alchemy_language.sentiment(parameters, function (err, response) {
  if (err)
    console.log('error:', err);
  else
    console.log(JSON.stringify(response, null, 2));
});
  1. Run the app:
$ node app.js


Got any ibm-watson-cognitive Question?