Giter Club home page Giter Club logo

retext-sentiment's Introduction

retext-sentiment Build Status Coverage Status

Detect the sentiment of text with Retext.

Installation

npm:

$ npm install retext-sentiment

Component:

$ component install wooorm/retext-sentiment

Bower:

$ bower install retext-sentiment

Usage

var Retext = require('retext');
var visit = require('retext-visit');
var sentiment = require('retext-sentiment');

var retext = new Retext()
    .use(visit)
    .use(sentiment);

retext.parse(
    'Haha hanks and happy birthday!!!!! ' +
    'I hate forgetting to bring a book somewhere I ' +
    'definitely should have brought a book to. ' +
    'Hate having to wait a whole week until the next game now.',
    function (err, tree) {
        console.log(tree.data.valence, tree.data.polarity);
        /**
         * 'neutral', 0
         */

        tree.visit(tree.SENTENCE_NODE, function (sentenceNode) {
            console.log(sentenceNode.data.valence, sentenceNode.data.polarity);
        });
        /**
         * 'positive', 6
         * 'negative', -3
         * 'negative', -3
         */

        tree.visit(tree.WORD_NODE, function (wordNode) {
            if (!wordNode.data.polarity) {
                return;
            }

            console.log(wordNode.toString(), wordNode.data.valence);
        });
        /**
         * 'Haha', 'positive'
         * 'happy', 'positive'
         * 'hate', 'negative'
         * 'Hate', 'negative'
         */
    }
);

Supported Words

retext-sentiment supports all words wooorm/afinn-111 supports.

API

None, retext-sentiment automatically detects the sentiment of each word (using wooorm/afinn-111), and stores the valence in word.data.valence, and polarity in word.data.polarity.

In addition, the plugin exposes the average of the detected sentiment on parents (sentences, paragraphs, and root nodes), through the same valence and polarity properties.

Valence? Either "neutral", "positive", or "negative". Polarity? A number between -5 and 5 (both including).

License

MIT © Titus Wormer

retext-sentiment's People

Contributors

wooorm avatar

Watchers

James Cloos avatar Slim Ben Nasrallah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.