*/ public static function from(string $question): array { $original = preg_split('/[^\p{L}\p{N}-]+/u', $question, -1, PREG_SPLIT_NO_EMPTY) ?: []; $terms = []; foreach ($original as $raw) { $word = mb_strtolower(trim($raw, '-')); // Kurze Abkürzungen in Großbuchstaben zählen („IT“, „QM“, „BW“) – sonst erst ab drei Zeichen $abbreviation = mb_strlen($word) === 2 && preg_match('/^\p{Lu}{2}$/u', trim($raw, '-')); if ((mb_strlen($word) < 3 && ! $abbreviation) || in_array($word, self::STOPWORDS, true)) { continue; } $terms[] = self::stem($word); // „MAV-Wahl“ findet auch „Wahl der MAV“ if (str_contains($word, '-')) { foreach (explode('-', trim($raw, '-')) as $part) { if ((mb_strlen($part) >= 3 || preg_match('/^\p{Lu}{2}$/u', $part)) && ! in_array(mb_strtolower($part), self::STOPWORDS, true)) { $part = mb_strtolower($part); $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; } }