PHPackages                             certifiedwebninja/caroline - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. certifiedwebninja/caroline

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

certifiedwebninja/caroline
==========================

AFINN-based sentiment analysis

1.0.1(11y ago)164212MITPHPPHP &gt;=5.4.0

Since Sep 18Pushed 11y ago2 watchersCompare

[ Source](https://github.com/mizterp/caroline)[ Packagist](https://packagist.org/packages/certifiedwebninja/caroline)[ RSS](/packages/certifiedwebninja-caroline/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Caroline - Sentimental Analysis
===============================

[](#caroline---sentimental-analysis)

[![Build Status](https://camo.githubusercontent.com/f8fa3a6ff85b38c5479c7d17d647a6eb5fe58c83b9bf9d1b13a71915ad4555f1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6365727469666965647765626e696e6a612f6361726f6c696e652f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/certifiedwebninja/caroline)[![Coverage Status](https://camo.githubusercontent.com/e5c07a8c507afe5163d91d34cd2a283b4d7c4ca2ed130bcc4507b3130b4e84d5/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6365727469666965647765626e696e6a612f6361726f6c696e652e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/certifiedwebninja/caroline)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/fbb79b2d63afc45a541ad3f458cfe412c14dab050a1d6bb83c74c25e94c62c1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365727469666965647765626e696e6a612f6361726f6c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/certifiedwebninja/caroline)[![Total Downloads](https://camo.githubusercontent.com/d9a687234baf544b83623a5d9ae445edc19ef99b4565122d8081778b6495a33d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6365727469666965647765626e696e6a612f6361726f6c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/certifiedwebninja/caroline)

Sentiment analysis tool for PHP based on the [AFINN-111 wordlist](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010).

Install
-------

[](#install)

```
composer require certifiedwebninja/caroline:1.0.1
```

Simple Example
--------------

[](#simple-example)

```
use CertifiedWebNinja\Caroline\Analysis;

$caroline = new Analysis;

$result = $caroline->analyze('Hey you worthless scumbag');

echo 'Score: '.$result->getScore().PHP_EOL;
echo 'Comparative: '.$result->getComparative().PHP_EOL;
```

DataSet Example
---------------

[](#dataset-example)

By default if no dataset is passed to the constructor, it uses the AFINN dataset. You can create your own datasets or even modify a default dataset.

Here is how you can use another dataset.

```
use CertifiedWebNinja\Caroline\Analysis;
use CertifiedWebNinja\Caroline\DataSets\AFINN;

$afinn = new AFINN;

$caroline = new Analysis($afinn);

$result = $caroline->analyze('Hey you worthless scumbag');

echo 'Score: '.$result->getScore().PHP_EOL;
echo 'Comparative: '.$result->getComparative().PHP_EOL;
```

This will return the same results as the Simple Example above, what's neat about this though is by instantiating the AFINN dataset before the analysis class, you can replace and even extend the dataset as `AFINN` extends `AbstractDataSet` which gives a few helper methods on the dataset.

### Replace dataset words

[](#replace-dataset-words)

```
$afinn->replace(['love' => 5]);

$caroline = new Analysis($afinn);

$result = $caroline->analyze('I love my cat.');

echo $result->getScore(); // 5
```

### Extend dataset

[](#extend-dataset)

```
$afinn->extend(['cat' => 3]);

$caroline = new Analysis($afinn);

$result = $caroline->analyze('I love my cat.');

echo $result->getScore(); // 6 because "love" and "cat" both have a score of 3 each.
```

You can also create your own datasets to use by extending `AbstractDataSet`

```
