Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Viralheat sentiment analysis for Node.js.
JavaScript Shell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
.npmignore
LICENSE
README.md
index.js
package.json

README.md

Viralheat Sentiment API

You must have a Viralheat account and API key to access the Sentiment API.

Usage of the Module

Require the module

var vh_sentiment = require('viralheat-sentiment')('[Your API Key Here]');

Make a sentiment request

vh_sentiment.get('[text (360 characters or less) that you want to analyze]', function(err, data, status) {
    if(err) {
        // Error
    } else {
        console.log(data);
    }
});

Successful response will look like:

{
    text: 'Hello! I love this product!!',
    mood: 'positive',
    prob: 0.9372610796240683,
    raw: {
        status: 200,
        error: null,
        text: '\'Hello! I love this product!!\'',
        mood: '\'positive\'',
        prob: '0.93726107962406835'
    }
}

The object contained in the raw attribute is the response returned directly from the Viralheat Sentiment API.

Train the Sentiment Analyzer

vh_sentiment.train('[text you would like analyzed]', ['positive','negative', or 'neutral'], function(err, data, status) {
    if(err) {
        // Error
    } else {
        console.log(data);
    }
});

Standard response from a train request:

{"status":"ok"}
Something went wrong with that request. Please try again.