text-utils / n-gram
PHP Helpers to get n-grams
1.0.0
2018-06-05 17:13 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.4
This package is not auto-updated.
Last update: 2025-06-28 02:30:44 UTC
README
Generate n-grams for your string.
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.