Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_interactions(lines, comments='#', directed=False, delimiter=None, nodetype=None, timestamptype=None,
keys=None):
if not directed:
G = DynGraph()
else:
G = DynDiGraph()
for line in lines:
p = line.find(comments)
if p >= 0:
line = line[:p]
if not len(line):
continue
s = line.strip().split(delimiter)
if len(s) != 4:
continue
else:
def parse_snapshots(lines, comments='#', directed=False, delimiter=None, nodetype=None, timestamptype=None, keys=None):
if not directed:
G = DynGraph()
else:
G = DynDiGraph()
for line in lines:
p = line.find(comments)
if p >= 0:
line = line[:p]
if not len(line):
continue
# split line, should have 2 or more
s = line.strip().split(delimiter)
if len(s) < 3:
continue
if len(s) == 3:
u = s.pop(0)
v = s.pop(0)
Examples
--------
>>> from dynetx.readwrite import json_graph
>>> import dynetx as dn
>>> G = dn.DynGraph([(1,2)])
>>> data = json_graph.node_link_data(G)
>>> H = json_graph.node_link_graph(data)
See Also
--------
node_link_data
"""
directed = data.get('directed', directed)
graph = dn.DynGraph()
if directed:
graph = graph.to_directed()
id_ = attrs['id']
mapping = []
graph.graph = data.get('graph', {})
c = count()
for d in data['nodes']:
node = d.get(id_, next(c))
mapping.append(node)
nodedata = dict((make_str(k), v) for k, v in d.items() if k != id_)
graph.add_node(node, **nodedata)
for d in data['links']:
graph.add_interaction(d['source'], d["target"], d['time'])
return graph