import glob, re, os, sys sys.stdout.reconfigure(encoding='utf-8') target_files = [] target_files.extend(glob.glob('resources/knowledge/original/원가계산/건설공사_표준품셈/02_토목부문/*.md')) target_files.extend(glob.glob('resources/knowledge/original/원가계산/건설공사_표준품셈/05_유지관리부문/*.md')) target_files.append('resources/knowledge/original/원가계산/건설공사_표준품셈/04_기계설비부문/제13장_플랜트설비공사.md') print(f"Total target files: {len(target_files)}") ditto_matches = [] remarks_tables = [] for filepath in target_files: fname = os.path.basename(filepath) with open(filepath, 'r', encoding='utf-8') as f: lines = f.readlines() in_table = False headers = [] current_sec = 'UNKNOWN' table_rows = [] header_line = 0 for idx, line in enumerate(lines): line_s = line.strip() sec_m = re.search(r'(\d+-\d+(?:-\d+)?(?:\s+[^\n(]+)?)', line_s) if sec_m and not line_s.startswith('|'): current_sec = sec_m.group(1).strip() if line_s.startswith('|') and not line_s.startswith('|---'): cols = [c.strip() for c in line_s.split('|')[1:-1]] if not in_table: # Check if this row is header if any('비고' in c or '비 고' in c or '구분' in c or '직종' in c or '규격' in c for c in cols): headers = cols in_table = True header_line = idx + 1 table_rows = [] continue if in_table: table_rows.append((idx + 1, cols)) for col_idx, col in enumerate(cols): if col in ['〃', '"', '″', '”'] or '〃' in col: ditto_matches.append({ 'file': fname, 'sec': current_sec, 'line': idx + 1, 'col_idx': col_idx, 'val': col, 'row': cols }) else: if in_table and (line_s == '' or not line_s.startswith('|')): # Check table for remarks has_remarks = any('비고' in h or '비 고' in h for h in headers) if has_remarks or any(m['line'] >= header_line and m['line'] <= idx for m in ditto_matches): remarks_tables.append({ 'file': fname, 'sec': current_sec, 'header_line': header_line, 'headers': headers, 'row_count': len(table_rows), 'rows': table_rows }) in_table = False headers = [] table_rows = [] print(f"Total ditto matches: {len(ditto_matches)}") print(f"Total tables with remarks/dittos: {len(remarks_tables)}") # Summary by section by_sec = {} for m in ditto_matches: k = f"{m['file']} :: {m['sec']}" by_sec.setdefault(k, []).append(m) for k, v in by_sec.items(): print(f" {k} -> {len(v)} dittos (lines {v[0]['line']}~{v[-1]['line']})")