Coder Social home page Coder Social logo

anukat2015 / retext-sentiment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from retextjs/retext-sentiment

0.0 3.0 0.0 544 KB

Text Sentiment Aalytics using Retext -> Detect the sentiment of text with Retext

Home Page: http://wooorm.github.io/retext-sentiment/

License: MIT License

JavaScript 100.00%

retext-sentiment's Introduction

retext-sentiment Build Status Coverage Status

Sentiment detection with Retext.

Installation

npm:

npm install retext-sentiment

retext-sentiment is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var retext = require('retext');
var inspect = require('unist-util-inspect');
var sentiment = require('retext-sentiment');

retext().use(sentiment).use(function () {
    return function (cst) {
        console.log(inspect(cst));
    };
}).process(
    'I hate forgetting to bring a book somewhere I ' +
    'definitely should have brought a book to. ' +
    /*
     * Note that `bad` is a negative word, but that it's
     * classified as positive due to its preceding `not`
     * on parent (sentence, paragraph, root) level.
     */
    'This product is not bad at all. ' +
    /*
     * Emoji.
     */
    'Hai sexy! \ud83d\ude0f'
);

Yields:

RootNode[1] [data={"polarity":6,"valence":"positive"}]
└─ ParagraphNode[5] [data={"polarity":6,"valence":"positive"}]
   ├─ SentenceNode[32] [data={"polarity":-3,"valence":"negative"}]
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'I'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1] [data={"polarity":-3,"valence":"negative"}]
   │  │  └─ TextNode: 'hate' [data={"polarity":-3,"valence":"negative"}]
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'forgetting'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'to'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'bring'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'a'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'book'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'somewhere'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'I'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'definitely'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'should'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'have'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'brought'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'a'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'book'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'to'
   │  └─ PunctuationNode: '.'
   ├─ WhiteSpaceNode: ' '
   ├─ SentenceNode[14] [data={"polarity":3,"valence":"positive"}]
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'This'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'product'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'is'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'not'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1] [data={"polarity":-3,"valence":"negative"}]
   │  │  └─ TextNode: 'bad' [data={"polarity":-3,"valence":"negative"}]
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'at'
   │  ├─ WhiteSpaceNode: ' '
   │  ├─ WordNode[1]
   │  │  └─ TextNode: 'all'
   │  └─ PunctuationNode: '.'
   ├─ WhiteSpaceNode: ' '
   └─ SentenceNode[6] [data={"polarity":6,"valence":"positive"}]
      ├─ WordNode[1]
      │  └─ TextNode: 'Hai'
      ├─ WhiteSpaceNode: ' '
      ├─ WordNode[1] [data={"polarity":3,"valence":"positive"}]
      │  └─ TextNode: 'sexy' [data={"polarity":3,"valence":"positive"}]
      ├─ PunctuationNode: '!'
      ├─ WhiteSpaceNode: ' '
      └─ SymbolNode: '😏' [data={"polarity":3,"valence":"positive"}]

API

retext.use(sentiment[, options])

retext().use(sentiment, {
    'cat': -3,
    'dog': 3
});

retext-sentiment automatically detects the sentiment of each Text/WordNode (using wooorm/afinn-111 and wooorm/emoji-emotion), and stores the valence in node.data.valence, and polarity in node.data.polarity.

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

In addition, the plugin exposes a calculated sentiment on parents (sentences, paragraphs, and root nodes), through the same valence and polarity properties. This calculated sentiment includes negation, so a word such as bad, with a polarity of -3, is calculated as 3 when preceded by a word such as not, neither, nor, or a word ending in n't.

Parameters:

  • sentiment — This module;

  • inject (Object, optional) — Mapping strings (words, other symbols) to numbers. Used to insert custom values, or overwrite existing values with new weights.

Supported Words

retext-sentiment supports all wooorm/afinn-111 words and wooorm/emoji-emotion emoji/gemoji.

License

MIT © Titus Wormer

retext-sentiment's People

Contributors

wooorm avatar

Watchers

James Cloos avatar anukat2015 avatar  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.