import re, sys; sys.path.insert(0,"/app")
from collections import Counter
from app.database import SessionLocal
from sqlalchemy import text as sa_text
db = SessionLocal()
rows = db.execute(sa_text("""SELECT id, question_text, explanation, image_path FROM questions
                             WHERE image_path IS NOT NULL AND image_path <> ''""")).fetchall()
CUE = re.compile(r"figure|photograph|image|shown below|pictured", re.I)
b = Counter(); only_expl=[]
for qid, q, e, ip in rows:
    s=bool(CUE.search(q or "")); x=bool(CUE.search(e or "")); b[(s,x)]+=1
    if x and not s: only_expl.append(qid)
print("stem mentions:", b[(True,True)]+b[(True,False)])
print("ONLY explanation:", b[(False,True)])
print("neither:", b[(False,False)])
print("only-expl ids:", only_expl[:10])
