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

Method add_edge

pattern/graph/__init__.py:362–385  ·  view source on GitHub ↗

Appends a new Edge to the graph. An optional base parameter can be used to pass a subclass of Edge: Graph.add_edge("cold", "winter", base=IsPropertyOf)

(self, id1, id2, *args, **kwargs)

Source from the content-addressed store, hash-verified

360 return n
361
362 def add_edge(self, id1, id2, *args, **kwargs):
363 """ Appends a new Edge to the graph.
364 An optional base parameter can be used to pass a subclass of Edge:
365 Graph.add_edge("cold", "winter", base=IsPropertyOf)
366 """
367 # Create nodes that are not yet part of the graph.
368 n1 = self.add_node(id1)
369 n2 = self.add_node(id2)
370 # Creates an Edge instance.
371 # If an edge (in the same direction) already exists, yields that edge instead.
372 e1 = n1.links.edge(n2)
373 if e1 and e1.node1 == n1 and e1.node2 == n2:
374 return e1
375 e2 = kwargs.pop("base", Edge)
376 e2 = e2(n1, n2, *args, **kwargs)
377 self.edges.append(e2)
378 # Synchronizes Node.links:
379 # A.links.edge(B) yields edge A->B
380 # B.links.edge(A) yields edge B->A
381 n1.links.append(n2, edge=e2)
382 n2.links.append(n1, edge=e1 or e2)
383 # Clear adjacency cache.
384 self._adjacency = None
385 return e2
386
387 def remove(self, x):
388 """ Removes the given Node (and all its edges) or Edge from the graph.

Callers 15

appendMethod · 0.95
_add_edge_copyMethod · 0.95
test_unlinkMethod · 0.95
test_redirectMethod · 0.95
test_cutMethod · 0.95
test_insertMethod · 0.95
graph.jsFile · 0.45
setUpMethod · 0.45
setUpMethod · 0.45
setUpMethod · 0.45
test_graph_edgesMethod · 0.45
test_cacheMethod · 0.45

Calls 4

add_nodeMethod · 0.95
edgeMethod · 0.45
popMethod · 0.45
appendMethod · 0.45

Tested by 15

test_unlinkMethod · 0.76
test_redirectMethod · 0.76
test_cutMethod · 0.76
test_insertMethod · 0.76
setUpMethod · 0.36
setUpMethod · 0.36
setUpMethod · 0.36
test_graph_edgesMethod · 0.36
test_cacheMethod · 0.36
test_pathsMethod · 0.36
setUpMethod · 0.36
setUpMethod · 0.36