60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import os, sys
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
merged_path = "resources/knowledge/original/원가계산/건설공사_표준품셈/2026년_건설공사_표준품셈.md"
|
|
with open(merged_path, 'r', encoding='utf-8') as f:
|
|
text_merged = f.read()
|
|
|
|
initial_len = len(text_merged)
|
|
applied_count = 0
|
|
|
|
# Import replacements from previous fix scripts
|
|
fix_scripts = [
|
|
"scratch/fix_common_squashed_tables.py",
|
|
"scratch/fix_civil_squashed_tables.py",
|
|
"scratch/clean_civil_ch5_ch6.py",
|
|
"scratch/fix_arch_squashed_tables.py",
|
|
"scratch/fix_mech_squashed_tables.py",
|
|
"scratch/fix_ch13_pipes.py",
|
|
"scratch/fix_ch13_pipes_part2.py",
|
|
"scratch/fix_maint_squashed_tables.py",
|
|
]
|
|
|
|
# Run regex/string replacements on text_merged
|
|
# Extract target and repl pairs from scripts
|
|
for script_path in fix_scripts:
|
|
with open(script_path, 'r', encoding='utf-8') as f:
|
|
code = f.read()
|
|
|
|
# Execute code in a local dict to get targets and repls
|
|
loc = {}
|
|
exec(code, {}, loc)
|
|
|
|
# Find all target_* and repl_* variables
|
|
pairs = []
|
|
for k in loc:
|
|
if k.startswith('target_'):
|
|
suffix = k[7:]
|
|
repl_k = 'repl_' + suffix
|
|
if repl_k in loc:
|
|
pairs.append((loc[k], loc[repl_k]))
|
|
elif k.startswith('old_l'):
|
|
suffix = k[5:]
|
|
repl_k = 'new_l' + suffix
|
|
if repl_k in loc:
|
|
pairs.append((loc[k], loc[repl_k]))
|
|
|
|
for tgt, rpl in pairs:
|
|
if tgt in text_merged:
|
|
text_merged = text_merged.replace(tgt, rpl)
|
|
applied_count += 1
|
|
print(f"Applied replacement: {tgt[:40]}...")
|
|
|
|
print(f"\nTotal replacements applied to merged file: {applied_count}")
|
|
|
|
with open(merged_path, 'w', encoding='utf-8') as f:
|
|
f.write(text_merged)
|
|
|
|
print(f"Merged file updated: len {initial_len} -> {len(text_merged)}")
|