fix(build_graph): resolve cache state-loss and vis.js text overlap (#12)
This commit is contained in:
@@ -152,9 +152,23 @@ def build_inferred_edges(pages: list[Path], existing_edges: list[dict], cache: d
|
|||||||
for p in pages:
|
for p in pages:
|
||||||
content = read_file(p)
|
content = read_file(p)
|
||||||
h = sha256(content)
|
h = sha256(content)
|
||||||
if cache.get(str(p)) != h:
|
entry = cache.get(str(p))
|
||||||
|
|
||||||
|
if not isinstance(entry, dict) or entry.get("hash") != h:
|
||||||
changed_pages.append(p)
|
changed_pages.append(p)
|
||||||
cache[str(p)] = h
|
else:
|
||||||
|
# Page unchanged: load its inferred edges from cache perfectly
|
||||||
|
src = page_id(p)
|
||||||
|
for rel in entry.get("edges", []):
|
||||||
|
new_edges.append({
|
||||||
|
"from": src,
|
||||||
|
"to": rel["to"],
|
||||||
|
"type": rel.get("type", "INFERRED"),
|
||||||
|
"title": rel.get("relationship", ""),
|
||||||
|
"label": "",
|
||||||
|
"color": EDGE_COLORS.get(rel.get("type", "INFERRED"), EDGE_COLORS["INFERRED"]),
|
||||||
|
"confidence": float(rel.get("confidence", 0.7)),
|
||||||
|
})
|
||||||
|
|
||||||
if not changed_pages:
|
if not changed_pages:
|
||||||
print(" no changed pages — skipping semantic inference")
|
print(" no changed pages — skipping semantic inference")
|
||||||
@@ -209,17 +223,26 @@ Rules:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
inferred = json.loads(raw)
|
inferred = json.loads(raw)
|
||||||
|
valid_rels = []
|
||||||
for rel in inferred:
|
for rel in inferred:
|
||||||
if isinstance(rel, dict) and "to" in rel:
|
if isinstance(rel, dict) and "to" in rel:
|
||||||
new_edges.append({
|
new_edges.append({
|
||||||
"from": src,
|
"from": src,
|
||||||
"to": rel["to"],
|
"to": rel["to"],
|
||||||
"type": rel.get("type", "INFERRED"),
|
"type": rel.get("type", "INFERRED"),
|
||||||
"label": rel.get("relationship", ""),
|
"title": rel.get("relationship", ""),
|
||||||
|
"label": "",
|
||||||
"color": EDGE_COLORS.get(rel.get("type", "INFERRED"), EDGE_COLORS["INFERRED"]),
|
"color": EDGE_COLORS.get(rel.get("type", "INFERRED"), EDGE_COLORS["INFERRED"]),
|
||||||
"confidence": rel.get("confidence", 0.7),
|
"confidence": float(rel.get("confidence", 0.7)),
|
||||||
})
|
})
|
||||||
except (json.JSONDecodeError, TypeError):
|
valid_rels.append(rel)
|
||||||
|
|
||||||
|
# Save properly to cache
|
||||||
|
cache[str(p)] = {
|
||||||
|
"hash": sha256(content),
|
||||||
|
"edges": valid_rels
|
||||||
|
}
|
||||||
|
except (json.JSONDecodeError, TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return new_edges
|
return new_edges
|
||||||
|
|||||||
Reference in New Issue
Block a user