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

Method remove

pattern/graph/__init__.py:387–403  ·  view source on GitHub ↗

Removes the given Node (and all its edges) or Edge from the graph. Note: removing Edge a->b does not remove Edge b->a.

(self, x)

Source from the content-addressed store, hash-verified

385 return e2
386
387 def remove(self, x):
388 """ Removes the given Node (and all its edges) or Edge from the graph.
389 Note: removing Edge a->b does not remove Edge b->a.
390 """
391 if isinstance(x, Node) and x.id in self:
392 self.pop(x.id)
393 self.nodes.remove(x); x.graph = None
394 # Remove all edges involving the given node.
395 for e in list(self.edges):
396 if x in (e.node1, e.node2):
397 if x in e.node1.links: e.node1.links.remove(x)
398 if x in e.node2.links: e.node2.links.remove(x)
399 self.edges.remove(e)
400 if isinstance(x, Edge):
401 self.edges.remove(x)
402 # Clear adjacency cache.
403 self._adjacency = None
404
405 def node(self, id):
406 """ Returns the node in the graph with the given id.

Callers 1

pruneMethod · 0.95

Calls 2

popMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected