graphit/graph.py
def add_node(self, node=None, unicode_convert=True, run_node_new=True, **kwargs):
        """
        Add a node to the graph
        
        All nodes are stored using a dictionary like data structure that can be
        represented like:
            
            {nid: {'_id': auto_nid, attribute_key: attribute_value, ....}}

        'nid' is the primary node identifier which is either an auto-incremented
        unique integer value if `Graph.auto_nid` equals True or a custom value
        when False.

        If `Graph.auto_nid` equals True, the `node` parameter is stored as part
        of the node attributes (value in the above dict example) using the
        `Graph.key_tag` as key unless overloaded by any additional keyword
        arguments provided to the method.
        Using the key_tag and value_tag is a convenient way of storing node
        data that should be accessible using the same key. The key_tag and
        value_tag are used as default in the various dictionary style set and
        get methods of the graph, node and edge classes.

        When `Graph.auto_nid` equals False, the `node` parameter becomes the
        primary node identifier that can be any hashable object except None.

        .. note:: With auto_nid disabled the method checks if there is a node
                  with nid in the graph already. If found, a warning is logged
                  and the attributes of the existing node are updated.

        The node attribute dictionary contains at least the '_id' attribute
        representing the unique auto-incremented integer node identifier and
        any additional keyword argument provided to the method (kwargs)

        After de new node is created the node class 'new' method is called once
        to allow any custom node 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 node:            object representing the node
        :type node:             any hashable object
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_node_new:    run the custom initiation method (new method) of
                                the new node once.
        :type run_node_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                node attributes.

        :return:                node ID (nid)
        :rtype:                 int
        """

        # Use internal nid or node as node ID
        if self.auto_nid:
            nid = self._nodeid
        else:

            # Node should not be None
            if node is None:
                raise GraphitException('Node ID required when auto_nid is disabled')

            # Node needs to be hashable
            nid = to_unicode(node, convert=unicode_convert)
            if not isinstance(nid, collections.Hashable):
                raise GraphitException('Node {0} of type {1} not a hashable object'.format(nid, type(nid).__name__))
            
            # If node exist, log a warning, update attributes and return
            if nid in self.nodes:
                logger.warning('Node with identifier "{0}" already assigned'.format(nid))
                self.nodes[nid].update(copy.deepcopy(kwargs))
                return nid
        
        logger.debug('Add node. id: {0}, type: {1}'.format(nid, type(node).__name__))
        
        # Prepare node data dictionary, always set a unique ID.
        node_data = {self.key_tag: to_unicode(node, convert=unicode_convert)}
        node_data.update(prepaire_data_dict(copy.deepcopy(kwargs)))
        node_data[u'_id'] = self._nodeid
        self._nodeid += 1

        self.nodes[nid] = node_data

        # Call 'new' method of the new node once to allow for custom initiation
        if run_node_new:
            self.getnodes(nid).new()
        
        return nid

        Add a node to the graph
        
        All nodes are stored using a dictionary like data structure that can be
        represented like:
            
            {nid: {'_id': auto_nid, attribute_key: attribute_value, ....}}

        'nid' is the primary node identifier which is either an auto-incremented
        unique integer value if `Graph.auto_nid` equals True or a custom value
        when False.

        If `Graph.auto_nid` equals True, the `node` parameter is stored as part
        of the node attributes (value in the above dict example) using the
        `Graph.key_tag` as key unless overloaded by any additional keyword
        arguments provided to the method.
        Using the key_tag and value_tag is a convenient way of storing node
        data that should be accessible using the same key. The key_tag and
        value_tag are used as default in the various dictionary style set and
        get methods of the graph, node and edge classes.

        When `Graph.auto_nid` equals False, the `node` parameter becomes the
        primary node identifier that can be any hashable object except None.

        .. note:: With auto_nid disabled the method checks if there is a node
                  with nid in the graph already. If found, a warning is logged
                  and the attributes of the existing node are updated.

        The node attribute dictionary contains at least the '_id' attribute
        representing the unique auto-incremented integer node identifier and
        any additional keyword argument provided to the method (kwargs)

        After de new node is created the node class 'new' method is called once
        to allow any custom node 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 node:            object representing the node
        :type node:             any hashable object
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_node_new:    run the custom initiation method (new method) of
                                the new node once.
        :type run_node_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                node attributes.

        :return:                node ID (nid)
        :rtype:                 int
        
Add a node to the graph
All nodes are stored using a dictionary like data structure that can be
represented like.



'nid' is the primary node identifier which is either an auto-incremented
unique integer value if `Graph.auto_nid` equals True or a custom value
when False.



When `Graph.auto_nid` equals False, the `node` parameter becomes the
primary node identifier that can be any hashable object except None.

: With auto_nid disabled the method checks if there is a node
with nid in the graph already. If found, a warning is logged
and the attributes of the existing node are updated.

The node attribute dictionary contains at least the '_id' attribute
representing the unique auto-incremented integer node identifier and
any additional keyword argument provided to the method (kwargs)

After de new node is created the node class 'new' method is called once
to allow any custom node 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 a node to the graph All nodes are stored using a dictionary like data structure that can be represented like . ' nid ' is the primary node identifier which is either an auto - incremented unique integer value if ` Graph . auto_nid ` equals True or a custom value when False . When ` Graph . auto_nid ` equals False the ` node ` parameter becomes the primary node identifier that can be any hashable object except None . : With auto_nid disabled the method checks if there is a node with nid in the graph already . If found a warning is logged and the attributes of the existing node are updated . The node attribute dictionary contains at least the ' _id ' attribute representing the unique auto - incremented integer node identifier and any additional keyword argument provided to the method ( kwargs ) After de new node is created the node class ' new ' method is called once to allow any custom node 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_node(self, node=None, unicode_convert=True, run_node_new=True, **kwargs):
        if self.auto_nid:
            nid = self._nodeid
        else:
            if node is None:
                raise GraphitException('Node ID required when auto_nid is disabled')
            nid = to_unicode(node, convert=unicode_convert)
            if not isinstance(nid, collections.Hashable):
                raise GraphitException('Node {0} of type {1} not a hashable object'.format(nid, type(nid).__name__))
            if nid in self.nodes:
                logger.warning('Node with identifier "{0}" already assigned'.format(nid))
                self.nodes[nid].update(copy.deepcopy(kwargs))
                return nid
        logger.debug('Add node. id: {0}, type: {1}'.format(nid, type(node).__name__))
        node_data = {self.key_tag: to_unicode(node, convert=unicode_convert)}
        node_data.update(prepaire_data_dict(copy.deepcopy(kwargs)))
        node_data[u'_id'] = self._nodeid
        self._nodeid += 1
        self.nodes[nid] = node_data
        if run_node_new:
            self.getnodes(nid).new()
        return nid
def add_node ( self , node = None , unicode_convert = True , run_node_new = True , ** kwargs ) : if self . auto_nid : nid = self . _nodeid else : if node is None : raise GraphitException ( 'Node ID required when auto_nid is disabled' ) nid = to_unicode ( node , convert = unicode_convert ) if not isinstance ( nid , collections . Hashable ) : raise GraphitException ( 'Node {0} of type {1} not a hashable object' . format ( nid , type ( nid ) . __name__ ) ) if nid in self . nodes : logger . warning ( 'Node with identifier "{0}" already assigned' . format ( nid ) ) self . nodes [ nid ] . update ( copy . deepcopy ( kwargs ) ) return nid logger . debug ( 'Add node. id: {0}, type: {1}' . format ( nid , type ( node ) . __name__ ) ) node_data = { self . key_tag : to_unicode ( node , convert = unicode_convert ) } node_data . update ( prepaire_data_dict ( copy . deepcopy ( kwargs ) ) ) node_data [ u'_id' ] = self . _nodeid self . _nodeid += 1 self . nodes [ nid ] = node_data if run_node_new : self . getnodes ( nid ) . new ( ) return nid
Add a node to the graph
All nodes are stored using a dictionary like data structure that can be
represented like:
Add a node to the graph All nodes are stored using a dictionary like data structure that can be represented like :
"""
        Add a node to the graph
        
        All nodes are stored using a dictionary like data structure that can be
        represented like:
            
            {nid: {'_id': auto_nid, attribute_key: attribute_value, ....}}

        'nid' is the primary node identifier which is either an auto-incremented
        unique integer value if `Graph.auto_nid` equals True or a custom value
        when False.

        If `Graph.auto_nid` equals True, the `node` parameter is stored as part
        of the node attributes (value in the above dict example) using the
        `Graph.key_tag` as key unless overloaded by any additional keyword
        arguments provided to the method.
        Using the key_tag and value_tag is a convenient way of storing node
        data that should be accessible using the same key. The key_tag and
        value_tag are used as default in the various dictionary style set and
        get methods of the graph, node and edge classes.

        When `Graph.auto_nid` equals False, the `node` parameter becomes the
        primary node identifier that can be any hashable object except None.

        .. note:: With auto_nid disabled the method checks if there is a node
                  with nid in the graph already. If found, a warning is logged
                  and the attributes of the existing node are updated.

        The node attribute dictionary contains at least the '_id' attribute
        representing the unique auto-incremented integer node identifier and
        any additional keyword argument provided to the method (kwargs)

        After de new node is created the node class 'new' method is called once
        to allow any custom node 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 node:            object representing the node
        :type node:             any hashable object
        :param unicode_convert: convert string types to unicode
        :type unicode_convert:  :py:bool
        :param run_node_new:    run the custom initiation method (new method) of
                                the new node once.
        :type run_node_new:     :py:bool
        :param kwargs:          any additional keyword arguments to be added as
                                node attributes.

        :return:                node ID (nid)
        :rtype:                 int
        """ # Use internal nid or node as node ID # Node should not be None # Node needs to be hashable # If node exist, log a warning, update attributes and return # Prepare node data dictionary, always set a unique ID. # Call 'new' method of the new node once to allow for custom initiation
node ID (nid)
node ID ( nid )
int
self
node
object representing the node
object representing the node
unicode_convert
convert string types to unicode
convert string types to unicode
run_node_new
run the custom initiation method (new method) of
the new node once.
run the custom initiation method ( new method ) of the new node once .
kwargs
any additional keyword arguments to be added as
node attributes.
any additional keyword arguments to be added as node attributes .