Skip to content

PHP 8.3+ · English & Indonesian · zero dependencies

Sentiment analysis for PHP

Score English and Indonesian text as positive, negative or neutral. No API, no dependencies, no training. Just one composer require.

composer require risan/sentiment-analysis
analyze.php
use Risan\Sentiment\Sentiment;
$result = Sentiment::analyze('This package is awesome!');
$result->label; // Label::Positive
$result->compound; // 0.6588
$result->positive; // 0.594

Product reviews, support tickets, tweets, comments. The kind of text people actually write, with typos, shouting and emoji.

  • English and Indonesian

    One API, two languages. English runs the VADER rules; Indonesian has its own lexicon and rules for negation, intensifiers and informal spelling.

  • Reads like a person

    Understands "not good", "very good", "GOOD!!!", "good, but…", emoticons and emoji, not just a bag of words.

  • Zero dependencies

    Pure PHP 8.3+ with ext-mbstring. No API keys, no network calls, no model files, nothing to train.

  • Fast and light

    About 80,000 short texts per second. Lexicons are plain PHP arrays that OPcache keeps in shared memory.

  • Yours to tune

    Add or override words, drop words, move the neutral threshold. Every analyzer is immutable, so one tweak never leaks into another.

  • MIT licensed

    Built on the published VADER algorithm, checked against the reference implementation. The Indonesian lexicon is written for this project.

Every analysis returns a label and four numbers: a compound score from -1 (most negative) to +1 (most positive), plus the share of positive, neutral and negative signal in the text.

TextLabelCompoundPosNeuNeg
This package is awesome!Englishpositive0.65880.5940.4060.000
The movie was good.Englishpositive0.44040.4920.5080.000
The movie was not good.Englishnegative-0.34120.0000.6240.376
It isn't bad at all.Englishpositive0.43100.4160.5840.000
The service was extremely good.Englishpositive0.49270.4440.5560.000
The service was kind of good.Englishpositive0.38320.3430.6570.000
The plot was good, but the ending was terrible.Englishnegative-0.49390.1490.5340.317
I LOVE this phone.Englishpositive0.71250.6220.3780.000
The concert was great!!!Englishpositive0.71630.6240.3760.000
Thanks for the help :)Englishpositive0.82250.8110.1890.000
Loved the show 😍Englishpositive0.78450.5800.4200.000
Worst day ever 😭Englishnegative-0.80200.0000.3570.643
The meeting is at 3 pm.Englishneutral0.00000.0001.0000.000
Filmnya bagus banget!Indonesianpositive0.62300.6710.3290.000
Makanannya enak sekali.Indonesianpositive0.58490.6550.3450.000
Pelayanannya tidak ramah.Indonesiannegative-0.35700.0000.4460.554
Tempatnya nyaman tapi harganya mahal.Indonesiannegative-0.12800.2670.4000.333
Aku BENCI antrean panjang!!!Indonesiannegative-0.68170.0000.3940.606
Hotelnya lumayan, tapi kamarnya kotor.Indonesiannegative-0.64280.1620.3240.514
Kamera hp ini keren parah 😍Indonesianpositive0.77780.4920.5080.000
Besok rapat jam 3 sore.Indonesianneutral0.00000.0001.0000.000
English
use Risan\Sentiment\Sentiment;
$result = Sentiment::analyze('Not bad at all!');
$result->isPositive(); // true
Indonesian
use Risan\Sentiment\Language;
use Risan\Sentiment\Sentiment;
$result = Sentiment::analyze(
'Filmnya bagus banget!',
Language::Indonesian,
);
$result->isPositive(); // true

Install the package and score your first sentence in under a minute.