Files
Aislo/resources/tester/scratch/audit_in_as_unit.py
T

84 lines
3.1 KiB
Python

import json
import sys
import re
from pathlib import Path
sys.stdout.reconfigure(encoding='utf-8')
# Load enriched tables
sys.path.insert(0, '.')
from scratch.enrich_tables import tables
with open('resources/data_work_item_master/work_item_master_2026-01-01.json', 'r', encoding='utf-8') as f:
master = json.load(f)
master_tables = {}
for wi in master['work_items']:
for t in wi.get('tables', []):
tid = t.get('pum_table_id')
if tid:
master_tables[tid] = (wi, t)
print("=== 1. 마스터에서 basis_unit 이 '인'으로 들어간 표 전수 조사 ===")
master_in_tables = []
for tid, (wi, t) in master_tables.items():
bu = t.get('basis_unit')
if bu and '인' in str(bu):
master_in_tables.append((tid, t.get('section'), t.get('basis_quantity'), bu, t.get('pum_form'), t.get('basis_source')))
print(f"Total tables with '인' in basis_unit in Master: {len(master_in_tables)}")
for it in master_in_tables:
print(f" [{it[0]}] {it[1]} -> {it[2]} {it[3]} (form: {it[4]}, src: {it[5]})")
print("\n=== 2. 원문 MD/PDF 에서 '인' 또는 '인당'이 단위로 쓰인 표 전수 조사 ===")
unit_in_tables = []
for t in tables:
tid = t['table_id']
pre_lines = t['pre_context']
header_line = t['lines'][0] if t['lines'] else ""
# search for parenthesis unit containing '인'
found = []
for pl in reversed(pre_lines):
m = re.search(r'[\(\[\{]\s*단위\s*[:\=]?\s*([^\)\]\}]+)[\)\]\}]', pl)
if m:
u_str = m.group(1).strip()
if '인' in u_str:
found.append(('pre_context', pl, u_str))
break
# also check headers
m_h = re.search(r'[\(\[]\s*단위\s*[:\=]?\s*([^\)\]]+)[\)\]]', header_line)
if m_h:
u_str = m_h.group(1).strip()
if '인' in u_str:
found.append(('header', header_line, u_str))
# Also check if table row has "인당" in applicable standard (적용기준)
has_apply_in = any('1인당' in l or '인당' in l for l in t['lines'])
if found or has_apply_in:
unit_in_tables.append({
'table_id': tid,
'chapter': t['chapter'],
'section': t['section'],
'line': t['start_line'],
'found_units': found,
'has_apply_in': has_apply_in
})
print(f"Total tables where 원문 has '인' in unit or apply text: {len(unit_in_tables)}")
print("\n--- [A. 순수 '인' 또는 '인당' (무복합) 단위 표] ---")
pure_in = []
for it in unit_in_tables:
for src, pl, u in it['found_units']:
if u in ['인', '인당', '인/일', '인 / 일', '1인/1일']:
pure_in.append((it['table_id'], it['section'], u, pl))
print(f" [{it['table_id']}] {it['section']} -> unit: '{u}' (from: {pl})")
print(f"\n--- [B. 적용기준 셀에 '1인당'이 들어있어 마스터가 '인'으로 잘못 뽑은 표] ---")
for it in unit_in_tables:
if it['has_apply_in']:
t_master = master_tables.get(it['table_id'])
m_bu = t_master[1].get('basis_unit') if t_master else None
print(f" [{it['table_id']}] {it['section']} -> Master basis_unit: {m_bu}")