def add_nodes_from(self, nodes, **attr):
        """Add multiple nodes.

        Parameters
        ----------
        nodes : iterable container
            A container of nodes (list, dict, set, etc.).
            OR
            A container of (node, attribute dict) tuples.
            Node attributes are updated using the attribute dict.
        attr : keyword arguments, optional (default= no attributes)
            Update attributes for all nodes in nodes.
            Node attributes specified in nodes as a tuple
            take precedence over attributes specified generally.

        See Also
        --------
        add_node

        Examples
        --------
        >>> from discoursegraphs import DiscourseDocumentGraph
        >>> d = DiscourseDocumentGraph()
        >>> d.add_nodes_from([(1, {'layers':{'token'}, 'word':'hello'}), \
                (2, {'layers':{'token'}, 'word':'world'})])
        >>> d.nodes(data=True)
        [(1, {'layers': {'token'}, 'word': 'hello'}),
         (2, {'layers': {'token'}, 'word': 'world'})]

        Use keywords to update specific node attributes for every node.

        >>> d.add_nodes_from(d.nodes(data=True), weight=1.0)
        >>> d.nodes(data=True)
        [(1, {'layers': {'token'}, 'weight': 1.0, 'word': 'hello'}),
         (2, {'layers': {'token'}, 'weight': 1.0, 'word': 'world'})]

        Use (node, attrdict) tuples to update attributes for specific
        nodes.

        >>> d.add_nodes_from([(1, {'layers': {'tiger'}})], size=10)
        >>> d.nodes(data=True)
        [(1, {'layers': {'tiger', 'token'}, 'size': 10, 'weight': 1.0,
              'word': 'hello'}),
         (2, {'layers': {'token'}, 'weight': 1.0, 'word': 'world'})]
        """
        additional_attribs = attr  # will be added to each node
        for n in nodes:
            try:  # check, if n is a node_id or a (node_id, attrib dict) tuple
                newnode = n not in self.succ  # is node in the graph, yet?
            except TypeError:  # n is a (node_id, attribute dict) tuple
                node_id, ndict = n

                if not 'layers' in ndict:
                    ndict['layers'] = {self.ns}

                layers = ndict['layers']
                assert isinstance(layers, set), \
                    "'layers' must be specified as a set of strings."
                assert all((isinstance(layer, str) for layer in layers)), \
                    "All elements of the 'layers' set must be strings."

                if node_id not in self.succ:  # node doesn't exist, yet
                    self.succ[node_id] = {}
                    self.pred[node_id] = {}
                    newdict = additional_attribs.copy()
                    newdict.update(ndict)  # all given attribs incl. layers
                    self.node[node_id] = newdict
                else:  # node already exists
                    existing_layers = self.node[node_id]['layers']
                    all_layers = existing_layers.union(layers)

                    self.node[node_id].update(ndict)
                    self.node[node_id].update(additional_attribs)
                    self.node[node_id].update({'layers': all_layers})
                continue  # process next node

            # newnode check didn't raise an exception
            if newnode:  # n is a node_id and it's not in the graph, yet
                self.succ[n] = {}
                self.pred[n] = {}
                self.node[n] = attr.copy()
                # since the node isn't represented as a
                # (node_id, attribute dict) tuple, we don't know which layers
                # it is part of. Therefore, we'll add the namespace of the
                # graph as the node layer
                self.node[n].update({'layers': set([self.ns])})
            else:  # n is a node_id and it's already in the graph
                self.node[n].update(attr)
def add_nodes_from ( self , nodes , ** attr ) : additional_attribs = attr for n in nodes : try : newnode = n not in self . succ except TypeError : node_id , ndict = n if not 'layers' in ndict : ndict [ 'layers' ] = { self . ns } layers = ndict [ 'layers' ] assert isinstance ( layers , set ) , "'layers' must be specified as a set of strings." assert all ( ( isinstance ( layer , str ) for layer in layers ) ) , "All elements of the 'layers' set must be strings." if node_id not in self . succ : self . succ [ node_id ] = { } self . pred [ node_id ] = { } newdict = additional_attribs . copy ( ) newdict . update ( ndict ) self . node [ node_id ] = newdict else : existing_layers = self . node [ node_id ] [ 'layers' ] all_layers = existing_layers . union ( layers ) self . node [ node_id ] . update ( ndict ) self . node [ node_id ] . update ( additional_attribs ) self . node [ node_id ] . update ( { 'layers' : all_layers } ) continue if newnode : self . succ [ n ] = { } self . pred [ n ] = { } self . node [ n ] = attr . copy ( ) self . node [ n ] . update ( { 'layers' : set ( [ self . ns ] ) } ) else : self . node [ n ] . update ( attr )
Add multiple nodes.

        Parameters
        ----------
        nodes : iterable container
            A container of nodes (list, dict, set, etc.).
            OR
            A container of (node, attribute dict) tuples.
            Node attributes are updated using the attribute dict.
        attr : keyword arguments, optional (default= no attributes)
            Update attributes for all nodes in nodes.
            Node attributes specified in nodes as a tuple
            take precedence over attributes specified generally.

        See Also
        --------
        add_node

        Examples
        --------
        >>> from discoursegraphs import DiscourseDocumentGraph
        >>> d = DiscourseDocumentGraph()
        >>> d.add_nodes_from([(1, {'layers':{'token'}, 'word':'hello'}), \
                (2, {'layers':{'token'}, 'word':'world'})])
        >>> d.nodes(data=True)
        [(1, {'layers': {'token'}, 'word': 'hello'}),
         (2, {'layers': {'token'}, 'word': 'world'})]

        Use keywords to update specific node attributes for every node.

        >>> d.add_nodes_from(d.nodes(data=True), weight=1.0)
        >>> d.nodes(data=True)
        [(1, {'layers': {'token'}, 'weight': 1.0, 'word': 'hello'}),
         (2, {'layers': {'token'}, 'weight': 1.0, 'word': 'world'})]

        Use (node, attrdict) tuples to update attributes for specific
        nodes.

        >>> d.add_nodes_from([(1, {'layers': {'tiger'}})], size=10)
        >>> d.nodes(data=True)
        [(1, {'layers': {'tiger', 'token'}, 'size': 10, 'weight': 1.0,
              'word': 'hello'}),
         (2, {'layers': {'token'}, 'weight': 1.0, 'word': 'world'})]