Download the PHP package risan/sentiment-analysis without Composer

On this page you can find all versions of the php package risan/sentiment-analysis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sentiment-analysis

Sentiment Analysis for PHP

Scores English and Indonesian text as positive, negative or neutral. Pure PHP 8.3+, no API calls, no dependencies.

Documentation and live examples: https://sentiment-analysis.risanb.com

Install

Requires PHP 8.3 or newer and the mbstring extension.

Usage

Analyze a text

Pass a string. You get a result with a label and a compound score.

compound runs from -1 (very negative) to +1 (very positive). The label comes from compound.

Read the result

The three shares add up to about 1. Three methods check the label.

Export the result

Turn the result into an array, or encode it as JSON.

Analyze Indonesian

Pass the language as an enum case, or as the code 'id'. An unknown code throws a ValueError.

Customize the analyzer

Add or remove words and change the threshold. Every with*() call returns a new analyzer.

The default threshold is 0.05. A text is positive when compound is at least the threshold. It is negative when compound is at most minus the threshold. Otherwise it is neutral.

More in the documentation: understanding the scores, languages, customizing the lexicon, thresholds and long text.

How it works

The engine is a PHP version of VADER (Hutto & Gilbert, 2014).

  1. A lexicon gives each known word a score from -4 to +4.
  2. Rules adjust the scores in context: negation, intensifiers and dampeners ("very", "kind of"), the contrast word "but", ALL CAPS, ! and ?, emoticons and emoji.
  3. The package adds up the scores and squashes the sum into compound, between -1 and +1.

English uses the original VADER lexicon and rules. Its scores match vaderSentiment 3.3.2 on more than 2,700 reference scores, with two deliberate fixes. Indonesian runs the same engine with a lexicon and rules written for this project. It handles negation, intensifiers before and after the word (bagus banget), contrast words (tapi), informal spellings and emoji.

It is a lexicon method. It does not understand sarcasm, regional languages or words from your own field. How it works, in the docs.

Accuracy and performance

On the test split of IndoNLU SmSA, Indonesian scoring reaches 81.2% accuracy and 0.744 macro F1. The split has 500 reviews and comments in three classes, and the test uses the default threshold. Always guessing the most common class gives 41.6% accuracy. A fine-tuned model reaches more. Reproduce the numbers with php tools/evaluate-id.php --split=test. See Languages.

With OPcache on, the package scores about 80,000 short English texts per second and about 14,000 reviews per second. These are single runs on PHP 8.5, on a laptop with Docker on WSL2. They vary by 10% or more. The whole benchmark process peaks at about 2 MB. Run php benchmarks/run.php on your own hardware. See Performance.

Development

resources/ is generated from tools/data/. Run composer build:lexicons after you edit the sources. A test fails when they drift apart.

The examples in this README, on the website and in the docs are checked by tests/Feature/DocsExamplesTest.php.

Credits and license

MIT, see NOTICE.md.


All versions of sentiment-analysis with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package risan/sentiment-analysis contains the following files

Loading the files please wait ...