121 lines
4.0 KiB
Python
121 lines
4.0 KiB
Python
import os
|
|
import re
|
|
import uuid
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# UTF-8 Output support
|
|
if sys.stdout.encoding != 'utf-8':
|
|
import io
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
|
|
base_dir = r"e:\Wiki\2nd"
|
|
raw_dir = os.path.join(base_dir, "00_Raw", "2026-04-20")
|
|
|
|
batch_files = [
|
|
"AI 迡 ˿ ñ_ - м (ESLint & Prettier)).md",
|
|
"Albion Online (Full Loot_Player-Driven Production).md",
|
|
"Algebraic-Data-Types-in-TypeScript.md",
|
|
"Algebraic-Data-Types.md",
|
|
"Algorithmic Bias in Art.md",
|
|
"Algorithmic Decision Making.md",
|
|
"Algorithmic Game Theory.md",
|
|
"Algorithmic Governance.md",
|
|
"Algorithmic Mechanism Design.md",
|
|
"Algorithmic Rhetoric.md"
|
|
]
|
|
|
|
mapping = {
|
|
"AI 迡 ˿ ñ_ - м (ESLint & Prettier)).md": "Programming & Tools",
|
|
"Albion Online (Full Loot_Player-Driven Production).md": "Game Design",
|
|
"Algebraic-Data-Types-in-TypeScript.md": "Programming & Language",
|
|
"Algebraic-Data-Types.md": "Computer Science & Math",
|
|
"Algorithmic Bias in Art.md": "AI & Ethics",
|
|
"Algorithmic Decision Making.md": "AI & Ethics",
|
|
"Algorithmic Game Theory.md": "Game Design & Math",
|
|
"Algorithmic Governance.md": "Sociology & Tech",
|
|
"Algorithmic Mechanism Design.md": "Economics & Algorithms",
|
|
"Algorithmic Rhetoric.md": "Communication & Tech"
|
|
}
|
|
|
|
def wikify(filename):
|
|
raw_path = os.path.join(raw_dir, filename)
|
|
if not os.path.exists(raw_path):
|
|
print(f"File not found: {raw_path}")
|
|
return
|
|
|
|
try:
|
|
with open(raw_path, "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
except UnicodeDecodeError:
|
|
with open(raw_path, "r", encoding="cp949") as f:
|
|
content = f.read()
|
|
|
|
title_match = re.search(r'^#\s*\[\[(.*?)\]\]', content, re.M)
|
|
if not title_match:
|
|
title_match = re.search(r'^\[\[(.*?)\]\]', content, re.M)
|
|
|
|
# Handle messed up filenames in titles
|
|
clean_title = filename.replace(".md", "")
|
|
if "AI" in clean_title:
|
|
clean_title = "AI Coding Standard (ESLint & Prettier)"
|
|
|
|
title = title_match.group(1) if title_match else clean_title
|
|
sub_folder = mapping.get(filename, "Uncategorized")
|
|
category_path = f"10_Wiki/💡 Topics/{sub_folder}"
|
|
|
|
summary_match = re.search(r'##?\s*📌\s*Brief Summary\n(.*?)(?=\n##|$)', content, re.S)
|
|
summary = summary_match.group(1).strip() if summary_match else "지식 요약 작업 중"
|
|
|
|
core_match = re.search(r'##?\s*📖\s*Core Content\n(.*?)(?=\n##|$)', content, re.S)
|
|
core = core_match.group(1).strip() if core_match else "본문 구조화 작업 중"
|
|
|
|
conn_match = re.search(r'##?\s*🔗\s*Knowledge Connections\n(.*?)(?=\n##|$)', content, re.S)
|
|
conn = conn_match.group(1).strip() if conn_match else ""
|
|
|
|
doc_id = f"P-REINFORCE-{uuid.uuid4().hex[:6].upper()}"
|
|
today = "2026-04-20"
|
|
|
|
wiki_content = f"""---
|
|
id: {doc_id}
|
|
category: "[[{category_path}]]"
|
|
confidence_score: 0.95
|
|
tags: []
|
|
last_reinforced: {today}
|
|
github_commit: "[P-Reinforce] Batch 11 - Wikified {title}"
|
|
---
|
|
|
|
# [[{title}]]
|
|
|
|
## 📌 한 줄 통찰 (The Karpathy Summary)
|
|
> {summary}
|
|
|
|
## 📖 구조화된 지식 (Synthesized Content)
|
|
{core}
|
|
|
|
## ⚠️ 모순 및 업데이트 (Contradictions & RL Update)
|
|
- **과거 데이터와의 충돌:** 신규 지식 카테고리화 및 연결성 강화.
|
|
- **정책 변화:** {sub_folder} 분야의 지식 자산 보호 및 네트워크 확장.
|
|
|
|
## 🔗 지식 연결 (Graph)
|
|
{conn}
|
|
- Raw Source: [[00_Raw/2026-04-20/{filename}]]
|
|
---
|
|
"""
|
|
|
|
target_dir = os.path.join(base_dir, category_path.replace("/", os.sep))
|
|
if not os.path.exists(target_dir):
|
|
os.makedirs(target_dir)
|
|
|
|
# Clean title for filename to avoid issues
|
|
safe_title = re.sub(r'[^\w\s\(\)\[\]-]', '', title).strip()
|
|
target_path = os.path.join(target_dir, f"{safe_title}.md")
|
|
|
|
with open(target_path, "w", encoding="utf-8") as f:
|
|
f.write(wiki_content)
|
|
print(f"Processed: {filename} -> {target_path}")
|
|
|
|
if __name__ == "__main__":
|
|
for f in batch_files:
|
|
wikify(f)
|