import sys, os, re, json sys.stdout.reconfigure(encoding='utf-8') base_dir = "resources/knowledge/original/원가계산/건설공사_표준품셈" merged_file = os.path.join(base_dir, "2026년_건설공사_표준품셈.md") with open(merged_file, 'r', encoding='utf-8') as f: merged_text = f.read() all_md_files = [] for root, dirs, files in os.walk(base_dir): for f in files: if f.endswith('.md') and not f.startswith('_') and '개정사항' not in f and '2026년_건설공사_표준품셈.md' not in f: all_md_files.append(os.path.join(root, f)) # 1. Check divider column mismatch in all MD files (including merged) files_to_check = all_md_files + [merged_file] divider_mismatches = [] for fpath in files_to_check: rel = os.path.relpath(fpath, base_dir) with open(fpath, 'r', encoding='utf-8') as f: lines = f.readlines() for i in range(len(lines) - 1): l1 = lines[i].strip() l2 = lines[i+1].strip() # Check if l2 is divider if l1.startswith('|') and l1.endswith('|') and l2.startswith('|') and l2.endswith('|'): # check if l2 consists of --- and | if re.match(r'^\|(?:\s*:?-+:?\s*\|)+$', l2): c1 = len(l1.split('|')) - 2 c2 = len(l2.split('|')) - 2 if c1 != c2: divider_mismatches.append({ "file": rel, "line": i + 2, "header_cols": c1, "divider_cols": c2, "header": l1[:60], "divider": l2[:40] }) print(f"=== Divider Column Mismatches across all files: {len(divider_mismatches)} ===") for dm in divider_mismatches[:20]: print(f" - {dm['file']} (L{dm['line']}): header={dm['header_cols']} vs divider={dm['divider_cols']} | {dm['header']}") # 2. Check 3-line spec displacement # Tables where header has 형식 and 출력(kW) or similar spec_displacements = [] for fpath in files_to_check: rel = os.path.relpath(fpath, base_dir) with open(fpath, 'r', encoding='utf-8') as f: lines = f.readlines() for i, l in enumerate(lines): if '출력' in l and '㎾' in l and '|' in l: # check subsequent rows # if next rows have misplaced cell values or shifted empty cells pass with open('scratch/divider_mismatches.json', 'w', encoding='utf-8') as f: json.dump(divider_mismatches, f, ensure_ascii=False, indent=2)