yooper/stop-words
Collection of stop-word lists gathered from public sources for filtering text in multiple languages. Includes one-word-per-line files and welcomes contributions and validation ideas to improve stop-word quality.
Install via Composer:
composer require yooper/stop-words
Begin by instantiating the StopWords service and using default English stop words:
use Yooper\StopWords\StopWords;
$stopWords = new StopWords();
$clean = $stopWords->filter('The quick brown fox jumps over the lazy dog');
// Result: 'quick brown fox jumps over lazy dog'
First use case: clean user-submitted search queries before passing them to your search engine (e.g., Elasticsearch) to reduce noise and improve relevance.
StopWords in a service provider or use it directly in jobs, services, or models (e.g., App\Services\TextCleaner).en, fr, es, etc.) or extend with your own via addStopWords(array $words) or setStopWords(array $words).isStopWord(string $word) to filter tokens conditionally:
$tokens = preg_split('/\s+/', 'Data science is an interdisciplinary field');
$filtered = array_filter($tokens, fn($w) => !$stopWords->isStopWord($w));
setLanguage('en')) or use strict(false) to preserve case-insensitive matches (e.g., “The” → removed).isStopWord('THE') returns true). Use setStrict(true) if you need case-sensitive control.filter() collapses multiple spaces. Use preg_replace('/\s+/', ' ', trim($result)) post-filter if precise spacing matters.setStopWords() with your custom array—ideal for domain-specific terms (e.g., removing “CPU”, “RAM” from tech product descriptions).How can I help you explore Laravel packages today?