/markov

Implementation of MarkovChain algorithm in PHP

Primary LanguagePHP

Markov Chain

Implementation of MarkovChain algorithm in PHP.

Build Status

Getting started

use Fieg\Markov\MarkovChain;

$sentences = [
    'my blue car',
    'red and blue flowers',
    'his blue car',
];

$chain = new MarkovChain();

foreach ($sentences as $sentence) {
    $tokens = explode(" ", $sentence);

    $chain->train($tokens);
}

$result = $chain->query("blue");

Which would result in:

array(2) {
  'car' =>
  double(0.66666666666667)
  'flowers' =>
  double(0.33333333333333)
}