Case_02_Comparison_Research - Stage 1 v.8: Part 1~4 YAMLs with R1~R3 patches, F-1/F-2 fixes, 피고과식별방지 prompt (defendant_qualification), dated backups, 실행검사/실패분석 reports - Stage 2 S2_00: v7.4 handoff (Task_S2_00_handoff, 경량화 전략서 + §2 개정) and v7.5 defendant qualification gate (피고관련작업_개정_S2_00.md), copies v.7/v.10/v.11, dated backups, 실행보고서/실패분석/결과물 리스트 - Stage 2 S2_10: v6/v7/v8 failure analyses, 재작성전략 10_06/10_08, case_kind_registry.json, 연구조사보고서_S2_10_재작성용.md (v.1), _추가.md (multi-claim methodology) and merged _v.2.md (claims[] 1~4, join PRELIMINARY/SELECTIVE/INDEPENDENT, V1~V6), S2_10_Test run outputs, 실행검사 v.10/v.11 - Stage_2 MEMORY.md / CLAUDE.md / work-history notes, AGENTS.md and README_KO.md updates Other corpora and tooling - Default_Agent_청구취지기재방법: 청구취지 규칙문서 전체 모음(원문·사건종류별·raw) and tmp drafts - 요건사실론: 사건종류별 문서(raw·filtered), plans, rf_draft - 판례모음, STT_앱구성_연구, API Crowdness 조사, update_numbers.py Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
43 lines
3.3 KiB
Python
43 lines
3.3 KiB
Python
import re,json,hashlib
|
|
from pathlib import Path
|
|
B=Path('plans/extract-remaining-elements'); batch=json.loads((B/'batch_2.json').read_text());notes=json.loads((B/'agent2_review_notes.json').read_text())
|
|
def sections(t):
|
|
ms=list(re.finditer(r'(?m)^(#{2,3}) (?:§)?(\d+(?:\.(?:P\d+|\d+))?)\.?[^\n]*',t));return {m[2]:t[m.end():ms[i+1].start() if i+1<len(ms) else len(t)].strip() for i,m in enumerate(ms)}
|
|
def clean(t):
|
|
t=re.sub(r'\[([^\]\n]+)\]\(https?://[^\s)]+\)',r'\1',t);t=re.sub(r'https?://[^\s<>|)]+','',t);t=re.sub(r'(?<!원문 )§(?=\d)','원문 §',t);return t.strip()
|
|
ledger=[]
|
|
for i,x in enumerate(batch):
|
|
s=Path(x['source']).read_text();p=Path(x['output']);o=p.read_text();sec=sections(s)
|
|
o=o.replace('## 1. 청구경로 선택','## 1. 청구경로 선택\n\n**추출 시 적용 구별:** '+notes[str(i)]['focus']+' (원문 §1·§4·§5·§6·§12.7)')
|
|
for key,dest in [('4','## 3. 공통·경로별 요건사실'),('5','## 3. 공통·경로별 요건사실'),('6','## 4. 부인·항변·재항변')]:
|
|
if sec.get(key):o=o.replace(dest,dest+'\n\n'+clean(sec[key]))
|
|
# The burden catalogue repeats the complete element blocks, sometimes with truncated cells.
|
|
o=re.sub(r'(?ms)^### 주장·증명책임 연결표\n.*?(?=^### 증명책임·추정|^## 5\.)','',o)
|
|
# Recover normative material from mixed evidence fields; omit purely evidential lists.
|
|
ids=list(re.finditer(r'(?m)^#{3,6} [^\n]*\b(R-PROV\d+-[45]-\d+)\b[^\n]*',s)); recovered=[]
|
|
for n,m in enumerate(ids):
|
|
end=ids[n+1].start() if n+1<len(ids) else len(s)
|
|
block=s[m.end():end];block=re.split(r'(?m)^#{2,3} ',block)[0]
|
|
fields=re.findall(r'(?m)^- \*\*증명 실무\*\*[^\n]*(?:\n[ \t]+[^\n]+)*',block)
|
|
for field in fields:
|
|
if not re.search(r'추정|간주|입증책임|증명책임|주장책임|주요사실|요건|조건|반증|무효|대항|의제|동시이행|상환|익명조합|출자금|평가근거',field):continue
|
|
rid=m[1]; patt=r'(?m)^#{3,6} [^\n]*\b'+re.escape(rid)+r'\b[^\n]*'
|
|
om=re.search(patt,o)
|
|
if om:
|
|
boundary=re.search(r'(?m)^#{2,6} ',o[om.end():]);oe=om.end()+boundary.start() if boundary else len(o)
|
|
add=clean(field).replace('**증명 실무**','**적용·입증 보충**')
|
|
if add not in o[om.end():oe]:o=o[:oe].rstrip()+'\n'+add+'\n\n'+o[oe:];recovered.append(rid)
|
|
o=o.replace('<!-- CASE_REVIEW_LIMITS -->','다음은 원문 §12.7에서 요건 선택·분류·적용에 영향을 주는 한계만 간추린 것이다.\n\n'+notes[str(i)]['limits'])
|
|
# Remove duplicated statements only when text is exactly identical; retain tables and headings.
|
|
paras=o.split('\n\n'); seen=set();out=[]
|
|
for a in paras:
|
|
if not a.startswith(('#','|','---','```')) and len(a)>100:
|
|
if a in seen:continue
|
|
seen.add(a)
|
|
out.append(a)
|
|
o='\n\n'.join(out)
|
|
o=re.sub(r'\n{3,}','\n\n',o).strip()+'\n';p.write_text(o)
|
|
ledger.append({'case':x['case'],'focus':notes[str(i)]['focus'],'source_sections_reviewed':['path and element headings','12.7 full text','4/5/6 full preserved core structure','mixed evidence recovery'],'mixed_fields_preserved':recovered,'source_unchanged':hashlib.sha256(Path(x['source']).read_bytes()).hexdigest()==x['sha256'],'output_bytes':len(o.encode())})
|
|
(B/'agent2_review_ledger.json').write_text(json.dumps(ledger,ensure_ascii=False,indent=2)+'\n')
|
|
print('FINALIZED',len(ledger),'mixed_fields',sum(len(x['mixed_fields_preserved']) for x in ledger))
|