MCPcopy Index your code
hub / github.com/clips/pattern / flatten

Method flatten

pattern/graph/__init__.py:147–160  ·  view source on GitHub ↗

Recursively lists the node and nodes linked to it. Depth 0 returns a list with the node. Depth 1 returns a list with the node and all the directly linked nodes. Depth 2 includes the linked nodes' links, and so on.

(self, depth=1, traversable=lambda node, edge: True, _visited=None)

Source from the content-addressed store, hash-verified

145 betweenness = betweenness_centrality = centrality
146
147 def flatten(self, depth=1, traversable=lambda node, edge: True, _visited=None):
148 """ Recursively lists the node and nodes linked to it.
149 Depth 0 returns a list with the node.
150 Depth 1 returns a list with the node and all the directly linked nodes.
151 Depth 2 includes the linked nodes' links, and so on.
152 """
153 _visited = _visited or {}
154 _visited[self.id] = (self, depth)
155 if depth >= 1:
156 for n in self.links:
157 if n.id not in _visited or _visited[n.id][1] < depth-1:
158 if traversable(self, self.links.edges[n.id]):
159 n.flatten(depth-1, traversable, _visited)
160 return [n for n,d in _visited.values()] # Fast, but not order-preserving.
161
162 def draw(self, weighted=False):
163 """ Draws the node as a circle with the given radius, fill, stroke and strokewidth.

Callers 8

fringeMethod · 0.45
partitionFunction · 0.45
graph.jsFile · 0.45
haloMethod · 0.45
haloFunction · 0.45
taxonomyMethod · 0.45
_test_clusterMethod · 0.45
test_flattenMethod · 0.45

Calls 1

valuesMethod · 0.45

Tested by 2

_test_clusterMethod · 0.36
test_flattenMethod · 0.36