Files
Liti-agent-Development/요건사실론/plans/extract-remaining-elements/agent1_extract.py
T
jhogyuandClaude Fable 5.1 5f9853e44b chore: snapshot of work since 2026-10-05 (Stage 1 v.8, S2_00 v7.4/v7.5 handoff, S2_10 rewrite research v.2, 청구취지·요건사실 corpora)
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>
2026-10-12 13:02:13 +09:00

85 lines
5.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import json,re,hashlib,pathlib
BASE=pathlib.Path('.')
B=json.loads((BASE/'plans/extract-remaining-elements/batch_1.json').read_text())
# Deliberately selected substantive subsection scope; original numbering supports traceability.
KEEP={'1.1','1.2','1.4','2.1','2.2','2.3','3.1','3.2','3.3','3.4','3.5','3.6','4.2','4.4','8.4','9.4','10.4','12.6'}
# Per-document §12.7 rows selected after reading legal effect / unresolved lists.
ROWS={0:[1,2,3,4,5,6,7,9,10,15],1:list(range(1,14))+[15,17,18,19,20,22],2:[1,2,3,4,5,6,8,9,13,14,15,16,17,18,20],3:[2,3,4,5,6,7,8,12,13,14,16,17],4:[1,2,3,4,5,7,8,9,10,11,12,17,18,19,20],5:list(range(1,8))+[9,10,11,12,14,15,16,17,18],6:[2,3,4,5,6,7,10,11,13],7:[2,3,4,5,6,7,8,9,10,11],8:[2,3,4,6,7,10,11,13,14],9:[2,3,4,5,6,7,9],10:[2,3,4,5,6],11:[2,3,4,5,6,7],12:[2,3,4,5,6],13:[2,3,4,5,6,7,8,10,11,12],14:[3,4,5,6,8,9],15:[2,3,4,5,6,7,8,10,11],16:[2,3,4,5,7],17:[2,3,4,5,6,7,8,9],18:[2,4,5,6,7,8,9,10,11,12,15,16,17],19:[1,2,3,4],20:[2,3,4,5,6,8,9,10],21:[2,3,4,5,6,7,8,9,10,13,16],22:[2,3,4,5,6,7,8],23:[1,2,3,4,5,7,8],24:[2,3,4,5,6,8],25:[1,2,3,4,5,6],26:[2,3,4,5,6,8],27:list(range(1,9)),28:[1,2,3,4,5],29:[2,3,4,5,6,7,8],30:list(range(2,9)),31:[1,2,3,4,5,6,7,10],32:list(range(1,9))}
def clean(t):
t=re.sub(r'\[([^\]]+)\]\(https?://[^\s)]+\)',r'\1',t)
t=re.sub(r'https?://[^\s<>|)]+','',t)
# Only null/non-operative template fields; preserve conditions accompanying "없음".
t=re.sub(r'^[-*] \*\*(?:다중 대응|추정·전환|재재항변|부수급부)\*\*\s*[::]\s*(?:없음|해당 없음)[.。]?\s*$', '',t,flags=re.M)
# Evidence inventories are excluded only when the complete line contains no operative prose.
lines=[]
for line in t.splitlines():
if re.match(r'^[-*] \*\*증명 실무\*\*\s*[::]',line):
payload=line.split('**',2)[-1]
if not re.search(r'(다[.。]|한다|된다|여야|경우|추정|증명책임|부담|요건|다만|한정|제외|조건|UNVERIFIED|UNKNOWN|QUALIFIED)',payload):continue
lines.append(line)
t='\n'.join(lines)
return re.sub(r'\n{3,}','\n\n',t).strip()
def scope_parts(s):
# Heading segmentation at level 2 and 3, retaining detailed level 4+ facts intact.
chunks=re.split(r'(?=^#{2,3} )',s,flags=re.M)
out=[]
for c in chunks:
h=c.split('\n')[0]
n=re.match(r'^### (\d+\.\d+|5\.P\d+)\b',h)
major=re.match(r'^## §(\d+)\.',h)
if major and int(major[1]) in [1,2,3,4,5,6]:
# Include semantic introduction to sections, excluding schema scaffolding.
out.append(c)
elif n and (n[1] in KEEP or n[1].startswith('5.P') or n[1].startswith('6.')):out.append(c)
elif h.startswith('### 6.'):out.append(c)
return out
def rows(s,i):
t=s.split('### 12.7',1)[1]
ls=t.splitlines(); table=[x for x in ls if x.startswith('|')]
if table:
data=[x for x in table[2:] if x.strip('| ').strip()]
else:
data=[]
for x in ls:
if re.match(r'^(?:\d+\.\s|[-*] )',x):data.append(x)
return [data[j-1] for j in ROWS[i] if j<=len(data)]
for i,r in enumerate(B):
p=BASE/r['source'];s=p.read_text();assert hashlib.sha256(p.read_bytes()).hexdigest()==r['sha256']
fm=s.split('---',2)[1]
val=lambda k: (re.search(r'^'+k+r':\s*(.*)$',fm,re.M).group(1) if re.search(r'^'+k+r':\s*(.*)$',fm,re.M) else '未記載')
h=re.search(r'^# .+',s,re.M).group(0)
out=f'''{h} — 要件事項抽出 v2
> 原文に基づく抽出編集。以下の記載は原文の法令基準日・検証状態を引き継ぐものであり、今回、法令・判例を独立して再検証したものではない。
'''
# Korean artifact; legal statuses copied without upgrading.
out=f'''{h} — 요건사실 항목 추출 v2
- 사건 식별자: `{val('case_kind_id').strip(chr(34))}`
- 원문 법령 기준일: `{val('law_as_of').strip(chr(34))}`
- 원문 검증상태: `{val('verification_status').strip(chr(34))}`
- 원문: [{p.name}](../raw/{p.name})
> 원문의 요건·적용 조건·예외·주장증명책임·항변·기간·주문 특정에 관한 추출본이다. 절 번호와 요건/근거 ID는 원문 연결을 위해 유지했다. 원문 검증상태는 승계 표지이며 이번 추출에서 법령·판례를 재검증한 결과가 아니다. 아래에서 생략한 절을 참조하는 표시는 위 원문의 해당 절을 가리킨다. 원문 내부 설명이 충돌하거나 미해결로 표시된 사항은 확정된 규칙으로 취급하지 않는다.
'''
out+='\n\n'.join(clean(c) for c in scope_parts(s))
selected=rows(s,i)
if selected:
out+='\n\n## §12. 요건 선택·분류에 관련된 원문 유보\n\n'
out+='순수 서지목록과 조사 경과는 원문에서 확인한다. 다음은 요건 해석에 영향을 주는 항목이다.\n\n'
# Convert arbitrary original table columns into bullets, keeping complete legal qualification.
for row in selected:
if row.startswith('|'):
cells=[x.strip() for x in row.strip().strip('|').split('|')]
if cells and re.fullmatch(r'(?:\d+|U-\d+)',cells[0]):cells=cells[1:]
out+='- '+' — '.join(cells)+'\n'
else:out+='- '+re.sub(r'^(?:\d+\.\s*|[-*] )','',row)+'\n'
out=clean(out)+'\n'
dest=BASE/r['output'];dest.write_text(out)
print(i,r['case'],len(s.encode()),len(out.encode()),round(100*(1-len(out.encode())/len(s.encode())),1))