承接 hopkins/laravel-aylien-wrapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

hopkins/laravel-aylien-wrapper

Composer 安装命令:

composer require hopkins/laravel-aylien-wrapper

包简介

A laravel friendly wrapper around the Aylien PHP SDK

README 文档

README

Aylien is a package consisting of eight different Natural Language Processing, Information Retrieval and Machine Learning APIs that can be adapted to your processes and applications with relative ease. Admittidly this wrapper doesn't add a significant value to their extensive, well documented PHP SDK, as the primary purpose is to provide the facade Aylien:: to your Laravel 5 app.

Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight

#Installation

Require this package in your composer.json and update composer. Run/add either of the below two commands

"hopkins/laravel-aylien-wrapper": "dev-master"

or

composer require hopkins/laravel-aylien-wrapper=dev-master

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Hopkins\LaravelAylienWrapper\Providers\AylienServiceProvider',

and the facade into your array of facades

'Aylien'    => 'Hopkins\LaravelAylienWrapper\Facades\Aylien',

Run the artisan command to bring the config into your project

php artisan vendor:publish

I put my api keys in the .env file. To use this style of config you can copy the below into your config/aylien.php

return [
    'app_id' => env('API_AYLIEN_APP_ID'),
    'app_key' => env('API_AYLIEN_APP_KEY')
];

#How to use

Aylien provides a number of great examples on their site, as well as terrific documentation. However I'd feel bad if I didn't at least provide one example. The example at the bottom of the readme uses the Sentiment analysis, however all of the following are available for use

Aylien::Sentiment();
Aylien::Extract();
Aylien::Classify();
Aylien::Concepts();
Aylien::Hashtags();
Aylien::Entities();
Aylien::Language();
Aylien::Related();
Aylien::Summarize();
Aylien::Microformats();
Aylien::UnsupervisedClassify();

Let's say you want to log all messages you receive from a chat/email client/contact form. You'd have a Message.php model in this case that saved to your database. By adding a public static function boot() method we can utilize Laravel's model events to make sure first we get the message into the db, and then take the time to call Aylien's API. The below example is using the Sentiment anaylisis

class Message extends BaseModel
{
    protected $guarded = ['id'];
    public static function boot()
    {
        parent::boot();
        Message::created(function(Message $message)
        {
            $aylienResponse = \Aylien::Sentiment(['text'=>$message->message]);
            $message->update([
                'polarity' => $aylienResponse->polarity,
                'polarity_confidence' => $aylienResponse->polarity_confidence,
                'subjectivity' => $aylienResponse->subjectivity,
                'subjectivity_confidence' => $aylienResponse->subjectivity_confidence
            ]);
        });
    }
}

统计信息

  • 总下载量: 499
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-20