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

78 lines
2.9 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
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
print("=== 원문 전체에서 '분모가 둘'이거나 복합 단위인 표 전수 조사 ===")
complex_units = []
# Pattern to find parenthesis units in pre_context or headers
unit_regex = re.compile(r'[\(\[\{]\s*단위\s*[:\=]?\s*([^\)\]\}]+)[\)\]\}]')
for t in tables:
tid = t['table_id']
pre_lines = t['pre_context']
header_line = t['lines'][0] if t['lines'] else ""
found_u = None
src_line = None
for pl in reversed(pre_lines):
m = unit_regex.search(pl)
if m:
found_u = m.group(1).strip()
src_line = pl
break
if not found_u:
m_h = unit_regex.search(header_line)
if m_h:
found_u = m_h.group(1).strip()
src_line = header_line
if found_u:
# Check if it has multiple slashes or complex compound units
# e.g. "인/1일 1km당", "㎥/1인/1일", "인/ha", "인/개당", "㎥/㎡당", "100본/ha당", "/일,대"
is_double_denom = False
# double denominator pattern: has two '/' or '/일' and 'km당' etc.
slash_count = found_u.count('/')
has_per_day_and_unit = ('일' in found_u and any(k in found_u for k in ['km', 'm', 'ha', '개', '본', '㎡', '㎥']))
has_compound_slash = slash_count >= 2 or ('/' in found_u and '당' in found_u and any(k in found_u for k in ['1일', '일,', '일당', '인당']))
if slash_count >= 2 or has_per_day_and_unit or '㎥/㎡' in found_u or '인/10개' in found_u or '인/100m' in found_u:
is_double_denom = True
complex_units.append({
'table_id': tid,
'chapter': t['chapter'],
'section': t['section'],
'line': t['start_line'],
'raw_unit': found_u,
'src_line': src_line,
'slash_count': slash_count,
'is_double_denom': is_double_denom
})
print(f"Total tables with parenthesis units found: {len(complex_units)}")
double_denoms = [u for u in complex_units if u['is_double_denom']]
print(f"Total tables with '분모가 둘인 꼴 (복합 분모)' : {len(double_denoms)}\n")
print("--- [분모가 둘인 꼴 전수 명세] ---")
for idx, d in enumerate(double_denoms):
print(f"{idx+1:2d}. [{d['table_id']} | line {d['line']}] {d['section']}")
print(f" 원문 단위 표기: '{d['raw_unit']}' (출처: {d['src_line']})")
print("\n--- [슬래시 1개인 단순 몫 단위(인/ha, 인/개 등) 표들] ---")
single_slash = [u for u in complex_units if not u['is_double_denom'] and u['slash_count'] == 1]
print(f"Total single slash units: {len(single_slash)}개 (sample 15):")
for s in single_slash[:15]:
print(f" [{s['table_id']}] {s['section']} -> '{s['raw_unit']}'")