ppuzio's picture
Add source rights-review skill and 2026-10 rights audit evidence
4092152
Raw History Blame
2.08 kB
import pyarrow.parquet as pq, pandas as pd, random, re, json, html, unicodedata, difflib, subprocess, sys, time
sys.path.insert(0,'src')
P='data/saos/'
f=pq.ParquetFile(P+'saos.parquet')
a=pd.read_pickle('attr.pkl')
random.seed(21)
pick=[]
for court,n in [('COMMON',3),('SUPREME',3),('NATIONAL_APPEAL_CHAMBER',2),('CONSTITUTIONAL_TRIBUNAL',2)]:
sub=a[a.court==court]
pick+= list(sub.sample(n,random_state=7).index)
TR=str.maketrans({"\u00a0":" ","\u2007":" ","\u202f":" ","\u200b":"","\ufeff":"","\u00ad":"","\u2010":"-","\u2011":"-","\u2012":"-","\u2013":"-","\u2014":"-","\u2212":"-","\u2018":"'","\u2019":"'","\u201c":'"',"\u201d":'"',"\u2026":"..."})
def norm(s):
s=unicodedata.normalize('NFKC',html.unescape(s)).translate(TR)
s=re.sub(r'\[(?:PII:)?(?:PHONE|EMAIL|PESEL|IDENTIFIER|ACCOUNT)\]','',s)
return re.sub(r'\s+',' ',s).strip()
def strip_html(h):
h=re.sub(r'<br\s*/?>|</p>|</div>|</h\d>|</tr>|</li>','\n',h)
h=re.sub(r'<[^>]+>','',h)
return h
out=[]
for idx in pick:
import numpy as np
st=np.load('rgstart.npy'); rg=int(np.searchsorted(st,idx,side='right')-1)
t=f.read_row_group(rg,columns=['id','text']).to_pandas()
row=t.iloc[idx-st[rg]]
sid=row.id.replace('saos_','')
r=subprocess.run(['curl','-sL','-m','60',f'https://www.saos.org.pl/api/judgments/{sid}'],capture_output=True,text=True)
try: d=json.loads(r.stdout)['data']
except Exception as e: print(sid,'FETCH FAIL',r.stdout[:200]); continue
live=norm(strip_html(d['textContent'] or ''))
mine=norm(row.text)
sm=difflib.SequenceMatcher(None,live,mine,autojunk=False) if len(live)<70000 and len(mine)<70000 else None
ratio=sm.ratio() if sm else None
print(sid,a.court[idx],a.jt[idx],'len live',len(live),'len snap',len(mine),'equal',live==mine,'ratio',ratio, 'live_summary',bool(d.get('summary')),'decision',bool(d.get('decision')))
if live!=mine and sm:
for tag,i1,i2,j1,j2 in sm.get_opcodes():
if tag!='equal': print(' ',tag,repr(live[i1:i2][:80]),'->',repr(mine[j1:j2][:80]))
time.sleep(0.5)