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

Function load_node_link_graph

graphify/paths.py:771–797  ·  view source on GitHub ↗

Load a graphify graph.json into a networkx graph, accepting both writers. The clustered writer stores edges under ``links`` (networkx's node-link default); the raw ``--no-cluster`` writer stores them under ``edges``. Consumers that call ``node_link_graph(data, edges="links")`` directly

(path_or_data)

Source from the content-addressed store, hash-verified

769
770
771def load_node_link_graph(path_or_data):
772 """Load a graphify graph.json into a networkx graph, accepting both writers.
773
774 The clustered writer stores edges under ``links`` (networkx's node-link
775 default); the raw ``--no-cluster`` writer stores them under ``edges``.
776 Consumers that call ``node_link_graph(data, edges="links")`` directly
777 raise ``KeyError: 'links'`` on a raw graph (#2212) — the ``except
778 TypeError`` fallback only covers old networkx without the ``edges``
779 kwarg, not the missing key. Normalize before parsing, same idiom as
780 affected.py/serve.py.
781
782 Accepts a path (size-cap-checked via the security module, then parsed)
783 or an already-parsed dict (no size check — the caller owns any cap).
784 """
785 from networkx.readwrite import json_graph
786 data = path_or_data
787 owned = not isinstance(data, dict)
788 if owned:
789 p = Path(data)
790 from graphify.security import check_graph_file_size_cap # lazy: security imports paths
791 check_graph_file_size_cap(p)
792 data = read_graph_json(p)
793 if isinstance(data, dict) and "links" not in data and "edges" in data:
794 data = dict(data, links=data["edges"])
795 if isinstance(data, dict):
796 data = consumed_graph_rows(data) if owned and isinstance(data.get("links"), list) else restore_arc_direction(data)
797 return json_graph.node_link_graph(data, edges="links")
798
799
800# Path.resolve() memo shared by detect(), the cache layer and extract() (#perf).

Calls 5

read_graph_jsonFunction · 0.85
consumed_graph_rowsFunction · 0.85
restore_arc_directionFunction · 0.85
getMethod · 0.45