File size: 778 Bytes
9b3794b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """
core/text.py — ตัวช่วยข้อความที่ใช้ร่วมกันทุกแบรนด์ (ไม่มีความรู้เรื่องสินค้า)
"""
from __future__ import annotations
import re
from typing import Iterable, Optional
def norm_code(s: str) -> str:
"""MP8 0 C / MP80-C / mp80c → MP80C (& ในรหัสที่ OCR อ่านผิดก็ตัดทิ้ง)"""
return re.sub(r"[^A-Z0-9%]", "", (s or "").upper())
def has(pattern: str, text: str) -> bool:
return bool(re.search(pattern, text or "", re.IGNORECASE))
def any_word(words: Iterable[str], text: str) -> Optional[str]:
low = (text or "").lower()
return next((w for w in words if w.lower() in low), None)
|