Initial Commit: Reinforced Knowledge Wiki v1.0 - Pure Origin

This commit is contained in:
2026-04-20 14:26:57 +09:00
parent 895d66e238
commit 46fd50381e
4457 changed files with 174028 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import os
import re
import json
base_dir = r"e:\Wiki\2nd"
wiki_dir = os.path.join(base_dir, "10_Wiki")
graph_path = os.path.join(base_dir, "20_Meta", "Graph.json")
def rebuild_graph():
nodes = []
links = []
# 1. Scan for all files and create nodes
all_files = []
for root, dirs, files in os.walk(wiki_dir):
for file in files:
if file.endswith(".md"):
rel_path = os.path.relpath(os.path.join(root, file), base_dir)
title = file.replace(".md", "")
all_files.append((title, rel_path))
nodes.append({"id": title, "path": rel_path})
# 2. Scan content for links [[...]]
titles = [n["id"] for n in nodes]
for title, rel_path in all_files:
full_path = os.path.join(base_dir, rel_path)
with open(full_path, "r", encoding="utf-8") as f:
content = f.read()
found_links = re.findall(r'\[\[(.*?)\]\]', content)
for link in found_links:
if link in titles and link != title:
links.append({"source": title, "target": link})
graph = {"nodes": nodes, "links": links}
with open(graph_path, "w", encoding="utf-8") as f:
json.dump(graph, f, indent=2, ensure_ascii=False)
print(f"Graph rebuilt: {len(nodes)} nodes, {len(links)} links.")
if __name__ == "__main__":
rebuild_graph()