PHPackages                             bdp-raymon/rhyme-suggester - 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. bdp-raymon/rhyme-suggester

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

bdp-raymon/rhyme-suggester
==========================

rhyme suggester based on phonetics, using edit-distance algorithm

v0.1.5(5y ago)655MITPHPPHP ^7.4|^8.0

Since Jan 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bdp-raymon/rhyme-suggester)[ Packagist](https://packagist.org/packages/bdp-raymon/rhyme-suggester)[ Docs](https://github.com/bdp-raymon/rhyme-suggester)[ RSS](/packages/bdp-raymon-rhyme-suggester/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

rhyme-suggester
===============

[](#rhyme-suggester)

Rhyme Suggester Php package

[![Total Downloads](https://camo.githubusercontent.com/ff740ce2a9d9eb6ffe1433b2dc06e2f968bd1639a4593dbbe582138a01f4f238/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6264702d7261796d6f6e2f7268796d652d7375676765737465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bdp-raymon/rhyme-suggester)

This package helps you to find the nearest object to your desired object, using [edit-distance algorithm](https://en.wikipedia.org/wiki/Edit_distance#:~:text=In%20computational%20linguistics%20and%20computer,one%20string%20into%20the%20other.), specifically for phonetic of words. In the other words, this package will suggest closest elements of the database to the desired word based on it's pronunciation.

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

[](#installation)

For installing this package, you just need to require it via composer in the root of your project:

```
composer require bdp-raymon/rhyme-suggester
```

Basic Usage
-----------

[](#basic-usage)

In order to getting familiar with the pacakge, we provided a small database in the `samples` directory. You just need to run codes bellow to see the rhytmic related words to `امیر`:

```
use BdpRaymon\RhymeSuggester\Rhyme;
use BdpRaymon\RhymeSuggester\Samples\Database as SampleDatabase;
use BdpRaymon\RhymeSuggester\PhpLibrary\Arr;

// this will return the array containing the nearest objects to the ‍‍`امیر`
$list = Rhyme::db(SampleDatabase::_)->filter();
$output = Arr::get($list, fn($value) => $value[0]['name']);
print_r($output);
```

The generated output should be something like this:

```
[
     "امیر",
     "عمید",
     "امین",
     "عزیز",
     "عقیل",
     "عقیق",
     "ادیب",
     "عفیف",
     "علیم",
     "اوین"
]
```

Full Usage
----------

[](#full-usage)

### Feeding Database

[](#feeding-database)

You can feed database to the package with two different ways. First way have been already shown in the example above, with injecting it as an array to the static `Rhyme::db` function. Secondly, you can provide a `.csv` file of your own dataset and use it as an argument:

```
Rhyme::db("PATH-TO-THE-CSV-FILE.csv");
```

### Configuration

[](#configuration)

The sample configuration file is placed in the `samples/Config.php` file. The fields that should be used in the config file are as follow:

- **searchKey**: *(Required)*It's the key that package uses to search your query to find the query object in the database. for example in our database, we use *name* key
- **phoneticKey**: *(Required)*The key in the database that we use edit-distance algorithm on it. Usually it should be the *phonetic* field.
- **vowels**: *(Required)*Specify the vowels of your language alphabet in a single string here.
- **rhymeDistance**: *(Required)*It's the distance between **not important characters** in the phonetic algorithm. we will discuss about it later.

Config file need to be set after instantiating an object of the `Rhyme` class, with following structure:

```
$config = [
    'searchKey' => 'name',
    'phoneticKey' => 'phonetic',
    'vowels' => 'aeiouā',
    'rhymeDistance' =>  0.1,
];
Rhyme::db($db)->setConfig($config);
```

### Running a Query and Filtering

[](#running-a-query-and-filtering)

After specifying the database and configuration, you can run queries using `filter` function. This function allows customizing the search query with what you desire. Allowable fields in the filter array are as follow:

- **config searchKey**The search key you have configured as a config in previous step. In our example we used *name* key for *searchKey*.
- **rhyme**: *(Required)*The rhyme field accepts two values:

    - RhymeTypes::VOWEL
    - RhymeTypes::CONSONENT

    these two fields allow you to specify how the names would be suggested. In particular, it indicates which characters of the phonetics have lesser weight than the others in the edit-distance algorithm. If you choose *VOEWEL*, consonant characters will have the *rhymeDistance* weight, provided in the previous stage while the vowel characters value are equal to 1. And vice versa.
- **selection**: *(Optional)*Accepted values for this section are as follow:

    - SelectionTypes::FIRST
    - SelectionTypes::LAST
    - SelectionTypes::BOTH
    - SelectionTypes::NO

    These values specify which syllables of the phonetic should be used in the algorithm.*FIRST* indicates the first syllable should be used, and so on.
- **similarity**: *(Optional)*Similarity part force suggested names have the exaclty same parts specified with this attribute. It accepts following values:

    - SimilarityTypes::FIRST
    - SimilarityTypes::LAST
    - SimilarityTypes::NO
- **tashdid**: *(Optional)*If set to false, it will remove one of each two consecutive consonants in the phonetic. For example, it will turn *abbās* to *abās*.
- **included**: *(Optional)*If set true, it will suggest the words whether it is included to the query name or contains the query name.
- **showDistance**: *(Optional)*If set true, it will display the distances of the found words in the returned array.
- **count**: *(Optional)*You can specify number of words you want to receive with this option. Defaults to -1 that means will return every instance would be found.

Example
-------

[](#example)

The complete working example should be something like this:

```
use BdpRaymon\RhymeSuggester\Rhyme;
use BdpRaymon\RhymeSuggester\Types\RhymeTypes;
use BdpRaymon\RhymeSuggester\Types\SelectionTypes;
use BdpRaymon\RhymeSuggester\Types\SimilarityTypes;
use BdpRaymon\RhymeSuggester\PhpLibrary\Arr;

$dbPath = __DIR__ . "/vendor/bdp-raymon/rhyme-suggester/samples/output_phonetic.csv";
$config = [
    'searchKey' => 'name',
    'phoneticKey' => 'phonetic',
    'vowels' => 'aeiouā',
    'rhymeDistance' =>  0.1,
];
$filter = [
    'name' => 'مهدی',
    'rhyme' => RhymeTypes::VOWEL,
    'selection' => SelectionTypes::NO,
    'similarity' => SimilarityTypes::FIRST,
    'tashdid' => false,
    'included' => true,
    'showDistance' => true,
    'count' => 15,
];
$list = Rhyme::db($dbPath)->setConfig($config)->filter($filter);
$output = Arr::get($list, fn($value) => $value[0]['name']);
print_r($output);
```

And the output should be like this:

```
[
    "مهدی",
    "امیر مهدی",
    "مهدیس",
    "امیرمهدی",
    "اوتانا",
    "مهدیسا",
    "هستی",
    "فخری",
    "نرسی",
    "سلمی",
    "بدری",
    "زردیس",
    "تقی",
    "پردیس",
    "پری",
]
```

Tests
-----

[](#tests)

To run tests, use the following composer command:

```
composer test
```

Credits
-------

[](#credits)

- [Amirhossein Shapoori](https://github.com/shamir0xe)
- [Bdp Raymon Team](https://github.com/bdp-raymon)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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 ~5 days

Total

6

Last Release

1900d ago

PHP version history (2 changes)v0.1.0PHP ^7.4

v0.1.4PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/803cb3ff892af3fe04964adf1c725bc8b4aaff48116492545a3266b12fda90de?d=identicon)[shamir0xe](/maintainers/shamir0xe)

---

Top Contributors

[![shamir0xe](https://avatars.githubusercontent.com/u/20794740?v=4)](https://github.com/shamir0xe "shamir0xe (19 commits)")

---

Tags

bdp-raymonrhyme-suggesteredit-distance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bdp-raymon-rhyme-suggester/health.svg)

```
[![Health](https://phpackages.com/badges/bdp-raymon-rhyme-suggester/health.svg)](https://phpackages.com/packages/bdp-raymon-rhyme-suggester)
```

###  Alternatives

[trsteel/ckeditor-bundle

Symfony bundle for easy integration of the CKEditor WYSIWYG

99630.9k9](/packages/trsteel-ckeditor-bundle)[alom/graphviz

Graphviz generation for PHP

74651.4k9](/packages/alom-graphviz)[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[robertboes/inertia-breadcrumbs

Laravel package to automatically share breadcrumbs to Inertia

56129.1k](/packages/robertboes-inertia-breadcrumbs)[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

40225.5k](/packages/elhebert-laravel-sri)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)

PHPackages © 2026

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