*/ public static function from(string $question): array { $words = preg_split('/[^\p{L}\p{N}-]+/u', mb_strtolower($question), -1, PREG_SPLIT_NO_EMPTY) ?: []; $terms = []; foreach ($words as $word) { $word = trim($word, '-'); if (mb_strlen($word) < 3 || in_array($word, self::STOPWORDS, true)) { continue; } $terms[] = self::stem($word); // „MAV-Wahl“ findet auch „Wahl der MAV“ if (str_contains($word, '-')) { foreach (explode('-', $word) as $part) { if (mb_strlen($part) >= 3 && ! in_array($part, self::STOPWORDS, true)) { $terms[] = self::stem($part); } } } } return array_slice(array_values(array_unique($terms)), 0, self::MAX); } public static function stem(string $word): string { // Abkürzungen und Zahlen (z. B. „MAV“, „2026“) unverändert lassen if (mb_strlen($word) <= 4 || preg_match('/\d/u', $word)) { return $word; } foreach (self::ENDINGS as $ending) { if (str_ends_with($word, $ending) && mb_strlen($word) - mb_strlen($ending) >= 4) { return mb_substr($word, 0, mb_strlen($word) - mb_strlen($ending)); } } return $word; } }