docs(operators-manual): write, test, edit, and publish Operator's Manual for the Encyclopedia Knowledge Graph (v1.7.0)
This commit is contained in:
1 parent
5baf223f20
commit
7c0879ba7d
14 files changed
+1228
-234
No files matched your search
@@ -131,6 +131,7 @@ def build_graph() -> dict[str, Any]:
|
||||
nodes: list[dict[str, Any]] = []
|
||||
edges: list[dict[str, Any]] = []
|
||||
node_by_id: dict[str, dict[str, Any]] = {}
|
||||
seen_edges: set[tuple[str, str, str]] = set()
|
||||
|
||||
def add_node(nid: str, label: str, ntype: str, color: str, size: float, props: dict[str, Any]) -> None:
|
||||
if nid in node_by_id:
|
||||
@@ -147,8 +148,12 @@ def build_graph() -> dict[str, Any]:
|
||||
node_by_id[nid] = obj
|
||||
|
||||
def add_edge(src: str, tgt: str, rel: str, label: str = "", weight: float = 1.0, color: str = "#6B7280", directed: bool = True) -> None:
|
||||
if src not in node_by_id or tgt not in node_by_id or src == tgt and rel != "G4_ISOMETRIC_INVARIANT":
|
||||
if src not in node_by_id or tgt not in node_by_id or (src == tgt and rel != "G4_ISOMETRIC_INVARIANT"):
|
||||
return
|
||||
key = (src, tgt, rel) if directed else (min(src, tgt), max(src, tgt), rel)
|
||||
if key in seen_edges:
|
||||
return
|
||||
seen_edges.add(key)
|
||||
eid = f"e_{len(edges):04d}_{rel}_{src}_{tgt}"
|
||||
edges.append(
|
||||
{
|
||||
@@ -1000,15 +1005,130 @@ def render_atlas_pngs(graph_data: dict[str, Any], out_dir: Path) -> list[str]:
|
||||
return written
|
||||
|
||||
|
||||
def main() -> int:
|
||||
KG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
graph_data = build_graph()
|
||||
def verify_published_artifacts(kg_dir: Path, pre_gl_sha: str, pre_enc_sha: str) -> dict[str, Any]:
|
||||
import xml.etree.ElementTree as ET
|
||||
from PIL import Image
|
||||
|
||||
json_path = KG_DIR / "encyclopedia-graph.json"
|
||||
js_path = KG_DIR / "graph-data.js"
|
||||
graphml_path = KG_DIR / "encyclopedia-graph.graphml"
|
||||
gexf_path = KG_DIR / "encyclopedia-graph.gexf"
|
||||
canvas_path = KG_DIR / "encyclopedia.canvas"
|
||||
post_gl_sha = hashlib.sha256(GLOSSARY_REG_PATH.read_bytes()).hexdigest()
|
||||
post_enc_sha = hashlib.sha256(ENC_MANIFEST_PATH.read_bytes()).hexdigest()
|
||||
|
||||
json_p = kg_dir / "encyclopedia-graph.json"
|
||||
js_p = kg_dir / "graph-data.js"
|
||||
gml_p = kg_dir / "encyclopedia-graph.graphml"
|
||||
gexf_p = kg_dir / "encyclopedia-graph.gexf"
|
||||
canv_p = kg_dir / "encyclopedia.canvas"
|
||||
html_p = KG_DIR / "index.html"
|
||||
|
||||
j_obj = json.loads(json_p.read_text(encoding="utf-8"))
|
||||
c_obj = json.loads(canv_p.read_text(encoding="utf-8"))
|
||||
gml_root = ET.parse(gml_p).getroot()
|
||||
gexf_root = ET.parse(gexf_p).getroot()
|
||||
|
||||
png_checks = {}
|
||||
for m_name in ("atlas-mode1-trophic-food-web.png", "atlas-mode2-concentric-eti-radar.png", "atlas-mode3-bipartite-g1-funnel.png"):
|
||||
p = kg_dir / m_name
|
||||
with Image.open(p) as im:
|
||||
png_checks[m_name] = {"size": list(im.size), "mode": im.mode, "bytes": p.stat().st_size}
|
||||
|
||||
return {
|
||||
"all_gates_passed": (
|
||||
pre_gl_sha == post_gl_sha
|
||||
and pre_enc_sha == post_enc_sha
|
||||
and len(j_obj["nodes"]) >= 388
|
||||
and len(j_obj["edges"]) >= 1282
|
||||
and gml_root.tag.endswith("graphml")
|
||||
and gexf_root.tag.endswith("gexf")
|
||||
and len(c_obj["nodes"]) > 0
|
||||
and js_p.stat().st_size > 100000
|
||||
and html_p.exists()
|
||||
),
|
||||
"gate1_glossary_sha256_unchanged": pre_gl_sha == post_gl_sha,
|
||||
"gate2_encyclopedia_sha256_unchanged": pre_enc_sha == post_enc_sha,
|
||||
"gate3_json_schema_counts": {"nodes": len(j_obj["nodes"]), "edges": len(j_obj["edges"])},
|
||||
"gate4_xml_well_formed": {"graphml_root": gml_root.tag, "gexf_root": gexf_root.tag},
|
||||
"gate5_obsidian_canvas_counts": {"canvas_nodes": len(c_obj["nodes"]), "canvas_edges": len(c_obj["edges"])},
|
||||
"gate6_atlas_pngs": png_checks,
|
||||
}
|
||||
|
||||
|
||||
def query_node_ego(graph_data: dict[str, Any], query: str) -> dict[str, Any]:
|
||||
q = query.strip().lower()
|
||||
matches = []
|
||||
for n in graph_data["nodes"]:
|
||||
if (
|
||||
n["id"].lower() == q
|
||||
or q in n["label"].lower()
|
||||
or q == str(n.get("ing_aq", ""))
|
||||
or q == str(n.get("aq_value", ""))
|
||||
or q == (n.get("eng", "") or "").lower()
|
||||
or q == (n.get("ing", "") or "").lower()
|
||||
):
|
||||
matches.append(n)
|
||||
if not matches:
|
||||
return {"query": query, "match_count": 0, "matched_node_ids": [], "matches": []}
|
||||
primary = matches[0]
|
||||
nid = primary["id"]
|
||||
incident = [
|
||||
{"relation": e["relation"], "source": e["source"], "target": e["target"], "label": e["label"], "weight": e["weight"]}
|
||||
for e in graph_data["edges"]
|
||||
if e["source"] == nid or e["target"] == nid
|
||||
]
|
||||
return {
|
||||
"query": query,
|
||||
"match_count": len(matches),
|
||||
"matched_node_ids": [m["id"] for m in matches],
|
||||
"primary_node": {k: v for k, v in primary.items() if k != "layouts"},
|
||||
"layouts": primary.get("layouts"),
|
||||
"incident_edge_count": len(incident),
|
||||
"sample_incident_edges": incident[:15],
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
import argparse
|
||||
|
||||
ap = argparse.ArgumentParser(description="Build, verify, and query the Encyclopedia of Technocapital Singularity Zoology Knowledge Graph.")
|
||||
ap.add_argument("--out-dir", default=str(KG_DIR), help="Target output directory for generated graph artifacts (default: knowledge-graph/).")
|
||||
ap.add_argument("--verify-only", action="store_true", help="Run 6-gate verification on existing knowledge-graph artifacts without rebuilding.")
|
||||
ap.add_argument("--check-isolation", action="store_true", help="Print upstream glossary and encyclopedia SHA-256 digests and verify zero modifications.")
|
||||
ap.add_argument("--query-node", default=None, help="Query a node by ID, headword, Ingglish token, or integer AQ coordinate and inspect its ego-network.")
|
||||
args = ap.parse_args()
|
||||
|
||||
pre_gl_sha = hashlib.sha256(GLOSSARY_REG_PATH.read_bytes()).hexdigest()
|
||||
pre_enc_sha = hashlib.sha256(ENC_MANIFEST_PATH.read_bytes()).hexdigest()
|
||||
|
||||
if args.check_isolation:
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"glossary_registry_path": str(GLOSSARY_REG_PATH),
|
||||
"glossary_registry_sha256": pre_gl_sha,
|
||||
"encyclopedia_manifest_path": str(ENC_MANIFEST_PATH),
|
||||
"encyclopedia_manifest_sha256": pre_enc_sha,
|
||||
},
|
||||
indent=2,
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
out_dir = Path(args.out_dir)
|
||||
if args.verify_only:
|
||||
ver = verify_published_artifacts(out_dir, pre_gl_sha, pre_enc_sha)
|
||||
print(json.dumps(ver, indent=2))
|
||||
return 0 if ver["all_gates_passed"] else 1
|
||||
|
||||
graph_data = build_graph()
|
||||
if args.query_node:
|
||||
res = query_node_ego(graph_data, args.query_node)
|
||||
print(json.dumps(res, indent=2, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
json_path = out_dir / "encyclopedia-graph.json"
|
||||
js_path = out_dir / "graph-data.js"
|
||||
graphml_path = out_dir / "encyclopedia-graph.graphml"
|
||||
gexf_path = out_dir / "encyclopedia-graph.gexf"
|
||||
canvas_path = out_dir / "encyclopedia.canvas"
|
||||
|
||||
json_str = json.dumps(graph_data, indent=2, ensure_ascii=False)
|
||||
json_path.write_text(json_str + "\n", encoding="utf-8")
|
||||
@@ -1017,13 +1137,15 @@ def main() -> int:
|
||||
export_graphml(graph_data, graphml_path)
|
||||
export_gexf(graph_data, gexf_path)
|
||||
export_obsidian_canvas(graph_data, canvas_path)
|
||||
png_paths = render_atlas_pngs(graph_data, KG_DIR)
|
||||
png_paths = render_atlas_pngs(graph_data, out_dir)
|
||||
ver = verify_published_artifacts(out_dir, pre_gl_sha, pre_enc_sha)
|
||||
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"counts": graph_data["counts"],
|
||||
"isolation_verified": graph_data["isolation_verified"],
|
||||
"six_gate_verification": ver,
|
||||
"top_5_hubs": graph_data["top_coordinate_hubs_by_degree"][:5],
|
||||
"exported_files": [
|
||||
str(json_path),
|
||||
|
||||
Reference in new issue
Block a user