"""Conservative independent intent gate for instructions without confirmed slots. Only registered aliases and explicit quantities are accepted. Other language asks for structured clarification; this parser is not claimed to cover arbitrary NLP. """ import re COUNTS={'一':1,'二':2,'两':2,'三':3,'四':4,'五':5,'六':6,'七':7,'八':8,'九':9,'十':10,'one':1,'two':2,'three':3} def matches(instruction,registry,aliases): candidates=[] for key in registry: for term in [key]+list(aliases.get(key,[])): if not term:continue for m in re.finditer(re.escape(term),instruction):candidates.append((m.start(),m.end(),key)) chosen=[] for item in sorted(candidates,key=lambda x:(-(x[1]-x[0]),x[0])): if not any(item[0]