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', ] print("=== Scanning for Condition/Grouped Tables without Item Classification Numbers ===") grouped_tables = [] for fpath in target_files: fname = os.path.basename(fpath) with open(fpath, 'r', encoding='utf-8') as f: lines = f.readlines() tables = [] cur_t = [] cur_start = 0 cur_title = "" for idx, l in enumerate(lines): line_str = l.strip() if not line_str.startswith('|'): if line_str and not line_str.startswith('>'): cur_title = line_str if cur_t: tables.append((cur_start, cur_title, cur_t)) cur_t = [] else: if not cur_t: cur_start = idx + 1 cur_t.append((idx + 1, line_str)) if cur_t: tables.append((cur_start, cur_title, cur_t)) for t_start, t_title, t_rows in tables: data_rows = [] for lno, r_str in t_rows: cells = [c.strip() for c in r_str.split('|')[1:-1]] if all(re.match(r'^:?-+:?$', c) for c in cells if c): continue if cells and cells[0] in ["비고", "비 고", "주", "[주]"]: continue data_rows.append((lno, r_str, cells)) if len(data_rows) < 3: continue # Check if rows have item numbers like 1-1, 1-2, 1-1-1 or 4-3-1 etc. has_item_numbers = False for lno, r_str, cells in data_rows[1:]: c0 = cells[0] if cells else "" if re.match(r'^\d+-\d+(?:-\d+)?', c0) or re.match(r'^[A-Z]\d{4}', c0): has_item_numbers = True break if has_item_numbers: continue # Safe, has explicit classification numbers # Check if this table has condition/branch groups # (e.g. multi-level condition headers or blank cells inheriting above groups) has_grouping = False group_col_values = [] for lno, r_str, cells in data_rows[1:]: c0 = cells[0] if cells else "" c1 = cells[1] if len(cells) > 1 else "" # Inherited blank cell or condition keyword if c0 == "" or c0 == "〃" or any(k in c0 for k in ["기층", "보조기층", "포장", "Type", "식", "식재", "토사", "암반", "외업", "내업", "직선", "곡선"]): has_grouping = True if c0: group_col_values.append(c0) if has_grouping and len(set(group_col_values)) >= 2: grouped_tables.append({ 'file': fname, 'line': t_start, 'title': t_title[:60], 'rows_count': len(data_rows), 'groups': list(set(group_col_values))[:6], 'sample_header': data_rows[0][1][:70] }) print(f"Total Condition/Grouped Tables found in our scope: {len(grouped_tables)}") for gt in grouped_tables: print(f"\n[{gt['file']}:L{gt['line']}] {gt['title']}") print(f" Header: {gt['sample_header']}") print(f" Groups: {gt['groups']} (Rows: {gt['rows_count']})")