PHP code example of certifiedwebninja / caroline

1. Go to this page and download the library: Download certifiedwebninja/caroline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

certifiedwebninja / caroline example snippets


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;

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;

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

$caroline = new Analysis($afinn);

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

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

$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.

 namespace Acme;

use CertifiedWebNinja\Caroline\DataSets\AbstractDataSet;

class DataSet extends AbstractDataSet
{
    protected $dataSet = [
        'anvil' => -4,
        'catch' => 3
    ];
}