PHPackages                             text-utils/n-gram - 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. text-utils/n-gram

ActiveLibrary

text-utils/n-gram
=================

PHP Helpers to get n-grams

1.0.0(7y ago)2561MITPHPPHP ^7.0

Since Jun 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/devinbeeuwkes/ngram)[ Packagist](https://packagist.org/packages/text-utils/n-gram)[ Docs](https://github.com/devinbeeuwkes/ngram)[ RSS](/packages/text-utils-n-gram/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

PHP NGram
=========

[](#php-ngram)

Generate n-grams for your string.

[![Build Status](https://camo.githubusercontent.com/3313b5f90bf479940846998bba03b5171e666f89372a268e63b44b8d2d2c3375/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f446576696e42656575776b65732f6e6772616d2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/DevinBeeuwkes/ngram)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/87bced89b77aa8dddfeeeb25ed1bb9bf787a59e1884b5e1af2eb7964c7676620/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646576696e62656575776b65732f6e6772616d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/devinbeeuwkes/ngram/?branch=master)[![Latest Version](https://camo.githubusercontent.com/6bbcffd9f9eae1834e56d9e62a030f198f46464cce7d7b27f8db1491cc9aab5e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f746578742d7574696c732f6e2d6772616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devinbeeuwkes/ngram)[![Total Downloads](https://camo.githubusercontent.com/ef1e6aa86ffd695aee11b6e5abc3cc316e648c9fedf37d04223fe9e540bddf55/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746578742d7574696c732f6e2d6772616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devinbeeuwkes/ngram)

N-grams?
--------

[](#n-grams)

Why does this project exist? Come on, don't delete this part. Fill it. Yes it's hard, but it's perhaps the most important part of the README.

As to why *this* project exist, it's to serve as a template for future open source PHP projects. Of course, feel free to fork it and make your own recipe.

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

[](#installation)

```
composer install text-utils/n-gram
```

Usage
-----

[](#usage)

You can start using the n-gram generator by instantiating a new `NGram` class:

```
$n = 1;
$generator = new TextUtils\NGram($n, 'Foo');
$nGram = $generator->get(); // array ('F', 'o', 'o')
```

We also provide a static wrapper (the `for` method) and two helper functions (`bigram` and `trigram`) for quick usage

```
$nGram = TextUtils\NGram::for('string', 3); // array ('str', 'tri', 'rin', 'ing')
...
$biGram = bigram('foo'); // array ('fo', 'oo')
$triGram = trigram('foobar'); // array ('foo', 'oob', 'oba', 'bar')
```

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

[](#contributing)

See the [CONTRIBUTING](CONTRIBUTING.md) file.

License
-------

[](#license)

MIT. Please refer to the [LICENSE](LICENSE) file in this repository.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

2901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62d0f2faf5448d50af6e649bfb38d78ed722b670dfdb86dfbd40fe8703d18d68?d=identicon)[DevinBeeuwkes](/maintainers/DevinBeeuwkes)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/text-utils-n-gram/health.svg)

```
[![Health](https://phpackages.com/badges/text-utils-n-gram/health.svg)](https://phpackages.com/packages/text-utils-n-gram)
```

PHPackages © 2026

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