mintbridge/eloquent-sentiment

为 eloquent 模型添加情感分析的优雅包。

0.0.1 2016-02-21 15:51 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:52:59 UTC


README

Laravel 5 包,用于为 eloquent 模型添加情感分析。

安装

该包可以通过 Composer 安装。

composer require mintbridge/eloquent-sentiment

安装后,请将服务提供者和外观添加到您的应用程序配置中

// config/app.php

'providers' => [
    '...',
    'Mintbridge\EloquentSentiment\SentimentServiceProvider',
];

'aliases' => [
    '...',
    'Sentiment' => 'Mintbridge\EloquentSentiment\SentimentFacade',
];

您还需要发布并运行迁移,以便创建数据库表。

php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="config"
php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="migrations"
php artisan migrate

配置将被写入到 config/eloquent-sentiment.php。选项有合理的默认值,但您应该更改用户模型以匹配您应用程序中使用的模型。

用法

此包将允许您的用户为应用程序中使用的模型添加情感分析。为此,您希望情感化的模型必须使用 Sentimentable 特性和实现 SentimentableInterface

use Mintbridge\EloquentSentiment\Sentimentable;
use Mintbridge\EloquentSentiment\SentimentableInterface;

class Article extends Eloquent implements SentimentableInterface {

    use Sentimentable;
    ...
}

可以通过 SentimentManager 或更简单的 Sentiment 外观向模型添加情感分析

$article = Article::find(1);

// add article as a favourite
Sentiment::add('like', $article);

// remove article from by a favourite
Sentiment::remove('like', $article);

// toggle article as being a favourite
Sentiment::toggle('like', $article);

贡献

有关详细信息,请参阅 CONTRIBUTING

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件