yab/cerebrum

此包已被废弃且不再维护。未建议替换包。

将一些心灵魔法添加到您的Laravel/Lumen应用的任何部分的简单方法。

v1.1.3 2017-11-10 13:58 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:59:44 UTC


README

Cerebrum - 将一些心灵魔法添加到您的Laravel/Lumen应用的任何部分的简单方法。

  • 内存提供魔法缓存能力。
  • 语言学提供了一种简单的自然语言处理方法。
  • 感知帮助您发现您甚至不知道您拥有的数据

作者

要求

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

Composer

启动一个新的Laravel项目

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

然后运行以下命令以添加Cerebrum

composer require yab/cerebrum

提供者

Yab\Cerebrum\CerebrumProvider::class

Lumen专用

将以下内容添加到bootsrap/app.php中的服务提供者数组

Laravel专用

将以下内容添加到config/app.php中的服务提供者数组

里程碑

1.0

  • 内存
  • 语言学

1.1

  • 感知

内存示例

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

关于$this->forgetful,如果您没有设置它,那么Memory将解析您的类中的所有函数并清除任何找到的相关缓存。

另一方面,remember函数将收集一个值并将其存储在缓存中,返回缓存的版本。带有参数的forget将找到具有类似值的缓存并清除您的缓存。

语言学示例

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

感知示例

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://open-source.org.cn/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.