# 실행: python3 tmp/rf_draft/leaf_id.py "<####>" import sys, re, unicodedata as u CHO=['g','kk','n','d','tt','r','m','b','pp','s','ss','','j','jj','ch','k','t','p','h'] JUNG=['a','ae','ya','yae','eo','e','yeo','ye','o','wa','wae','oe','yo','u','wo','we','wi','yu','eu','ui','i'] JONG=['','k','k','k','n','n','n','t','l','k','m','l','l','l','p','l','m','p','p','t','t','ng','t','t','k','t','p','t'] def rom(s): o=[] for c in u.normalize('NFC', s): n=ord(c) if 0xAC00<=n<=0xD7A3: i=n-0xAC00; o.append(CHO[i//588]+JUNG[(i%588)//28]+JONG[i%28]) elif c.isascii() and c.isalnum(): o.append(c.lower()) else: o.append('-') return re.sub(r'-+','-',''.join(o)).strip('-') def norm(s): s=u.normalize('NFC', s) return ''.join(ch for ch in s if ch not in ' \t・·•,()') SKIP={'가사소송','가족관계등록','행정소송'} leaves=[] for ln in open('case_kinds.md', encoding='utf-8'): ln=u.normalize('NFC', ln).strip() if not ln.startswith('|'): continue cells=[c.strip() for c in ln.strip('|').split('|')] if len(cells)<3 or cells[0]=='소송 대분류' or set(cells[0])<=set('- '): continue big, dis, kinds = cells[0], cells[1], cells[2] if big in SKIP: continue leaves += [dis] if not kinds else [p.strip() for p in kinds.split(',') if p.strip()] assert len(leaves)==137, f'leaf 총수 {len(leaves)} != 137 — 중단' for n, nm in ((1,'대여금 청구'),(60,'종류물(대체물)의 지급 또는 인도를 구하는 소'), (66,'매매를 원인으로 한 소유권이전등기 청구'),(128,'기타 확인청구'), (137,'주주총회결의취소의 소')): assert norm(leaves[n-1])==norm(nm), f'검산 실패 PROV-{n:03d}: {leaves[n-1]}' q=norm(sys.argv[1]); hit=[(i,x) for i,x in enumerate(leaves,1) if norm(x)==q] assert len(hit)==1, f'사건종류 매칭 {len(hit)}건 — 중단' i, name = hit[0] print(f'PROV-{i:03d}', name, rom(name), sep='\t')