PHPackages                             scripturadesign/markov - 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. scripturadesign/markov

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

scripturadesign/markov
======================

Markov Chain

v2.0.0(4y ago)23.7k1MITPHPPHP ^8.0CI failing

Since Jan 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/scripturadesign/markov)[ Packagist](https://packagist.org/packages/scripturadesign/markov)[ Docs](https://github.com/scripturadesign/markov)[ RSS](/packages/scripturadesign-markov/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

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

[](#markov-chain)

[![Latest Version on Packagist](https://camo.githubusercontent.com/48ba00b2bcfe2778fb611c6e7fd95144366dce5a624bcbe9192934f85f313bb8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73637269707475726164657369676e2f6d61726b6f762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scripturadesign/markov)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4afcb95a18107aed5f2afbff5335060529839a9f0dc905de41e5253570a5b535/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f73637269707475726164657369676e2f6d61726b6f762f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/scripturadesign/markov/actions?query=workflow%3ATests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/512604cd32607d2e2c46718e2692cc9097c2dff341566a29ca64121776eb9cac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73637269707475726164657369676e2f6d61726b6f762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scripturadesign/markov)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Markov Chain implementation.
You train it by giving it arrays of tokens. Then you can get the occurrences and probability of tokens after a given token.

Installation
------------

[](#installation)

You can install the package via composer:

```
$ composer require scripturadesign/markov
```

Usage
-----

[](#usage)

!!! Out of date, look in tests for now !!!

```
/* Create a new first order Markov Chain object */
$chain = new Chain(1);

/* Learn from arrays of tokens */
$chain->learn(['the', 'falcon', 'likes', 'the', 'snake']);

/* Get all the history of the training */
$chain->history();
// [
//     [
//         0 => [''],
//         1 => ['the'],
//         2 => ['falcon'],
//         3 => ['likes'],
//         4 => ['snake'],
//     ],
//     [
//         0 => ['the' => 1],
//         1 => ['falcon' => 1, 'snake' => 1],
//         2 => ['likes' => 1],
//         3 => ['the' => 1],
//         4 => ['' => 1],
//     ],
// ]
```

```
/* Create a new second order Markov Chain object */
$chain = new Chain(2);

/* Learn from arrays of tokens */
$chain->learn(['the', 'falcon', 'likes', 'the', 'snake']);

/* Get all the history of the training */
$chain->history();
// [
//     [
//         0 => ['', ''],
//         1 => ['', 'the'],
//         2 => ['the', 'falcon'],
//         3 => ['falcon', 'likes'],
//         4 => ['likes', 'the'],
//         5 => ['the', 'snake'],
//     ],
//     [
//         0 => ['the' => 1],
//         1 => ['falcon' => 1],
//         2 => ['likes' => 1],
//         3 => ['the' => 1],
//         4 => ['snake' => 1],
//         5 => ['' => 1],
//     ],
// ]
```

Testing
-------

[](#testing)

```
$ composer test
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Martin Dilling-Hansen](https://github.com/martindilling)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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

Every ~268 days

Recently: every ~135 days

Total

9

Last Release

1660d ago

Major Versions

v0.1.0 → v1.0.02020-06-20

v1.1.1 → v2.0.02021-12-15

PHP version history (4 changes)v0.1.0PHP ^5.6|^7.0

v1.0.0PHP ^7.4

v1.1.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/58a08b906afaef2d8891c0195c6ce4454d359854d2f0e126ff204cd02d158876?d=identicon)[martindilling](/maintainers/martindilling)

---

Top Contributors

[![martindilling](https://avatars.githubusercontent.com/u/1018838?v=4)](https://github.com/martindilling "martindilling (32 commits)")

---

Tags

markov chain

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[pecl/mcrypt

Bindings for the libmcrypt library.

239.0k](/packages/pecl-mcrypt)[digitalkaoz/yuml-php

a PHP Adapter for http://yuml.me

321.0k](/packages/digitalkaoz-yuml-php)

PHPackages © 2026

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