MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / normalize_edge

Function normalize_edge

graphify/callflow_html.py:201–219  ·  view source on GitHub ↗

Normalize graphify edges while preserving original fields.

(raw: dict, index: int)

Source from the content-addressed store, hash-verified

199
200
201def normalize_edge(raw: dict, index: int) -> dict | None:
202 """Normalize graphify edges while preserving original fields."""
203 edge = dict(raw)
204 source = endpoint_id(first_present(edge, "source", "src", "from", "from_id", "start", "u"))
205 target = endpoint_id(first_present(edge, "target", "dst", "to", "to_id", "end", "v"))
206 if not source or not target:
207 return None
208
209 relation = first_present(edge, "relation", "type", "kind", "label", "predicate", default="relates")
210 confidence = first_present(edge, "confidence", "evidence", "provenance", default="EXTRACTED")
211 score = first_present(edge, "confidence_score", "score", "weight", "probability", default=1.0)
212
213 edge["id"] = str(first_present(edge, "id", "edge_id", default=f"edge_{index + 1}"))
214 edge["source"] = source
215 edge["target"] = target
216 edge["relation"] = str(relation or "relates").lower()
217 edge["confidence"] = str(confidence or "EXTRACTED").upper()
218 edge["confidence_score"] = to_float(score, 1.0)
219 return edge
220
221
222def _node_link_payload(data: dict) -> tuple[list, list] | None:

Callers 1

load_graphFunction · 0.85

Calls 3

endpoint_idFunction · 0.85
first_presentFunction · 0.85
to_floatFunction · 0.85

Tested by

no test coverage detected