certifiedwebninja/caroline
Composer 安装命令:
composer require certifiedwebninja/caroline
包简介
AFINN-based sentiment analysis
README 文档
README
Sentiment analysis tool for PHP based on the AFINN-111 wordlist.
Install
composer require certifiedwebninja/caroline:1.0.1
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
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
$afinn->replace(['love' => 5]); $caroline = new Analysis($afinn); $result = $caroline->analyze('I love my cat.'); echo $result->getScore(); // 5
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
<?php namespace Acme; use CertifiedWebNinja\Caroline\DataSets\AbstractDataSet; class DataSet extends AbstractDataSet { protected $dataSet = [ 'anvil' => -4, 'catch' => 3 ]; }
统计信息
- 总下载量: 421
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-11