Simple "Markov chains" implementation
Download a latest package or use Composer:
composer require czproject/markov
CzProject\Markov requires PHP 7.2.0 or later.
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/