PHPackages                             kudashevs/keywords-extractor - 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. kudashevs/keywords-extractor

ActiveLibrary

kudashevs/keywords-extractor
============================

A flexible and customizable PHP library that extracts relevant keywords from text.

v1.3.0(1y ago)147—0%1MITPHPPHP ^8.1CI passing

Since Jan 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kudashevs/keywords-extractor)[ Packagist](https://packagist.org/packages/kudashevs/keywords-extractor)[ RSS](/packages/kudashevs-keywords-extractor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Keywords Extractor
==================

[](#keywords-extractor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b7d666db7b07ebf24f6012fac60c1d69dd4ecbaeaca8ca8b66124a4796241713/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b75646173686576732f6b6579776f7264732d657874726163746f722e737667)](https://packagist.org/packages/kudashevs/keywords-extractor)[![Run Tests](https://github.com/kudashevs/keywords-extractor/actions/workflows/run-tests.yml/badge.svg)](https://github.com/kudashevs/keywords-extractor/actions/workflows/run-tests.yml)[![License MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)

The `keywords-extractor` is a flexible and customizable PHP library that extracts relevant keywords from text.

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

[](#installation)

You can install the package via composer:

```
composer require kudashevs/keywords-extractor
```

Usage
-----

[](#usage)

The key feature of the `keywords-extractor` library is the possibility to extract not only individual nouns, but meaningful sequences of words that make more sense in some contexts. This possibility is provided by the [RAKE PHP](https://github.com/kudashevs/rake-php)library that is used as the default extraction algorithm. If this library doesn't suit your needs, it can be easily substituted with something more appropriate or relevant.

The usage of the `KeywordsExtractor` class is pretty straightforward. To extract keywords call the `extract` method:

```
use Kudashevs\KeywordsExtractor\KeywordsExtractor;

$extractor = new KeywordsExtractor([
    'add_words' => 'some',
    'remove_words' => 'interesting'
]);

$keywords = $extractor->extract('this is some interesting text');

print_r($keywords); // some, text
```

To make this library even more convenient to use in some specific cases, it provides a fluent interface.

```
use Kudashevs\KeywordsExtractor\KeywordsExtractor;

$extractor = new KeywordsExtractor();

$keywords = $extractor->addWords(['this', 'example'])
    ->extract('this is a usage example');

print_r($keywords); // usage example, this
```

### Words collections

[](#words-collections)

Sometimes, there may be a necessity to provide a big number of words to be excluded or included. It can be done with the `add_words` and `remove_words` options. In some cases, the options are not convenient to use. For these cases the library introduces a concept of [words collections](src/Collections/WordsCollection.php) and correspondent asset files. To start using them, provide an `assets_path` option to the `KeywordsExtractor` class. The instantiation process is going to create two different folders in the provided `assets` folder (once created, these files won't be modified):

- `words` folder - contains default files used for words exclusions and words inclusions
- `cache` folder - contains cached words collections (clean it whenever the `words` folder is updated)

If you want to include some words to the generated keywords, update the `rake_exclude.txt` file. If you want to exclude some words from the generated keywords, update the `rake_include.txt` file. The naming logic may seem wierd, but it is because the words are included to a list of stop words and excluded from a list of stop words.

### Result length

[](#result-length)

By default, the returning result is limitless, meaning that the length of the result is not limited. However, in some cases the length of the result does matter. For these cases the package introduces the concept of a [Limiter](src/Limiters/Limiter.php).

The library provides two possibilities to limit the result:

- using the `limit_length` option (for more information please refer to [options](#options))
- using a custom Limiter with a pre-defined max length (the library contains a `LengthLimiter` class that limits by length and a `PercentLimiter` class that limits by a text's percent that can be configured)

Options
-------

[](#options)

The `KeywordsExtractor` class accepts some configuration options:

```
'extractor'                     # An Extractor instance that does all of the extraction work.
'assets_path'                   # A string with a valid path with write permissions to keep assets.
'add_words' => value            # A string or an array of words to add to the result (if they are ignored by an Extractor).
'remove_words' => value         # A string or an array of words to remove from the result (if they are not ignored by an Extractor).
'limiter'                       # A Limiter instance that limits the length of the end result.
'limit_length'                  # An integer defines the maximum length of the result (is used only when a Limiter is not provided).

```

**Note:** At the moment of instantiation, the `KeywordsExtractor` class can throw a few exceptions: `InvalidOptionType`, `InvalidOptionValue`. These exceptions extend a built-in `InvalidArgumentException` class, so they are easy to deal with.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

**Note:** Please make sure to update tests as appropriate.

License
-------

[](#license)

The MIT License (MIT). Please see the [License file](LICENSE.md) for more information

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance45

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Total

4

Last Release

456d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cb0dfa9fab98bfb2cb6c697744ea5c1f7f57ffd6b0a498df6a17223912b617a?d=identicon)[Sergey Kudashev](/maintainers/Sergey%20Kudashev)

---

Top Contributors

[![kudashevs](https://avatars.githubusercontent.com/u/15892462?v=4)](https://github.com/kudashevs "kudashevs (137 commits)")

---

Tags

keywordskeywords-extractionkeywords-extractorkeywords-generatorphpkeywordskeywords extractorkeywords generator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kudashevs-keywords-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/kudashevs-keywords-extractor/health.svg)](https://phpackages.com/packages/kudashevs-keywords-extractor)
```

###  Alternatives

[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)

PHPackages © 2026

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