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

73 lines
3.6 KiB
Python

import os, sys, re
sys.stdout.reconfigure(encoding='utf-8')
target_files = [
# 02_토목부문
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제1장_도로포장공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제2장_하천공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제3장_터널공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제4장_궤도공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제5장_강구조공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제6장_관부설및접합공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제7장_항만공사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제8장_지반조사.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/제9장_측량.md',
# 05_유지관리부문
'resources/knowledge/original/원가계산/건설공사_표준품셈/05_유지관리부문/제1장_공통.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/05_유지관리부문/제2장_토목.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/05_유지관리부문/제3장_건축.md',
'resources/knowledge/original/원가계산/건설공사_표준품셈/05_유지관리부문/제4장_기계설비.md',
# 04_기계설비부문 제13장
'resources/knowledge/original/원가계산/건설공사_표준품셈/04_기계설비부문/제13장_플랜트설비공사.md',
]
# Suspect sentence continuation words in Col 0
CONTINUATION_PATTERNS = [
r'^구\s*간$', r'^설\s*치$', r'^후\s*설치$', r'^조립\s*설치$', r'^취급함', r'^정돈함',
r'^[가-힣\w\s]+(하고|하며|하여|혹은|및|등|까지|위해|위하여|취부함|포함|제외|운반|조양함)\b',
r'^→', r'^[A-Za-z0-9#]+\s*$', r'^분기기$', r'^교\s*환$', r'^매\s*립\s*식$', r'^\( 직 결 형 \)$'
]
print("=== Scanning All Target Files for Broken Groupings / Split Col 0 Sentences ===")
results = []
for fpath in target_files:
fname = os.path.basename(fpath)
with open(fpath, 'r', encoding='utf-8') as f:
lines = f.readlines()
for idx, line in enumerate(lines):
if not line.startswith('|'):
continue
cells = [c.strip() for c in line.split('|')[1:-1]]
if not cells or all(re.match(r'^:?-+:?$', c) for c in cells if c):
continue
c0 = cells[0]
# check if c0 matches any continuation patterns
for pat in CONTINUATION_PATTERNS:
if re.search(pat, c0):
# Also check surrounding lines to confirm it's part of a split
prev_line = lines[idx-1].strip() if idx > 0 else ""
next_line = lines[idx+1].strip() if idx + 1 < len(lines) else ""
results.append({
'file': fname,
'line': idx + 1,
'c0': c0,
'full_line': line.strip()[:100],
'matched_pat': pat
})
break
print(f"Total Suspect Split Col 0 Cells Found: {len(results)}")
by_file = {}
for r in results:
by_file.setdefault(r['file'], []).append(r)
for f, items in sorted(by_file.items()):
print(f"\n[{f}] ({len(items)}건)")
for it in items:
print(f" L{it['line']:<5} | Col0: '{it['c0']}' | {it['full_line']}")