patrickschur / markov-chain
An implementation of the Markov chain algorithm in PHP.
v1.0
2017-01-14 07:49 UTC
Requires
- php: ^7.0 || ^7.1
Requires (Dev)
- phpunit/phpunit: ~5.7
This package is auto-updated.
Last update: 2024-11-17 02:10:47 UTC
README
An implementation of the Markov chain algorithm in PHP.
Installation with Composer
$ composer require patrickschur/markov-chain
How to use
WordTokenizer
use MarkovChain\MarkovChain; use MarkovChain\Tokenizer\WordTokenizer; $c = new MarkovChain(new WordTokenizer()); $c->learn([ 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', 'At vero eos et accusam et justo duo dolores et ea rebum.', ]); print_r($c->classify('et')); /* [ 'accusam' => 0.33333333333333, 'justo' => 0.33333333333333, 'ea' => 0.33333333333333 ] */
CharTokenizer
use MarkovChain\MarkovChain; use MarkovChain\Tokenizer\CharTokenizer; $c = new MarkovChain(new CharTokenizer()); $c->learn([ 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', 'At vero eos et accusam et justo duo dolores et ea rebum.', ]); print_r($c->classify('a')); /* [ 'm' => 0.4, 'd' => 0.2, 'c' => 0.2, 'r' => 0.2 ] */