Heng2004's picture
Create qa_store.py
7171447 verified
raw
history blame
796 Bytes
# qa_store.py
from typing import List, Dict, Any
import re
# Textbook chunks
ENTRIES: List[Dict[str, Any]] = []
RAW_KNOWLEDGE: str = ""
# QA from textbook JSONL
AUTO_QA_KNOWLEDGE: List[Dict[str, Any]] = []
# Manual QA managed by teacher
MANUAL_QA_LIST: List[Dict[str, Any]] = []
MANUAL_QA_INDEX: Dict[str, Dict[str, Any]] = {}
# Combined index for fast lookup
QA_INDEX: Dict[str, str] = {}
ALL_QA_KNOWLEDGE: List[Dict[str, Any]] = []
# Counter for new manual IDs
NEXT_MANUAL_ID: int = 1
def normalize_question(q: str) -> str:
"""
Normalize Lao/English question text for matching.
Lowercase + remove punctuation + collapse spaces.
"""
q = (q or "").lower()
q = re.sub(r"[?!?!\.\,\:\;\"β€œβ€'β€˜β€™]", " ", q)
q = re.sub(r"\s+", " ", q)
return q.strip()