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

Function unlink

pattern/graph/__init__.py:1039–1055  ·  view source on GitHub ↗

Removes the edges between node1 and node2. If only node1 is given, removes all edges to and from it. This does not remove node1 from the graph.

(graph, node1, node2=None)

Source from the content-addressed store, hash-verified

1037# with respect for the surrounding nodes.
1038
1039def unlink(graph, node1, node2=None):
1040 """ Removes the edges between node1 and node2.
1041 If only node1 is given, removes all edges to and from it.
1042 This does not remove node1 from the graph.
1043 """
1044 if not isinstance(node1, Node):
1045 node1 = graph[node1]
1046 if not isinstance(node2, Node) and node2 is not None:
1047 node2 = graph[node2]
1048 for e in list(graph.edges):
1049 if node1 in (e.node1, e.node2) and node2 in (e.node1, e.node2, None):
1050 graph.edges.remove(e)
1051 try:
1052 node1.links.remove(node2)
1053 node2.links.remove(node1)
1054 except: # 'NoneType' object has no attribute 'links'
1055 pass
1056
1057def redirect(graph, node1, node2):
1058 """ Connects all of node1's edges to node2 and unlinks node1.

Callers 3

redirectFunction · 0.85
cutFunction · 0.85
insertFunction · 0.85

Calls 1

removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…