84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
import json
|
|
import sys
|
|
import re
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
from scratch.enrich_tables import tables, get_chapter
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
# Load Master
|
|
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] = t
|
|
|
|
# Filter target chapters: 1, 2, 5, 9, 12, 13
|
|
target_tids = []
|
|
for t in tables:
|
|
ch = t['chapter']
|
|
if any(k in ch for k in ['제1장', '제2장', '제5장', '제9장', '제12장', '제13장']):
|
|
target_tids.append(t)
|
|
|
|
print(f"Tables in target chapters: {len(target_tids)}")
|
|
|
|
basis_pattern = re.compile(r'\[\s*([0-9\.\,]*)\s*([a-zA-Z㎡㎥㏊ha본개공mkm㎏gtonLℓ대인組]+)\s*당\s*\]')
|
|
basis_pattern2 = re.compile(r'\(단위\s*:\s*([^\)]+)\)')
|
|
|
|
target_issues = []
|
|
for t in target_tids:
|
|
tid = t['table_id']
|
|
ch = t['chapter']
|
|
pre_lines = t['pre_context']
|
|
|
|
found_basis_qty = None
|
|
found_basis_unit = None
|
|
found_basis_src = None
|
|
|
|
for pl in reversed(pre_lines):
|
|
m = basis_pattern.search(pl)
|
|
if m:
|
|
qty_str = m.group(1).replace(',', '').strip()
|
|
found_basis_qty = float(qty_str) if qty_str else 1.0
|
|
found_basis_unit = m.group(2).strip()
|
|
found_basis_src = f"pre_context: '{pl}'"
|
|
break
|
|
m2 = basis_pattern2.search(pl)
|
|
if m2:
|
|
u = m2.group(1).strip()
|
|
found_basis_qty = 1.0
|
|
found_basis_unit = u
|
|
found_basis_src = f"unit_parenthesis: '{pl}'"
|
|
break
|
|
|
|
mt = master_tables.get(tid)
|
|
if not mt:
|
|
continue
|
|
m_qty = mt.get('basis_quantity')
|
|
m_unit = mt.get('basis_unit')
|
|
pform = mt.get('pum_form')
|
|
|
|
# Also check if master is None while table headers contain unit
|
|
header_str = t['lines'][0] if t['lines'] else ""
|
|
|
|
# Detect discrepancies
|
|
if found_basis_unit:
|
|
if m_qty is None or m_unit is None:
|
|
target_issues.append((tid, ch, t['start_line'], t['section'], 'MISSING_IN_MASTER', found_basis_qty, found_basis_unit, m_qty, m_unit, pform, found_basis_src))
|
|
elif float(m_qty) != float(found_basis_qty) or m_unit != found_basis_unit:
|
|
# Check unit aliases
|
|
u_norm_md = found_basis_unit.replace('㎡','m2').replace('㎥','m3')
|
|
u_norm_m = str(m_unit).replace('㎡','m2').replace('㎥','m3')
|
|
if float(m_qty) != float(found_basis_qty) or u_norm_md != u_norm_m:
|
|
target_issues.append((tid, ch, t['start_line'], t['section'], 'VALUE_MISMATCH', found_basis_qty, found_basis_unit, m_qty, m_unit, pform, found_basis_src))
|
|
|
|
print(f"Target chapter issues: {len(target_issues)}")
|
|
for tid, ch, line, sec, itype, md_q, md_u, m_q, m_u, pf, src in target_issues:
|
|
print(f"[{tid} | line {line}] {ch} | {sec} | {itype}")
|
|
print(f" MD: {md_q} {md_u} ({src}) vs Master: {m_q} {m_u} (form={pf})")
|