Files
llm_wiki/raw/教育AI研究/tools/add_bidirectional_links.py
hehaiguang1123 a6f05ab2d5 Phase 0-2: Schema cleanup, typed relations, event-driven automation
- Phase 0: AGENTS.md cleanup (dedup quotes, renumber sections, merge qmd)
- Phase 1: typed relations (manage-relations.py, graph-search.py, check-staleness.py, detect-conflicts.py)
- Phase 2: frontmatter validator, weekly lint, knowledge promotion, git hooks
- Fix .gitignore to track tools/ and .githooks/
- Fix git remote URL (remove plaintext token)
- New wiki pages: 504 pages, 34 raw sources
2026-07-01 08:05:43 +08:00

98 lines
3.3 KiB
Python

import os
import re
from pathlib import Path
WIKI_DIR = Path(r"D:\Applications\app\kepano-obsidian-main\wiki")
BIDIRECTIONAL_PAIRS = [
("LLM Wiki.md", "RAG vs 持久化知识库.md"),
("LLM Wiki.md", "知识库维护自动化.md"),
("LLM Wiki.md", "Memex.md"),
("LLM Wiki.md", "BYOAI.md"),
("LLM Wiki.md", "Farzapedia.md"),
("LLM Wiki.md", "Contamination Mitigation.md"),
("RAG vs 持久化知识库.md", "知识库维护自动化.md"),
("RAG vs 持久化知识库.md", "Memex.md"),
("高等教育AI专题.md", "教学大模型发展状况.md"),
("高等教育AI专题.md", "教学大模型有效性评估.md"),
("高等教育AI专题.md", "教育AI研究项目.md"),
("高等教育AI专题.md", "CMU LearnLab.md"),
("高等教育AI专题.md", "MIT RAISE.md"),
("高等教育AI专题.md", "牛津CCAI.md"),
("高等教育AI专题.md", "斯坦福 Accelerator.md"),
("高等教育AI专题.md", "Victor Lee.md"),
("教学大模型发展状况.md", "教学大模型有效性评估.md"),
("教学大模型有效性评估.md", "教育AI研究项目.md"),
("教育AI研究项目.md", "智能辅导系统.md"),
("教育AI研究项目.md", "自适应学习系统.md"),
("教育AI研究项目.md", "LLM教育应用.md"),
("CMU LearnLab.md", "MIT RAISE.md"),
("CMU LearnLab.md", "Victor Lee.md"),
("MIT RAISE.md", "牛津CCAI.md"),
("MIT RAISE.md", "斯坦福 Accelerator.md"),
("斯坦福 Accelerator.md", "Victor Lee.md"),
("牛津CCAI.md", "Victor Lee.md"),
("教学大模型有效性评估.md", "Khanmigo.md"),
("CMU LearnLab.md", "Khanmigo.md"),
("LLM教育应用系统综述.md", "教育AI研究项目.md"),
("LLM教育应用系统综述.md", "教学大模型发展状况.md"),
("LLM Wiki.md", "Andrej Karpathy.md"),
("Memex.md", "Vannevar Bush.md"),
("Contamination Mitigation.md", "Steph Ango.md"),
]
def add_bidirectional_link(file1, file2):
file_path = WIKI_DIR / file1
if not file_path.exists():
print(f"NOT FOUND: {file1}")
return False
try:
content = file_path.read_text(encoding="utf-8")
file2_name = file2.replace(".md", "")
link_pattern = f"[[{file2_name}]]"
if link_pattern in content:
print(f"ALREADY LINKED: {file1} -> {file2_name}")
return True
lines = content.split("\n")
insert_pos = len(lines)
for i in range(min(30, len(lines))):
if lines[i].strip().startswith("## "):
insert_pos = i + 1
break
ref_line = f"- {link_pattern}"
lines.insert(insert_pos, ref_line)
new_content = "\n".join(lines)
file_path.write_text(new_content, encoding="utf-8")
print(f"ADDED: {file1} -> {file2_name}")
return True
except Exception as e:
print(f"ERROR {file1}: {e}")
return False
def main():
print(f"BIDIRECTIONAL LINKS: {len(BIDIRECTIONAL_PAIRS)} pairs")
print(f"TARGET: {WIKI_DIR}")
print("-" * 50)
success_count = 0
for file1, file2 in BIDIRECTIONAL_PAIRS:
if add_bidirectional_link(file1, file2):
success_count += 1
add_bidirectional_link(file2, file1)
print("-" * 50)
print(f"DONE: {success_count} files")
if __name__ == "__main__":
main()