Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including sentiment-deftbyte with all npm packages installed. Try it out:

var sentimentDeftbyte = require("sentiment-deftbyte")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

sentiment-deftbyte v5.0.2

AFINN-based sentiment analysis for Node.js

sentiment-deftbyte

AFINN-based sentiment analysis for Node.js

Forked from Sentiment by thisandagain https://github.com/thisandagain/sentiment

Added Feature

1. Custom tokenization

You can add a custom function for creating tokens by adding customLabels and customTokenization in registerLanguage method

const Sentiment = require('./lib/index')
const sentiment = new Sentiment()
// require the custom tokenizetion function
const customFunction = require('./custom-tokenization') 

const idLanguage = {
  labels: {
     'berhasil': 3
     },
  customLabels: {
    "kasih sayang": 2
    "bertepuk tangan": 2
  },
  customTokenization: customFunction
};
sentiment.registerLanguage('id', idLanguage)

const analyzeOptions = {
  language: 'id'
}
const text = 'saat saya berhasil mengutarakan rasa kasih sayang ke dia, semua orang bertepuk tangan'
const result = sentiment.analyze(text, analyzeOptions)
console.dir(result)

The result will be:

{ score: 7,
  comparative: 0.6363636363636364,
  tokens:
   [ 'saat',
     'saya',
     'berhasil',
     'mengutarakan',
     'rasa',
     'kasih sayang',
     'ke',
     'dia',
     'semua',
     'orang',
     'bertepuk tangan' ],
  words: [ 'bertepuk tangan', 'kasih sayang', 'berhasil' ],
  positive: [ 'bertepuk tangan', 'kasih sayang', 'berhasil' ],
  negative: [] }
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free