graphit/graph.py
def add_edge(self, nd1, nd2, directed=None, node_from_edge=False, unicode_convert=True, run_edge_new=True,
                 **kwargs):
        """
        Add edge between two nodes to the graph
        
        An edge is defined as a connection between two node ID's.
        Edge metadata defined as a dictionary allows it to be queried
        by the various graph query functions.
        
        After de new edge is created the edge class 'new' method is called once
        to allow any custom edge initiation to be performed. This feature can
        be customized by overloading the 'new' method in the
        NodeEdgeToolsBaseClass abstract base class.
        Calling the 'new' method can be disabled using the run_node_new flag.
        
        :param nd1:             first node in edge node pair. Source node in
                                directed graph.
        :param nd2:             second node in edge node pair. Target node in
                                directed graph.
        :param directed:        override the graph definition for directed
                                for the added edge.
        :type directed:         :py:bool
        :param node_from_edge:  make node for edge node id's not in graph
        :type node_from_edge:   :py:bool
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_edge_new:    run the custom initiation method (new method) of
                                the new edge once.
        :type run_edge_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                edge metadata.
        
        :return:                edge ID
        :rtype:                 :py:tuple
        """

        # If node_from_edge than set auto_nid to false forcing identical node
        # and edge ID's
        curr_auto_nid = self.auto_nid
        if node_from_edge:
            self.auto_nid = False

        nd1 = to_unicode(nd1, convert=unicode_convert)
        nd2 = to_unicode(nd2, convert=unicode_convert)
        for nodeid in (nd1, nd2):
            if nodeid not in self.nodes:
                if node_from_edge:
                    self.add_node(nodeid)
                else:
                    raise GraphitException('Node with id {0} not in graph.'.format(nodeid))
        
        # Create edge tuples, directed or un-directed (local override possible for mixed graph).
        if directed is None:
            directed = self.directed
        edges_to_add = make_edges((nd1, nd2), directed=directed)

        edges_added = []
        for i, edge in enumerate(edges_to_add):
            if edge in self.edges:
                logger.warning('Edge between nodes {0}-{1} exists. Use edge update to change attributes.'.format(*edge))
                continue

            # Undirectional edge: second edge points to first edge attributes
            if i == 1 and not directed:
                self.edges[edge] = self.edges[edges_to_add[0]]
            else:
                # Make a deepcopy of the added attributes
                self.edges[edge] = prepaire_data_dict(copy.deepcopy(kwargs))

            edges_added.append(edge)
            logger.debug('Add edge between node {0}-{1}'.format(*edge))
        
        # Call 'new' method of new edges once to allow for custom initiation
        if run_edge_new:
            for edge in edges_added:
                self.getedges(edge).new()

        # If node_from_edge, restore auto_nid setting
        self.auto_nid = curr_auto_nid

        return edges_to_add[0]

        Add edge between two nodes to the graph
        
        An edge is defined as a connection between two node ID's.
        Edge metadata defined as a dictionary allows it to be queried
        by the various graph query functions.
        
        After de new edge is created the edge class 'new' method is called once
        to allow any custom edge initiation to be performed. This feature can
        be customized by overloading the 'new' method in the
        NodeEdgeToolsBaseClass abstract base class.
        Calling the 'new' method can be disabled using the run_node_new flag.
        
        :param nd1:             first node in edge node pair. Source node in
                                directed graph.
        :param nd2:             second node in edge node pair. Target node in
                                directed graph.
        :param directed:        override the graph definition for directed
                                for the added edge.
        :type directed:         :py:bool
        :param node_from_edge:  make node for edge node id's not in graph
        :type node_from_edge:   :py:bool
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_edge_new:    run the custom initiation method (new method) of
                                the new edge once.
        :type run_edge_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                edge metadata.
        
        :return:                edge ID
        :rtype:                 :py:tuple
        
Add edge between two nodes to the graph
An edge is defined as a connection between two node ID's.
Edge metadata defined as a dictionary allows it to be queried
by the various graph query functions.

After de new edge is created the edge class 'new' method is called once
to allow any custom edge initiation to be performed. This feature can
be customized by overloading the 'new' method in the
NodeEdgeToolsBaseClass abstract base class.
Calling the 'new' method can be disabled using the run_node_new flag.
Add edge between two nodes to the graph An edge is defined as a connection between two node ID ' s . Edge metadata defined as a dictionary allows it to be queried by the various graph query functions . After de new edge is created the edge class ' new ' method is called once to allow any custom edge initiation to be performed . This feature can be customized by overloading the ' new ' method in the NodeEdgeToolsBaseClass abstract base class . Calling the ' new ' method can be disabled using the run_node_new flag .
def add_edge(self, nd1, nd2, directed=None, node_from_edge=False, unicode_convert=True, run_edge_new=True,
                 **kwargs):
        curr_auto_nid = self.auto_nid
        if node_from_edge:
            self.auto_nid = False
        nd1 = to_unicode(nd1, convert=unicode_convert)
        nd2 = to_unicode(nd2, convert=unicode_convert)
        for nodeid in (nd1, nd2):
            if nodeid not in self.nodes:
                if node_from_edge:
                    self.add_node(nodeid)
                else:
                    raise GraphitException('Node with id {0} not in graph.'.format(nodeid))
        if directed is None:
            directed = self.directed
        edges_to_add = make_edges((nd1, nd2), directed=directed)
        edges_added = []
        for i, edge in enumerate(edges_to_add):
            if edge in self.edges:
                logger.warning('Edge between nodes {0}-{1} exists. Use edge update to change attributes.'.format(*edge))
                continue
            if i == 1 and not directed:
                self.edges[edge] = self.edges[edges_to_add[0]]
            else:
                self.edges[edge] = prepaire_data_dict(copy.deepcopy(kwargs))
            edges_added.append(edge)
            logger.debug('Add edge between node {0}-{1}'.format(*edge))
        if run_edge_new:
            for edge in edges_added:
                self.getedges(edge).new()
        self.auto_nid = curr_auto_nid
        return edges_to_add[0]
def add_edge ( self , nd1 , nd2 , directed = None , node_from_edge = False , unicode_convert = True , run_edge_new = True , ** kwargs ) : curr_auto_nid = self . auto_nid if node_from_edge : self . auto_nid = False nd1 = to_unicode ( nd1 , convert = unicode_convert ) nd2 = to_unicode ( nd2 , convert = unicode_convert ) for nodeid in ( nd1 , nd2 ) : if nodeid not in self . nodes : if node_from_edge : self . add_node ( nodeid ) else : raise GraphitException ( 'Node with id {0} not in graph.' . format ( nodeid ) ) if directed is None : directed = self . directed edges_to_add = make_edges ( ( nd1 , nd2 ) , directed = directed ) edges_added = [ ] for i , edge in enumerate ( edges_to_add ) : if edge in self . edges : logger . warning ( 'Edge between nodes {0}-{1} exists. Use edge update to change attributes.' . format ( * edge ) ) continue if i == 1 and not directed : self . edges [ edge ] = self . edges [ edges_to_add [ 0 ] ] else : self . edges [ edge ] = prepaire_data_dict ( copy . deepcopy ( kwargs ) ) edges_added . append ( edge ) logger . debug ( 'Add edge between node {0}-{1}' . format ( * edge ) ) if run_edge_new : for edge in edges_added : self . getedges ( edge ) . new ( ) self . auto_nid = curr_auto_nid return edges_to_add [ 0 ]
Add edge between two nodes to the graph
An edge is defined as a connection between two node ID's.
Add edge between two nodes to the graph An edge is defined as a connection between two node ID ' s .
"""
        Add edge between two nodes to the graph
        
        An edge is defined as a connection between two node ID's.
        Edge metadata defined as a dictionary allows it to be queried
        by the various graph query functions.
        
        After de new edge is created the edge class 'new' method is called once
        to allow any custom edge initiation to be performed. This feature can
        be customized by overloading the 'new' method in the
        NodeEdgeToolsBaseClass abstract base class.
        Calling the 'new' method can be disabled using the run_node_new flag.
        
        :param nd1:             first node in edge node pair. Source node in
                                directed graph.
        :param nd2:             second node in edge node pair. Target node in
                                directed graph.
        :param directed:        override the graph definition for directed
                                for the added edge.
        :type directed:         :py:bool
        :param node_from_edge:  make node for edge node id's not in graph
        :type node_from_edge:   :py:bool
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_edge_new:    run the custom initiation method (new method) of
                                the new edge once.
        :type run_edge_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                edge metadata.
        
        :return:                edge ID
        :rtype:                 :py:tuple
        """ # If node_from_edge than set auto_nid to false forcing identical node # and edge ID's # Create edge tuples, directed or un-directed (local override possible for mixed graph). # Undirectional edge: second edge points to first edge attributes # Make a deepcopy of the added attributes # Call 'new' method of new edges once to allow for custom initiation # If node_from_edge, restore auto_nid setting
None
:py:tuple
self
nd1
first node in edge node pair. Source node in
directed graph.
first node in edge node pair . Source node in directed graph .
nd2
second node in edge node pair. Target node in
directed graph.
second node in edge node pair . Target node in directed graph .
directed
override the graph definition for directed
for the added edge.
override the graph definition for directed for the added edge .
node_from_edge
make node for edge node id's not in graph
make node for edge node id ' s not in graph
unicode_convert
convert string types to unicode
convert string types to unicode
run_edge_new
run the custom initiation method (new method) of
the new edge once.
run the custom initiation method ( new method ) of the new edge once .
kwargs
any additional keyword arguments to be added as
edge metadata.
any additional keyword arguments to be added as edge metadata .