#!/usr/bin/env python3
from pathlib import Path
import json,sys
P=Path(__file__).resolve().parents[1];t=(P/'script/script_onion_tears.txt').read_text().casefold()
groups={
 'cell_damage':['tế bào hành','tế bào của củ hành','phá vỡ thành tế bào','tế bào bị phá vỡ'],
 'alliinase':['alliinase'],
 'sulfoxides':['sulfoxide'],
 'sulfenic_acids':['sulfenic'],
 'lfs':['lachrymatory-factor synthase','lachrymatory factor synthase'],
 'lf':['syn-propanethial-s-oxide'],
 'volatile':['dễ bay hơi','bay tới mắt'],
 'tear_film':['màng phim nước mắt','lớp phim nước mắt','phim nước mắt','tear film'],
 'trigeminal':['dây thần kinh sinh ba','trigeminal'],
 'lacrimal':['tuyến lệ'],
 'reflex_tears':['nước mắt phản xạ','phản xạ tiết lệ'],
 'tear_types':['nước mắt nền','nước mắt cảm xúc'],
 'not_sulfuric':['không phải acid sulfuric','không phải axit sulfuric','không phóng acid sulfuric'],
 'variability':['hành vàng','hành trắng','hành đỏ'],
 'cooking':['nấu chín','nhiệt'],
 'sharp_knife':['dao sắc'],
 'ventilation':['thông gió','quạt'],
 'no_rub':['không dụi','đừng dụi','đừng đưa bàn tay vừa chạm hành lên dụi'],
 'rinse':['nước sạch','rửa mắt'],
 'knife_safety':['an toàn với dao','an toàn dao','kỹ thuật an toàn','đặt dao xuống một cách an toàn'],
 'red_flags':['thay đổi thị lực','nhạy sáng'],
 'assessment':['đánh giá y tế','đi khám']
}
missing=[k for k,v in groups.items() if not any(x in t for x in v)]
out={'status':'PASS' if not missing else 'FAIL','missing':missing,'groups':len(groups)}
(P/'logs/script_semantic_gate.json').write_text(json.dumps(out,ensure_ascii=False,indent=2)+'\n');print(json.dumps(out,ensure_ascii=False));sys.exit(bool(missing))
