File size: 813 Bytes
456aba5
 
 
247f65e
 
 
456aba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# src/utils.py
from __future__ import annotations
from typing import Optional

from src.config import ARTICLE_ID_RE, LIST_TRIGGERS, FULLTEXT_TRIGGERS, EXPLAIN_TRIGGERS



def normalize_article_id(raw: str) -> str:
    return (raw or "").strip().upper().replace(" ", "").replace(".", "-")

def extract_article_id(q: str) -> Optional[str]:
    m = ARTICLE_ID_RE.search(q or "")
    return normalize_article_id(m.group(1)) if m else None

def is_list_request(q: str) -> bool:
    ql = (q or "").lower()
    return any(t in ql for t in LIST_TRIGGERS)

def is_fulltext_request(q: str) -> bool:
    ql = (q or "").lower()
    return any(t in ql for t in FULLTEXT_TRIGGERS)

def is_synthesis_request(q: str) -> bool:
    ql = (q or "").lower()
    return any(t in ql for t in EXPLAIN_TRIGGERS)