PHPackages                             drupol/phpngrams - 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. drupol/phpngrams

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

drupol/phpngrams
================

Get N-Grams from strings and/or arrays.

1.1.3(6y ago)96.1k↑381.8%1MITPHPPHP &gt;= 7.1.3

Since Feb 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/drupol/phpngrams)[ Packagist](https://packagist.org/packages/drupol/phpngrams)[ RSS](/packages/drupol-phpngrams/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (5)Versions (10)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/7847e73ac17e45644770ab45870924073612f1a99d79caf5ec4a33ccd86de5d3/68747470733a2f2f706f7365722e707567782e6f72672f647275706f6c2f7068706e6772616d732f762f737461626c65)](https://packagist.org/packages/drupol/phpngrams)[![Total Downloads](https://camo.githubusercontent.com/987abc5049a366dcba4e294c9eddff7b24d27e539dbd5ce8a77beecfb4ec18f9/68747470733a2f2f706f7365722e707567782e6f72672f647275706f6c2f7068706e6772616d732f646f776e6c6f616473)](https://packagist.org/packages/drupol/phpngrams)[![Build Status](https://camo.githubusercontent.com/6da7bfb436f91648ae13a621da07a780e3908300cb0f899a515c837e6a452263/68747470733a2f2f7472617669732d63692e6f72672f647275706f6c2f7068706e6772616d732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/drupol/phpngrams)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9e9bc7ec216cdd47e5ff3580171ab1b7776a4e64c502940875f97cbfcb0e48c1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f647275706f6c2f7068706e6772616d732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/drupol/phpngrams/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/4801b32c0a033aef700577c69213c520449c882d87fdb687c46c6b478b909218/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f647275706f6c2f7068706e6772616d732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/drupol/phpngrams/?branch=master)[![Mutation testing badge](https://camo.githubusercontent.com/1fc066f1b3493b38209fea3611c6b693c063847501ed4b1ff0ae826a44efb6a0/68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f647275706f6c2f7068706e6772616d732f6d6173746572)](https://stryker-mutator.github.io)[![License](https://camo.githubusercontent.com/c6575b36681cfd6ce914fc8fb80bf0cebd14121c79afc5d5567ab21b1f965ba8/68747470733a2f2f706f7365722e707567782e6f72672f647275706f6c2f7068706e6772616d732f6c6963656e7365)](https://packagist.org/packages/drupol/phpngrams)

PHPNgrams
---------

[](#phpngrams)

PHP N-Grams library

Introduction
------------

[](#introduction)

In the fields of computational linguistics, machine-learning and probability, an n-gram is a contiguous sequence of n items from a given sample of text or speech. The items can be phonemes, syllables, letters, words or base pairs according to the application. The n-grams typically are collected from a text or speech corpus. When the items are words, n-grams may also be called shingles.

An n-gram of size 1 is referred to as a "unigram"; size 2 is a "bigram" (or, less commonly, a "digram"); size 3 is a "trigram". Larger sizes are sometimes referred to by the value of n in modern language, e.g., "four-gram", "five-gram", and so on. (More on [Wikipedia](https://en.wikipedia.org/wiki/N-gram))

Requirements
------------

[](#requirements)

- PHP &gt;= 7.0

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

[](#installation)

Include this library in your project by doing:

`composer require drupol/phpngrams`

The library provides two classes:

- NGrams
- NGramsCyclic

and one trait:

- NGramsTrait

Usage
-----

[](#usage)

```
