Skip to content

devinbeeuwkes/ngram

Repository files navigation

PHP NGram

Generate n-grams for your string.

Build Status Scrutinizer Code Quality Latest Version Total Downloads

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

composer install text-utils/n-gram

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

See the CONTRIBUTING file.

License

MIT. Please refer to the LICENSE file in this repository.

About

PHP-Helpers to get n-grams

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages