63 lines
2.7 KiB
Python
63 lines
2.7 KiB
Python
import sys, os, re
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
split_ch8 = "resources/knowledge/original/원가계산/건설공사_표준품셈/01_공통부문/제8장_건설기계.md"
|
|
merged_file = "resources/knowledge/original/원가계산/건설공사_표준품셈/2026년_건설공사_표준품셈.md"
|
|
|
|
with open(split_ch8, 'r', encoding='utf-8') as f:
|
|
text_split = f.read()
|
|
|
|
with open(merged_file, 'r', encoding='utf-8') as f:
|
|
text_merged = f.read()
|
|
|
|
# 1. Extract 5220 from split and replace in merged
|
|
# In split:
|
|
p_split_5220 = re.compile(r'\(5220\)\s*소형브레이커\(전기식\).*?(?=\(5330\))', re.DOTALL)
|
|
m_sp_5220 = p_split_5220.search(text_split)
|
|
if m_sp_5220:
|
|
block_5220 = m_sp_5220.group(0).strip()
|
|
print("Found 5220 in split!")
|
|
# Find in merged
|
|
p_mg_5220 = re.compile(r'252공통부문\(5220\)[^\n]+\(5330\)', re.DOTALL)
|
|
m_mg_5220 = p_mg_5220.search(text_merged)
|
|
if m_mg_5220:
|
|
text_merged = text_merged[:m_mg_5220.start()] + block_5220 + "\n\n(5330)" + text_merged[m_mg_5220.end():]
|
|
print("Replaced 5220 in merged!")
|
|
else:
|
|
print("5220 pattern not matched in merged.")
|
|
|
|
# 2. Extract 7995 from split and replace in merged
|
|
p_split_7995 = re.compile(r'\(7995\)\s*배관파이프.*?(?=\n8-3-9|\n\(8201\))', re.DOTALL)
|
|
m_sp_7995 = p_split_7995.search(text_split)
|
|
if m_sp_7995:
|
|
block_7995 = m_sp_7995.group(0).strip()
|
|
print("Found 7995 in split!")
|
|
p_mg_7995 = re.compile(r'268공통부문\(7995\)[^\n]+(?=8-3-9|8201)', re.DOTALL)
|
|
m_mg_7995 = p_mg_7995.search(text_merged)
|
|
if m_mg_7995:
|
|
text_merged = text_merged[:m_mg_7995.start()] + block_7995 + "\n\n" + text_merged[m_mg_7995.end():]
|
|
print("Replaced 7995 in merged!")
|
|
else:
|
|
print("7995 pattern not matched in merged.")
|
|
|
|
# 3. Extract 8-4 operating tables from split and replace in merged
|
|
# In split, 8-4 starts around L3533 to the end of 8-4 tables (before 8-5 or chapter end)
|
|
p_split_84 = re.compile(r"8-4\s*운전경비\s*산정.*?8-4-1\s*\[00\]토공기계.*?(?=8-4-9|\(9040\)|\Z)", re.DOTALL)
|
|
m_sp_84 = p_split_84.search(text_split)
|
|
if m_sp_84:
|
|
block_84 = m_sp_84.group(0).strip()
|
|
print(f"Found 8-4 block in split, len={len(block_84)}!")
|
|
# Find in merged
|
|
p_mg_84 = re.compile(r"274공통부문8-4\s*운전경비\s*산정.*?8-4-1\s*\[00\]토공기계.*?(?=8-4-9|\(9040\)|286공통부문\(9040\))", re.DOTALL)
|
|
m_mg_84 = p_mg_84.search(text_merged)
|
|
if m_mg_84:
|
|
text_merged = text_merged[:m_mg_84.start()] + block_84 + "\n\n" + text_merged[m_mg_84.end():]
|
|
print("Replaced 8-4 operating tables in merged!")
|
|
else:
|
|
print("8-4 pattern not matched in merged.")
|
|
|
|
with open(merged_file, 'w', encoding='utf-8') as f:
|
|
f.write(text_merged)
|
|
|
|
print("Replacement script finished.")
|