const LOW_RECALL_THRESHOLD = 3;
const ACRONYMS = {
  rag: "retrieval augmented generation",
  k8s: "kubernetes",
  ml: "machine learning",
  llm: "large language model",
  ci: "continuous integration",
  cd: "continuous deployment",
  api: "application programming interface",
  ssr: "server side rendering",
  csr: "client side rendering",
  ssg: "static site generation",
  ide: "integrated development environment",
  jwt: "json web token",
  cors: "cross origin resource sharing",
  dom: "document object model",
  npm: "node package manager"
};
const PHRASE_COLLAPSE = [
  [/\buse state\b/gi, "useState"],
  [/\buse effect\b/gi, "useEffect"],
  [/\buse ref\b/gi, "useRef"],
  [/\buse memo\b/gi, "useMemo"],
  [/\buse callback\b/gi, "useCallback"],
  [/\buse context\b/gi, "useContext"],
  [/\buse reducer\b/gi, "useReducer"],
  [/\bnext js\b/gi, "nextjs"],
  [/\bnode js\b/gi, "nodejs"],
  [/\bnest js\b/gi, "nestjs"],
  [/\bnuxt js\b/gi, "nuxtjs"]
];
const STOP_WORDS = /* @__PURE__ */ new Set([
  "a",
  "an",
  "and",
  "are",
  "as",
  "at",
  "be",
  "by",
  "for",
  "from",
  "has",
  "he",
  "in",
  "is",
  "it",
  "its",
  "of",
  "on",
  "or",
  "that",
  "the",
  "to",
  "was",
  "were",
  "will",
  "with"
]);
const IRREGULAR_PLURALS = {
  child: "children",
  man: "men",
  woman: "women",
  person: "people",
  mouse: "mice",
  goose: "geese",
  foot: "feet",
  tooth: "teeth",
  ox: "oxen"
};
function pluralizeToken(token) {
  const lower = token.toLowerCase();
  if (IRREGULAR_PLURALS[lower]) return IRREGULAR_PLURALS[lower];
  return null;
}
function tryAcronymExpansion(query) {
  const tokens = query.split(/\s+/);
  for (let i = 0; i < tokens.length; i++) {
    const raw = tokens[i];
    const bare = raw.replace(/[^A-Za-z0-9]/g, "").toLowerCase();
    if (!bare) continue;
    const expansion = ACRONYMS[bare];
    if (expansion) {
      const rewritten = [...tokens];
      rewritten.splice(i + 1, 0, expansion);
      return rewritten.join(" ");
    }
  }
  return null;
}
function tryPhraseCollapse(query) {
  for (const [pattern, replacement] of PHRASE_COLLAPSE) {
    if (pattern.test(query)) {
      pattern.lastIndex = 0;
      return query.replace(pattern, replacement);
    }
  }
  return null;
}
function tryPluralization(query) {
  const tokens = query.split(/\s+/);
  const candidates = [];
  for (let i = 0; i < tokens.length; i++) {
    const t = tokens[i].toLowerCase();
    if (!t || STOP_WORDS.has(t)) continue;
    if (!/[a-z]/.test(t)) continue;
    candidates.push({ idx: i, len: t.length });
  }
  if (candidates.length === 0) return null;
  candidates.sort((a, b) => b.len - a.len);
  for (const c of candidates) {
    const pluralized = pluralizeToken(tokens[c.idx]);
    if (pluralized && pluralized !== tokens[c.idx].toLowerCase()) {
      const rewritten = [...tokens];
      rewritten[c.idx] = pluralized;
      return rewritten.join(" ");
    }
  }
  return null;
}
function expandQuery(query) {
  if (typeof query !== "string") return null;
  const trimmed = query.trim();
  if (trimmed.length === 0) return null;
  return tryAcronymExpansion(trimmed) ?? tryPhraseCollapse(trimmed) ?? tryPluralization(trimmed);
}
export {
  LOW_RECALL_THRESHOLD,
  expandQuery
};
//# sourceMappingURL=query-expansion.js.map