Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fieg/markov

Implementation of MarkovChain algorithm in PHP
https://github.com/fieg/markov

algorithm machine-learning markov markov-chain php

Last synced: 3 months ago
JSON representation

Implementation of MarkovChain algorithm in PHP

Awesome Lists containing this project

README

        

Markov Chain
============

Implementation of MarkovChain algorithm in PHP.

[![Build Status](https://travis-ci.org/fieg/markov.png?branch=master)](https://travis-ci.org/fieg/markov)

Getting started
---------------

```php
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)
}
```