"""Keyword extraction for grep-based codebase searching."""

from __future__ import annotations

_STOP_WORDS = {
    "the",
    "a",
    "an",
    "is",
    "are",
    "was",
    "were",
    "be",
    "been",
    "being",
    "have",
    "has",
    "had",
    "do",
    "does",
    "did",
    "will",
    "would",
    "could",
    "should",
    "may",
    "might",
    "must",
    "shall",
    "can",
    "to",
    "of",
    "in",
    "for",
    "on",
    "with",
    "at",
    "by",
    "from",
    "as",
    "into",
    "through",
    "during",
    "before",
    "after",
    "above",
    "below",
    "between",
    "and",
    "or",
    "but",
    "not",
    "no",
    "if",
    "then",
    "else",
    "when",
    "where",
    "how",
    "all",
    "each",
    "every",
    "any",
    "both",
    "few",
    "more",
    "most",
    "other",
    "some",
    "such",
    "only",
    "own",
    "same",
    "than",
    "too",
    "very",
    "that",
    "this",
    "it",
    "its",
    "which",
    "what",
    "who",
}


def extract_keywords(text: str) -> list[str]:
    """Extract meaningful keywords from AC text for grep."""
    words = text.lower().replace("`", "").replace("(", " ").replace(")", " ").split()
    return [w for w in words if len(w) > 3 and w not in _STOP_WORDS][:5]
