File size: 796 Bytes
7171447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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()