{"version":3,"sources":["../../src/turn_detector/utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Text normalization utilities for EOU turn detector\n */\n\n/**\n * Simple unicode category detection for punctuation\n * Mimics Python's unicodedata.category() for punctuation detection\n */\nexport function getUnicodeCategory(char: string): string {\n  const code = char.codePointAt(0);\n  if (!code) return '';\n\n  // Basic punctuation ranges (simplified version to match Python unicodedata.category)\n  if (\n    (code >= 0x21 && code <= 0x2f) || // !\"#$%&'()*+,-./\n    (code >= 0x3a && code <= 0x40) || // :;<=>?@\n    (code >= 0x5b && code <= 0x60) || // [\\]^_`\n    (code >= 0x7b && code <= 0x7e) || // {|}~\n    (code >= 0xa0 && code <= 0xbf) || // Latin-1 punctuation\n    (code >= 0x2000 && code <= 0x206f) || // General punctuation\n    (code >= 0x3000 && code <= 0x303f)\n  ) {\n    // CJK symbols and punctuation\n    return 'P';\n  }\n  return '';\n}\n\n/**\n * Normalizes text to match the training data format used by the EOU model\n *\n * This function applies the following transformations:\n * 1. Converts to lowercase\n * 2. Applies Unicode NFKC normalization\n * 3. Removes all punctuation except apostrophes (') and hyphens (-)\n * 4. Collapses multiple whitespace characters into single spaces\n * 5. Trims leading and trailing whitespace\n *\n * @param text - The input text to normalize\n * @returns The normalized text\n *\n * @example\n * ```typescript\n * normalizeText(\"Hi, how can I help you today?\")\n * // Returns: \"hi how can i help you today\"\n *\n * normalizeText(\"I'm a well-trained assistant!\")\n * // Returns: \"i'm a well-trained assistant\"\n *\n * normalizeText(\"Price: $19.99 (20% off).\")\n * // Returns: \"price 1999 20 off\"\n * ```\n */\nexport function normalizeText(text: string): string {\n  if (!text) return '';\n\n  let normalized = text.toLowerCase().normalize('NFKC');\n\n  // Remove punctuation except apostrophes and hyphens\n  // Using character-by-character approach to match Python logic\n  normalized = Array.from(normalized)\n    .filter((ch) => {\n      const category = getUnicodeCategory(ch);\n      return !(category.startsWith('P') && ch !== \"'\" && ch !== '-');\n    })\n    .join('');\n\n  // Collapse whitespace and trim\n  normalized = normalized.replace(/\\s+/g, ' ').trim();\n\n  return normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,mBAAmB,MAAsB;AACvD,QAAM,OAAO,KAAK,YAAY,CAAC;AAC/B,MAAI,CAAC,KAAM,QAAO;AAGlB,MACG,QAAQ,MAAQ,QAAQ;AAAA,EACxB,QAAQ,MAAQ,QAAQ;AAAA,EACxB,QAAQ,MAAQ,QAAQ;AAAA,EACxB,QAAQ,OAAQ,QAAQ;AAAA,EACxB,QAAQ,OAAQ,QAAQ;AAAA,EACxB,QAAQ,QAAU,QAAQ;AAAA,EAC1B,QAAQ,SAAU,QAAQ,OAC3B;AAEA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AA2BO,SAAS,cAAc,MAAsB;AAClD,MAAI,CAAC,KAAM,QAAO;AAElB,MAAI,aAAa,KAAK,YAAY,EAAE,UAAU,MAAM;AAIpD,eAAa,MAAM,KAAK,UAAU,EAC/B,OAAO,CAAC,OAAO;AACd,UAAM,WAAW,mBAAmB,EAAE;AACtC,WAAO,EAAE,SAAS,WAAW,GAAG,KAAK,OAAO,OAAO,OAAO;AAAA,EAC5D,CAAC,EACA,KAAK,EAAE;AAGV,eAAa,WAAW,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAElD,SAAO;AACT;","names":[]}