MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / node_link_graph

Function node_link_graph

easygraph/readwrite/json_graph/node_link.py:30–111  ·  view source on GitHub ↗

Returns graph from node-link data format. Parameters ---------- data : dict node-link formatted graph data directed : bool If True, and direction not specified in data, return a directed graph. multigraph : bool If True, and multigraph not specified in

(data, directed=False, multigraph=True, attrs=None)

Source from the content-addressed store, hash-verified

28
29
30def node_link_graph(data, directed=False, multigraph=True, attrs=None):
31 """Returns graph from node-link data format.
32
33 Parameters
34 ----------
35 data : dict
36 node-link formatted graph data
37
38 directed : bool
39 If True, and direction not specified in data, return a directed graph.
40
41 multigraph : bool
42 If True, and multigraph not specified in data, return a multigraph.
43
44 attrs : dict
45 A dictionary that contains five keys 'source', 'target', 'name',
46 'key' and 'link'. The corresponding values provide the attribute
47 names for storing NetworkX-internal graph data. Default value:
48
49 dict(source='source', target='target', name='id',
50 key='key', link='links')
51
52 Returns
53 -------
54 G : EasyGraph graph
55 A EasyGraph graph object
56
57 Examples
58 --------
59 >>> from easygraph.readwrite import json_graph
60 >>> G = eg.Graph([("A", "B")])
61 >>> data = json_graph.node_link_data(G)
62 >>> H = json_graph.node_link_graph(data)
63
64 Notes
65 -----
66 Attribute 'key' is only used for multigraphs.
67
68 See Also
69 --------
70 node_link_data, adjacency_data, tree_data
71 """
72 # Allow 'attrs' to keep default values.
73 if attrs is None:
74 attrs = _attrs
75 else:
76 attrs.update({k: v for k, v in _attrs.items() if k not in attrs})
77 multigraph = data.get("multigraph", multigraph)
78 directed = data.get("directed", directed)
79 if multigraph:
80 graph = eg.MultiGraph()
81 else:
82 graph = eg.Graph()
83 if directed:
84 graph = graph.to_directed()
85 name = attrs["name"]
86 source = attrs["source"]
87 target = attrs["target"]

Callers

nothing calls this directly

Calls 7

to_directedMethod · 0.95
add_nodeMethod · 0.95
add_edgeMethod · 0.95
countFunction · 0.85
_to_tupleFunction · 0.85
updateMethod · 0.80
GraphMethod · 0.80

Tested by

no test coverage detected