定制 certifiedwebninja/caroline 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

certifiedwebninja/caroline

Composer 安装命令:

composer require certifiedwebninja/caroline

包简介

AFINN-based sentiment analysis

README 文档

README

Build Status Coverage Status Software License Packagist Version Total Downloads

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

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固