Giter Club home page Giter Club logo

cerebrum's Introduction

Cerebrum

Cerebrum - The easiest way to add some mental magic to any part of your Laravel/Lumen app.

  • Memory provides magic caching abilities.
  • Linguistics provides a means of simple NLP.
  • Perception helping you discover data you didn't even know you had

Author(s):

Requirements

  1. PHP 5.6+
  2. Lumen 5.2+
  3. Laravel 5.2+

Composer

Start a new Laravel project:

composer create-project laravel/lumen your-project-name

Then run the following to add Cerebrum

composer require yab/cerebrum

Providers

Yab\Cerebrum\CerebrumProvider::class

For Lumen:

Add this to the bootsrap/app.php in the service providers array:

For Laravel:

Add this to the config/app.php in the service providers array:

Milestones

1.0

  • Memory
  • Linguistics

1.1

  • Perception

Memory Example

use Yab\Cerebrum\Memory;

class TaskService
{
    use Memory;

    public function __construct(TaskRespository $taskRepository)
    {
        $this->repository = $taskRepository;
        // provided by Memory
        $this->memoryDuration(15);
        $this->forgetful([
            'all'
        ]);
    }

    public function all()
    {
        return $this->remember($this->repository->all());
    }

    public function findById($id)
    {
        return $this->remember($this->repository->findById($id));
    }

    public function findByIdWithLongerCache($id)
    {
        return $this->remember($this->repository->findById($id), 1440);
    }

    public function update($id, $data)
    {
        $this->forget($id);
        return $this->repository->update($id, $data);
    }
}

Regarding $this->forgetful if you do not set it, then Memory will parse your class for all functions and clear any related caches it can find.

The remember function on the other hand, will collect a value and store it in the cache, returning the cached version. The forget with a parameter will find caches with similar values and clear your caches.

Linguistics Example

use Yab\Cerebrum\Linguistics;

class TaskService
{
    use Linguistics;

    public function __construct(TaskRespository $taskRepository)
    {
        $this->repository = $taskRepository;
    }

    public function getKeyWords($id)
    {
        return $this->getKeyWords($this->repository->findById($id)->text);
    }

    public function search($searchString)
    {
        if ($this->isQuestion($seachString)) {
            return $this->repository->search();
        }
    }
}

Perception Examples

use Yab\Cerebrum\Perception;

class TaskService
{
    use Perception;

    public function __construct(TaskRespository $taskRepository)
    {
        $this->repository = $taskRepository;
    }

    public function getNormalizedData()
    {
        $scores = $this->repository->pluck('score')->all();
        return $this->normalize($scores);
    }

    public function predictDay()
    {
        $records = $this->repository->pluck('day', 'sleep_hours', 'active_hours')->all();
        // $records = ['monday' => [6, 1], 'wednesday' => [4, 0]]
        $result = $this->supervised()->samples($records)->predict([5,2]);
        // $result = monday
    }

    public function getExpectingDay()
    {
        // This is a very simple frequency tool
        $records = $this->repository->pluck('day')->all();
        // $records = ['monday', 'tuesday', 'wednesday', 'tuesday', 'friday', 'monday', 'tuesday']
        $result = $this->ai()->samples($records)->expecting();
        // $result = tuesday
    }
}

## License
Cerebrum is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

### Bug Reporting and Feature Requests
Please add as many details as possible regarding submission of issues and feature requests

### Disclaimer
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cerebrum's People

Contributors

mlantz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.