Coder Social home page Coder Social logo

laravel-aylien-wrapper's Introduction

A Laravel 5 friendly wrapper around the Aylien PHP SDK

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
            ]);
        });
    }
}

laravel-aylien-wrapper's People

Contributors

chris-redbeed avatar michaeljhopkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aylien besher115

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.