voku/stop-words
PHP library providing curated stop-word lists for many languages (e.g., en, de, fr, es, ru, ar). Simple API to fetch stop words by language code, useful for search, indexing, and text processing pipelines.
$text = $stopWords->filter($tokenizer->tokenize($text));
composer require voku/stop-words) with no Laravel-specific dependencies.$this->app->singleton(StopWords::class, function () {
return new StopWords('en');
});
toSearchableArray() or Scout hooks).rubix/ml or php-stan/stan for advanced text processing.FilterStopWords middleware to normalize incoming requests (e.g., API payloads).preg_replace('/[^\p{L}\p{N}]/u', ' ', $text)).null, non-string inputs).laravel-text-classifier)?SearchService, ContentAnalyzer).// app/Providers/AppServiceProvider.php
public function boot() {
$this->app->bind('stopwords', function () {
return new StopWords(config('app.locale'));
});
}
Usage: app('stopwords')->filter($text).// app/Console/Commands/ProcessContent.php
protected $stopWords;
public function __construct(StopWords $stopWords) { $this->stopWords = $stopWords; }
Creating event for Post) or queues (e.g., ProcessUserContentJob).composer require voku/stop-words --dev
$stopWords = new StopWords('en');
$result = $stopWords->filter("The quick brown fox");
// Assert: "quick brown fox"
Symfony\Component\Stopwords).StopWords instance if instantiated frequently:
$cachedStopWords = Cache::remember("stopwords_{$lang}", now()->addHours(1), function () use ($lang) {
return new StopWords($lang);
});
toSearchableArray()) or storing user content:
// App/Models/Post.php
public function toSearchableArray() {
return [
'title' => app('stopwords')->filter($this->title),
'body' => app('stopwords')->filter($this->body),
];
}
SearchResult transformer) to avoid over-filtering:
// App/Transformers/SearchResultTransformer.php
public function transform($result) {
return [
'title' => app('stopwords')->filter($result['title']),
'snippet' => $this->highlightRelevantTerms($result['snippet']),
];
}
// app/Jobs/ProcessContentBatch.php
public function handle() {
foreach ($this->contents as $content) {
$content->clean_text = app('stopwords')->filter($content->raw_text);
$content->save();
}
}
addStopWords() or setStopWords():
$stopWords = new StopWords('en');
$stopWords->addStopWords(['custom', 'terms']); // Merge with defaults
$stopWords->setStopWords(['only', 'these']); // Override entirely
getAvailableLanguages()).$cleanText = preg_replace('/[^\p{L}\p{N}\p{P}]/u', ' ', $text);
logger()->debug('Filtered terms:', $stopWords->getStopWords('en'));
addStopWords() for domain-specific terms").How can I help you explore Laravel packages today?