PHPackages                             patrickschur/markov-chain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. patrickschur/markov-chain

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

patrickschur/markov-chain
=========================

An implementation of the Markov chain algorithm in PHP.

v1.0(9y ago)9653MITPHPPHP ^7.0 || ^7.1

Since Jan 14Pushed 7y ago2 watchersCompare

[ Source](https://github.com/patrickschur/markov-chain)[ Packagist](https://packagist.org/packages/patrickschur/markov-chain)[ Docs](https://github.com/patrickschur/markov-chain)[ RSS](/packages/patrickschur-markov-chain/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

markov-chain
============

[](#markov-chain)

[![Build Status](https://camo.githubusercontent.com/05131d1506176606f9f724531c0239d8c1e4b0566868377a762d82f17e0fc9a6/68747470733a2f2f7472617669732d63692e6f72672f7061747269636b73636875722f6d61726b6f762d636861696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/patrickschur/markov-chain)[![codecov](https://camo.githubusercontent.com/0ecd317c74f82518d7e94c89dc8e8e565866896fbd601e98b5d05cc4232db5c3/68747470733a2f2f636f6465636f762e696f2f67682f7061747269636b73636875722f6d61726b6f762d636861696e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/patrickschur/markov-chain)[![Minimum PHP Version](https://camo.githubusercontent.com/155999288c1f9dde431bb04df738efd216eadd4648a8e448957309300722c19e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e302d3562613663632e7376673f7374796c653d666c61742d737175617265)](http://php.net/)[![License](https://camo.githubusercontent.com/f31db3334342f319d57f22087529c67b979845829ebf287e16e287e6b09690e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7061747269636b73636875722f6c616e67756167652d646574656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

An implementation of the Markov chain algorithm in PHP.

Installation with Composer
--------------------------

[](#installation-with-composer)

```
$ composer require patrickschur/markov-chain
```

How to use
----------

[](#how-to-use)

WordTokenizer
-------------

[](#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
-------------

[](#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
    ]
*/
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3402d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb79131c7f6c10c12c85ece2ff6a790ae73d9d2127d6819733b7a41a03769bc5?d=identicon)[patrickschur](/maintainers/patrickschur)

---

Top Contributors

[![patrickschur](https://avatars.githubusercontent.com/u/18181635?v=4)](https://github.com/patrickschur "patrickschur (12 commits)")

---

Tags

markov-chainphpChainmarkov

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/patrickschur-markov-chain/health.svg)

```
[![Health](https://phpackages.com/badges/patrickschur-markov-chain/health.svg)](https://phpackages.com/packages/patrickschur-markov-chain)
```

###  Alternatives

[xiyusullos/nullable

chain calls on object whatever the object is null or not

152.2k](/packages/xiyusullos-nullable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
