czproject/markov

Simple Markov chains implementation

Fund package maintenance!
Other

v1.0.0 2022-09-25 16:23 UTC

This package is auto-updated.

Last update: 2024-10-13 19:55:59 UTC


README

Build Status Downloads this Month Latest Stable Version License

Simple "Markov chains" implementation

Donate

Installation

Download a latest package or use Composer:

composer require czproject/markov

CzProject\Markov requires PHP 7.2.0 or later.

Usage

use CzProject\Markov\WordAnalyzer;
use CzProject\Markov\MemoryStorage;
use CzProject\Markov\SentenceGenerator;
use CzProject\Markov\RandomNextStateChooser;

$analyzer = new WordAnalyzer;
$analyzer->analyze(['Hello', 'world', 'and', 'everyone']);
$analyzer->analyze(['I', 'love', 'you']);

$storage = new MemoryStorage;
$storage->persistAll($analyzer->getStates());

$generator = new SentenceGenerator($storage, new RandomNextStateChooser);
echo $generator->generateRandom();

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/