# Rule-based extraction of activation-type calls from hi-orig auto captions. Conservative; every field records its evidence text. import re,sys,json,datetime as dt,pandas as pd sys.path.insert(0,'scripts'); from subs2txt import load ACT=re.compile(r'एंट्री (एक्टिवेट|एक्टिवेटेड|हो गई|हो गया|ले ली|ली है|ले लिया|मिल गई|दे दी)|हमने एंट्री ली|एंट्री ले ली|ट्रेड पंच|एंट्री ले लो|एंट्री लो|यही एंट्री है|ट्रेड ले लो|ट्रेड लो|एंट्री करो|एक एंट्री ली|ले लो भाई|अभी एंट्री|ट्रेड ले लिया') CE=re.compile(r'कॉल|सीई|\bCE\b'); PE=re.compile(r'पुट|पीई|\bPE\b') NUM=r'(\d{1,3})' SL=[re.compile(NUM+r'\s*(-\s*\d{1,3}\s*)?पॉइंट(्स)?\s*(का|के)?\s*(भाई\s*)?(एसएल|रिस्क|स्टॉप)'),re.compile(r'(एसएल|स्टॉप लॉस|रिस्क)[^।?]{0,25}?\b'+NUM+r'\s*पॉइंट')] TG=[re.compile(NUM+r'\s*पॉइंट(्स)?\s*(का|के)?\s*(कम से कम\s*)?(पहला\s*)?टारगेट'),re.compile(r'(पहला|फर्स्ट|मिनिमम)\s*टारगेट[^।?]{0,25}?\b'+NUM+r'\s*पॉइंट'),re.compile(r'टारगेट[^।?]{0,15}?\b'+NUM+r'\s*पॉइंट')] CT=re.compile(r'(टारगेट|T1|टारगेट वन|फर्स्ट टारगेट|पहला टारगेट)\s*(वन\s*)?(डन|टच|आ गया|आ चुका|कंप्लीट|हिट|पूरा)') CS=re.compile(r'(एसएल|स्टॉप लॉस|एल)\s*(आ गया|आ गए|हो गया|हो गई|हिट|लग गया|लग गए|चला गया|गया|खा|घुस)') def segs(vid): return load(f'data/subs/{vid}.hi-orig.json3') def win(L,a,b): return ' '.join(x for t,x in L if a<=t<=b) def first(rx,s): for r in rx: m=r.search(s) if m: n=[g for g in m.groups() if g and g.isdigit()] if n: return int(n[0]),m.group(0) return None,None def extract(vid,start): L=segs(vid); st=dt.datetime.fromisoformat(start); calls=[]; last=-1e9 for t,x in L: if ACT.search(x) and t-last>300 and 'गोल्ड' not in win(L,t-60,t+60): last=t; w=win(L,t-90,t+30) # side: count nearest mentions within -90..+30s nce=len(CE.findall(w)); npe=len(PE.findall(w)); side='CE' if nce>npe else ('PE' if npe>nce else None) pre=win(L,t-240,t+120); slp,slev=first(SL,pre); tgp,tgev=first(TG,pre) post=[(tt,xx) for tt,xx in L if t