#NEWLINE# def rdflib_to_networkx_digraph( graph , calc_weights = True , edge_attrs = ( lambda s , p , o : { #NEWLINE# #INDENT# 'triples' : [ ( s , p , o ) ] , #NEWLINE# #UNINDENT# } ) , **kwds ) : #NEWLINE# #INDENT# "Converts the given graph into a networkx.DiGraph.\n\n    As an rdflib.Graph() can contain multiple edges between nodes, by default\n    adds the a 'triples' attribute to the single DiGraph edge with a list of\n    all triples between s and o.\n    Also by default calculates the edge weight as the length of triples.\n\n    Args:\n        graph: a rdflib.Graph.\n        calc_weights: If true calculate multi-graph edge-count as edge 'weight'\n        edge_attrs: Callable to construct later edge_attributes. It receives\n            3 variables (s, p, o) and should construct a dictionary that is\n            passed to networkx's add_edge(s, o, **attrs) function.\n\n            By default this will include setting the 'triples' attribute here,\n            which is treated specially by us to be merged. Other attributes of\n            multi-edges will only contain the attributes of the first edge.\n            If you don't want the 'triples' attribute for tracking, set this to\n            `lambda s, p, o: {}`.\n\n    Returns:\n        networkx.DiGraph\n\n    >>> from rdflib import Graph, URIRef, Literal\n    >>> g = Graph()\n    >>> a, b, l = URIRef('a'), URIRef('b'), Literal('l')\n    >>> p, q = URIRef('p'), URIRef('q')\n    >>> edges = [(a, p, b), (a, q, b), (b, p, a), (b, p, l)]\n    >>> for t in edges:\n    ...     g.add(t)\n    ...\n    >>> dg = rdflib_to_networkx_digraph(g)\n    >>> dg[a][b]['weight']\n    2\n    >>> sorted(dg[a][b]['triples']) == [(a, p, b), (a, q, b)]\n    True\n    >>> len(dg.edges())\n    3\n    >>> dg.size()\n    3\n    >>> dg.size(weight='weight')\n    4.0\n\n    >>> dg = rdflib_to_networkx_graph(g, False, edge_attrs=lambda s,p,o:{})\n    >>> 'weight' in dg[a][b]\n    False\n    >>> 'triples' in dg[a][b]\n    False\n    " #NEWLINE# import networkx as nx #NEWLINE# dg = nx . DiGraph ( ) #NEWLINE# _rdflib_to_networkx_graph ( graph , dg , calc_weights , edge_attrs , ** kwds ) #NEWLINE# return dg