Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
For each edge (n,e) in B add n to the edge e in the hypergraph.
"""
if not bipartite.is_bipartite(B):
raise HyperNetxError('Error: Method requires a bipartite graph.')
entities = []
for n,d in B.nodes(data=True):
if d['bipartite'] == set_names[1]:
elements = []
for nei in B.neighbors(n):
elements.append(Entity(nei,[],properties=B.nodes(data=True)[nei]))
if elements:
entities.append(Entity(n,elements,properties=d))
name = name or '_'
return Hypergraph(EntitySet(name,entities),name=name)
### If no ids are given, return default ids indexed by position in iterator
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}
_edges = {j: Entity(j,
elements = _elements[j].values(),
**setsystem[j].properties) for j in setsystem}
self._edges = EntitySet(f'{self.name}:Edges',
elements = _edges.values(), **setsystem.properties)
self._nodes = EntitySet(f'{self.name}:Nodes',
elements = _nodes.values())
self.name = name
##### Check setsystem type and change into an EntitySet before constructing hypergraph:
if not setsystem:
setsystem = EntitySet('_',elements=[])
elif isinstance(setsystem,dict):
### Must be a dictionary with values equal to iterables of Entities and hashables.
### Keys will be uids for new edges and values of the dictionary will generate the nodes.
setsystem = EntitySet('_',setsystem)
### If no ids are given, return default ids indexed by position in iterator
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}
_edges = {j: Entity(j,
elements = _elements[j].values(),
**setsystem[j].properties) for j in setsystem}
self._edges = EntitySet(f'{self.name}:Edges',
elements = _edges.values(), **setsystem.properties)
self._nodes = EntitySet(f'{self.name}:Nodes',
elements = _nodes.values())
def __init__(self,setsystem=None, name='_'):
self.name = name
##### Check setsystem type and change into an EntitySet before constructing hypergraph:
if not setsystem:
setsystem = EntitySet('_',elements=[])
elif isinstance(setsystem,dict):
### Must be a dictionary with values equal to iterables of Entities and hashables.
### Keys will be uids for new edges and values of the dictionary will generate the nodes.
setsystem = EntitySet('_',setsystem)
### If no ids are given, return default ids indexed by position in iterator
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}
_edges = {j: Entity(j,
elements = _elements[j].values(),
**setsystem[j].properties) for j in setsystem}
self._edges = EntitySet(f'{self.name}:Edges',
##### Check setsystem type and change into an EntitySet before constructing hypergraph:
if not setsystem:
setsystem = EntitySet('_',elements=[])
elif isinstance(setsystem,dict):
### Must be a dictionary with values equal to iterables of Entities and hashables.
### Keys will be uids for new edges and values of the dictionary will generate the nodes.
setsystem = EntitySet('_',setsystem)
### If no ids are given, return default ids indexed by position in iterator
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}
_edges = {j: Entity(j,
elements = _elements[j].values(),
**setsystem[j].properties) for j in setsystem}
self._edges = EntitySet(f'{self.name}:Edges',
elements = _edges.values(), **setsystem.properties)
self._nodes = EntitySet(f'{self.name}:Nodes',
elements = _nodes.values())
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}
_edges = {j: Entity(j,
elements = _elements[j].values(),
**setsystem[j].properties) for j in setsystem}
self._edges = EntitySet(f'{self.name}:Edges',
elements = _edges.values(), **setsystem.properties)
self._nodes = EntitySet(f'{self.name}:Nodes',
elements = _nodes.values())
def __init__(self,setsystem=None, name='_'):
self.name = name
##### Check setsystem type and change into an EntitySet before constructing hypergraph:
if not setsystem:
setsystem = EntitySet('_',elements=[])
elif isinstance(setsystem,dict):
### Must be a dictionary with values equal to iterables of Entities and hashables.
### Keys will be uids for new edges and values of the dictionary will generate the nodes.
setsystem = EntitySet('_',setsystem)
### If no ids are given, return default ids indexed by position in iterator
### This should be an iterable of sets
elif not isinstance(setsystem, EntitySet):
labels = [self.name+str(x) for x in range(len(setsystem))]
setsystem = EntitySet('_',dict(zip(labels, setsystem)))
_reg = setsystem.registry
_nodes = {k: Entity(k,**_reg[k].properties) for k in _reg }
_elements = {j: {k : _nodes[k] for k in setsystem[j]}
for j in setsystem}