### Test Documentation Examples Source: https://networkdisk.inria.fr/install Runs doctests on the examples included in the NetworkDisk documentation. ```Shell make -C doc/ doctest ``` -------------------------------- ### Install Documentation Dependencies Source: https://networkdisk.inria.fr/install Installs the required Sphinx packages and extensions for building NetworkDisk's documentation. ```Shell python3 -m pip -r install doc/requirements.txt ``` -------------------------------- ### Install NetworkDisk from Source Source: https://networkdisk.inria.fr/install Installs the NetworkDisk package from its source directory, including all necessary dependencies. ```Shell python3 -m pip install . ``` -------------------------------- ### Install NetworkDisk with Optional Dependencies Source: https://networkdisk.inria.fr/install Installs NetworkDisk with optional dependencies required for running tests or generating documentation. ```Shell python3 -m pip install .[test] ``` ```Shell python3 -m pip install .[doc] ``` -------------------------------- ### Build NetworkDisk Documentation Source: https://networkdisk.inria.fr/install Builds the HTML documentation for NetworkDisk locally using the make command. ```Shell make -C doc/ html ``` -------------------------------- ### Install NetworkDisk from PyPI Source: https://networkdisk.inria.fr/install Installs the NetworkDisk package along with its dependencies from the Python Package Index (PyPI). ```Shell python3 -m pip install networkdisk ``` -------------------------------- ### Install lxml Module Source: https://networkdisk.inria.fr/examples/dblp Installs the 'lxml' Python module, which is a prerequisite for building the DBLP graph. This command uses pip, the Python package installer. ```bash python3 -m pip install lxml ``` -------------------------------- ### Test NetworkDisk from Source Source: https://networkdisk.inria.fr/install Executes tests for the NetworkDisk package when it is in its source directory using the pytest framework. ```Shell pytest networkdisk ``` -------------------------------- ### Test NetworkDisk Installed Package (Python) Source: https://networkdisk.inria.fr/install Tests the installed NetworkDisk package programmatically using its Python API. ```Python import networkdisk as nd nd.test() ``` ```Shell python3 -c "import networkdisk as nd; nd.test()" ``` -------------------------------- ### Test NetworkDisk Installed Package (Command Line) Source: https://networkdisk.inria.fr/install Tests the installed NetworkDisk package from a shell command prompt using pytest. ```Shell pytest --pyargs networkdisk ``` -------------------------------- ### Retrieve and Compare Node Data (Python) Source: https://networkdisk.inria.fr/examples/dblp Shows how to fetch articles associated with a node and retrieve detailed data for a specific article. It includes comparing the fetched data with expected values. ```Python >>> knuth_articles = dblp[Knuth] >>> min_article = min(knuth_articles) # fetch one article >>> Kdata = dblp.nodes[min_article].fold() # fold force to fetch all node data >>> Kdata_expected = {'_attrib': {'mdate': '2020-07-09', 'key': 'journals/combinatorics/Knuth96'}, 'ee': {'_attrib': {'type': 'oa'}, '_text': 'http://www.combinatorics.org/Volume_3/Abstracts/v3i2r5.html'}, 'journal': 'Electron. J. Comb.', 'number': '2', 'title': 'Overlapping Pfaffians.', 'url': 'db/journals/combinatorics/combinatorics3.html#Knuth96', 'volume': '3', 'year': 1996} >>> Kdata == Kdata_expected True ``` -------------------------------- ### Print Shortest Path Details (Python) Source: https://networkdisk.inria.fr/examples/dblp Illustrates how to retrieve and print the details of nodes along the shortest path between two specified nodes in the graph. ```Python >>> for i, e in enumerate(nx.shortest_path(dblp, Shannon, Knuth)): ... if i%2: ... print(">Title:", dblp.nodes[e]["title"]) ... else: ... print("Name:", dblp.nodes[e]["name"]) Name: Claude E. Shannon >Title: Where the Action Is and Was in Information Science. Name: Gerard Salton >Title: ACM TODS Publication Policy. Name: Philip A. Bernstein >Title: The Concurrency Control Mechanism of SDD-1: A System for Distributed Databases (The Fully Redundant Case). Name: Christos H. Papadimitriou >Title: An Algorithmic View of the Universe. Name: Donald E. Knuth ``` -------------------------------- ### Copy Subgraph to NetworkX Format (Python) Source: https://networkdisk.inria.fr/examples/dblp Demonstrates converting a NetworkDisk subgraph into a NetworkX graph object for potentially faster operations on smaller graphs. ```Python >>> nx_dblp_knuth = dblp_knuth.copy_to_networkx(edge_data=False) ``` -------------------------------- ### Load and Inspect DBLP Graph Nodes (Python) Source: https://networkdisk.inria.fr/examples/dblp Demonstrates loading a NetworkDisk graph from a SQLite database and finding a specific node by its 'name' attribute. It also shows how to access node data and its attributes. ```Python >>> dblp = nd.sqlite.Graph(db=dblp_path) >>> Knuth = dblp.find_one_node("name", name="Donald E. Knuth") >>> #positional argument "name" to say “the node should have an attribute "name"” >>> #keyworded argument name="Donald E. Knuth" to say “if the node has an attribute "name" then the associated value should be "Donald E. Knuth"” >>> print(Knuth) # nodes are just indices 280664 >>> dblp.nodes[Knuth] {name: 'Donald E. Knuth'} ``` -------------------------------- ### Python Threading Example for SQLite Graph Source: https://networkdisk.inria.fr/_sources/references/threading Demonstrates how to create and manage threads for accessing an SQLite Graph instance. It includes a custom Thread class that interacts with the graph and handles potential exceptions during threaded operations. The example shows how to start threads, join them, and check for exceptions, illustrating the thread-safe behavior when using a file-based SQLite database. ```Python import threading import networkx as nx import nd class Thread(threading.Thread): def __init__(self, Graph, i): self.graph = Graph self.identity = i self.exception_raised = 0 super().__init__() def run(self): try: self.res = list(self.graph[self.identity]) # in Thread access to the db except Exception as e: self.exception_raised += 1 def join(self): self.graph.helper.close() # close the thread connection on join # Example usage: G = nd.sqlite.Graph(db=":tempfile:") G.add_edges_from(enumerate(range(1, 100))) # Build some line graph threads = [Thread(G, i) for i in range(3)] for t in threads: t.start() for t in threads: t.join() print(sum(t.exception_raised for t in threads)) ``` -------------------------------- ### Calculate Shortest Path Length (Python) Source: https://networkdisk.inria.fr/examples/dblp Demonstrates using NetworkX's shortest path functionality with a NetworkDisk graph to find the distance between two nodes. ```Python >>> Shannon = dblp.find_one_node("name", name="Claude E. Shannon") >>> nx.shortest_path_length(dblp, Shannon, Knuth) 8 ``` -------------------------------- ### Execute Graph Generation Script Source: https://networkdisk.inria.fr/examples/dblp Executes the bash script 'generate_graph.sh' to download and build the DBLP graph. The script takes a directory name as an argument; if not provided, it uses a date-based folder. ```bash bash generate_graph.sh foo ``` -------------------------------- ### Build and Query Subgraph by Distance (Python) Source: https://networkdisk.inria.fr/examples/dblp Shows how to create a subgraph containing nodes within a specified distance from a given node and then extract nodes with a 'name' attribute from this subgraph. ```Python >>> Neighbors_2 = nx.algorithms.descendants_at_distance(dblp, Knuth, 2).union(dblp[Knuth], [Knuth]) >>> dblp_knuth = dblp.subgraph(Neighbors_2) >>> len(dblp_knuth.nodes()) 246 >>> len(dblp_knuth.edges()) 278 >>> coauthors = list(dblp_knuth.find_all_nodes("name")) >>> len(coauthors) 73 ``` -------------------------------- ### Python Threading Example for NetworkDisk SQLite Graph Source: https://networkdisk.inria.fr/references/threading Demonstrates how to create a thread-safe Graph instance using NetworkDisk's SQLite backend. It shows how to define a custom Thread class that interacts with the Graph and manages its connection, including closing the helper connection on join. The example illustrates both successful threaded access and scenarios where threading errors occur due to limitations with in-memory or improperly initialized SQLite graphs. ```Python import threading >>> class Thread(threading.Thread): ... def __init__(self, Graph, i): ... self.graph = Graph ... self.identity = i ... self.exception_raised = 0 ... super().__init__() ... def run(self): ... try: ... self.res = list(self.graph[self.identity]) ... # in Thread access to the db ... except Exception as e: ... self.exception_raised += 1 ... def join(self): ... self.graph.helper.close() ... # close the thread connection on join >>> G = nd.sqlite.Graph(db=":tempfile:") >>> G.add_edges_from(enumerate(range(1, 100))) # Build some line graph >>> threads = [Thread(G, i) for i in range(3)] >>> for t in threads: ... t.start() >>> for t in threads: ... t.join() >>> sum(t.exception_raised for t in threads) 0 >>> H = nd.sqlite.Graph() >>> threads = [Thread(H, i) for i in range(3)] >>> for t in threads: ... t.start() >>> for t in threads: ... t.join() >>> sum(t.exception_raised for t in threads) 3 >>> J = nd.sqlite.Graph() >>> K = nd.sqlite.Graph(db=J.helper.db) >>> threads = [Thread(K, i) for i in range(3)] >>> for t in threads: ... t.start() >>> for t in threads: ... t.join() >>> sum(t.exception_raised for t in threads) 3 ``` -------------------------------- ### BinRel Class - Get Keys (Python) Source: https://networkdisk.inria.fr/references/utils The BinRel class provides a view of its keys. The keys() method returns a set-like object that offers a view on the collection's keys. ```Python class BinRel: def keys(self): """Return a set-like object providing a view on D's keys.""" pass ``` -------------------------------- ### Python: Manual Transaction Rollback Source: https://networkdisk.inria.fr/tutorials/introduction This example illustrates manual rollback of a NetworkDisk transaction. It shows adding an edge, confirming its presence, and then explicitly rolling back the transaction, ensuring the edge is removed. ```Python >>> with G.helper.transaction: ... G.add_edge(-99, 99) ... print((-99, 99) in G.edges) ... G.helper.transaction.rollback() True >>> (-99, 99) in G.edges False ``` ```Python >>> with G.helper.transaction as t: #t is a shorthand for G.helper.transaction ... G.add_edge(-99, 99) ... print((-99, 99) in G.edges) ... t.rollback() True >>> (-99, 99) in G.edges False ``` -------------------------------- ### Registering and Decorating Functions with Dialect Source: https://networkdisk.inria.fr/references/querybuilder/dialect Demonstrates how to register functions with a Dialect instance, both directly and using a decorator. It shows how registered functions can be made dialect-aware (receiving the dialect as the first argument) or standard Python functions. The examples illustrate accessing the original function and renaming registered functions. ```Python >>> dialect = Dialect('foo') >>> def f(*args): ... print(*args) >>> f2 = dialect.register(True, f) # return the decored function >>> f2 == f True >>> dialect.f(1, 2, 3) Dialect(foo) 1 2 3 >>> dialect.f == f False >>> dialect.f.func == f True >>> decored_f = dialect.register(False, f) >>> f2 = dialect.f(1, 2, 3) 1 2 3 >>> dialect.f == f True >>> decored_f = dialect.register(False, f, name="bar") >>> dialect.bar(1, 2, 3) 1 2 3 >>> print(dialect) Dialect(foo) >>> @dialect.register(True) ... def g(*args): ... print(*args) >>> dialect.g(1, 2, 3) Dialect(foo) 1 2 3 >>> @dialect.register(False) ... def h(*args): ... print(*args) >>> dialect.h(1, 2, 3) 1 2 3 ``` -------------------------------- ### Instantiate Graph with SQL Logger (Python) Source: https://networkdisk.inria.fr/tutorials/introduction Shows how to initialize a NetworkDisk graph with the SQL logger enabled. This is helpful for understanding the schema creation process as it happens. ```Python >>> G = nd.sqlite.DiGraph(sql_logger=True) ``` -------------------------------- ### Create and Access SQLite Graphs Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates creating multiple graph instances pointing to the same or different SQLite databases. It shows how to add nodes and check for their existence across different graph instances. ```Python _G = nd.sqlite.Graph(db="/tmp/myotherdb.db") _H = nd.sqlite.Graph(db="/tmp/myotherdb.db") #_H points to the same DB-graph as _G _I = nd.sqlite.DiGraph(db="/tmp/myotherdb.db", name="other graph") _J = nd.sqlite.Graph(db="/tmp/myotherdb.db") #_J is a new anonymous graph _G.add_node(0) print((0 in _G, 0 in _H, 0 in _J)) ``` -------------------------------- ### Adding Nodes with Local and Global Data (Python) Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates adding nodes with both local data specified per node and global data applied to all nodes. It shows how local data takes precedence over global data. ```Python >>> G = nd.sqlite.Graph() >>> G.add_nodes_from([(0, {'data': "local"}), (1,), (2, {'foo': "bar"})], data="global", generation=0) >>> sorted(G.nodes(data=True)) [(0, {'data': 'local', 'generation': 0}), (1, {'data': 'global', 'generation': 0}), (2, {'data': 'global', 'foo': 'bar', 'generation': 0})] ``` -------------------------------- ### NetworkDisk Graph Initialization (Python) Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates the initialization of NetworkDisk graph classes, which mirror NetworkX's Graph and DiGraph. These classes are designed for database interaction, with specific methods to handle database operations. ```python from networkdisk import Graph, DiGraph # Initialize a NetworkDisk Graph G = Graph() # Initialize a NetworkDisk DiGraph DG = DiGraph() ``` -------------------------------- ### Get Edge Data Source: https://networkdisk.inria.fr/references/introduction Explains how to retrieve the attribute dictionary for a specific edge (u, v) in a graph. It highlights that this method is similar to direct dictionary access (G[u][v]) but provides a default value instead of raising an error if the edge does not exist. Examples show direct access, using a tuple for edge nodes, and handling non-existent edges with a default value. ```Python >>> G = nx.path_graph(4) >>> G[0][1] {} >>> G[0][1]["weight"] = 7 >>> G[0][1]["weight"] 7 >>> G[1][0]["weight"] 7 ``` ```Python >>> G = nx.path_graph(4) >>> G.get_edge_data(0, 1) {} >>> e = (0, 1) >>> G.get_edge_data(*e) {} >>> G.get_edge_data("a", "b", default=0) 0 ``` -------------------------------- ### Python: Create and Populate SQLite Graph Source: https://networkdisk.inria.fr/tutorials/finding Demonstrates how to create a directed graph using NetworkDisk's SQLite implementation and add nodes with attributes and edges. This is the foundational step for querying. ```Python >>> G = nd.sqlite.DiGraph() >>> G.add_node(0, foo="bar") >>> G.add_node(1, foo="car") >>> G.add_node(2, value=23) >>> G.add_node(3, foo="bar", value=42) >>> G.add_node(4, value=54, foo="bir") >>> G.add_edges_from([(0, 1, {"w":0}), (1, 2, {"w":1}), (0, 2), (3, 4, {"color":"black"})]) ``` -------------------------------- ### Load Graph from Autofile Path Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates loading a graph from an autofile path. If the file exists, the graph is loaded; otherwise, a new one is created. Multiple instances pointing to the same autofile path share the same data. ```Python >>> B = nd.sqlite.Graph(db=':autofile:') >>> B.helper.dbpath == A.helper.dbpath True >>> A.add_edge(0, 1, foo='bar') >>> sorted(A.edges) [(0, 1)] >>> sorted(B.edges) [(0, 1)] ``` -------------------------------- ### Sequential Node Insertion (Python) Source: https://networkdisk.inria.fr/tutorials/introduction Illustrates a slow, sequential method of adding nodes one by one using a Python loop. This approach generates a separate transaction for each node insertion, leading to poor performance. ```Python >>> for i in range(2): ... G.add_node(f"new_node_{i}") ``` -------------------------------- ### Get Nodes with Specific Attribute (NetworkX) Source: https://networkdisk.inria.fr/references/introduction Illustrates how to fetch nodes and a specific attribute's value. It handles cases where the attribute might be missing by providing a default value. ```Python >>> list(G.nodes(data="foo")) [(0, 'bar'), (1, None), (2, None)] >>> list(G.nodes.data("foo")) [(0, 'bar'), (1, None), (2, None)] ``` -------------------------------- ### Get All Nodes in Graph (NetworkX) Source: https://networkdisk.inria.fr/references/introduction Demonstrates two common methods to retrieve all nodes from a NetworkX graph. This is useful for iterating through the graph's nodes or performing set-like operations. ```Python >>> G = nx.path_graph(3) >>> list(G.nodes) [0, 1, 2] >>> list(G) [0, 1, 2] ``` -------------------------------- ### Create and Manage Graphs with MasterGraphs Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates using `nd.sqlite.MasterGraphs` to create and manage graphs within a new or existing SQLite database. It shows how to create un/directed graphs with specified names and lists the contents of the master table. ```Python M = nd.sqlite.MasterGraphs("/tmp/master.db") # Empty DB file _ = M.new_ungraph(name="A") #the created graph is returned _ = M.new_ungraph(name="B") _ = M.new_diGraph(name="C") _ = M.new_diGraph(name="D") _ = M.new_ungraph(name=1) _ = M.new_ungraph(name=2) M.pretty_print() ``` -------------------------------- ### Initialize SQLite Helper and Configure Logging Source: https://networkdisk.inria.fr/_sources/references/querybuilder/index Imports the SQLite dialect and initializes a helper class for an in-memory SQLite database. It also demonstrates how to activate and configure SQL logging to view generated queries. ```Python from networkdisk.sqlite.dialect import sqlitedialect as dialect helper = dialect.helper.Helper(":memory:") print(helper) helper.sql_logger.active = True helper.sql_logger.color = False ``` -------------------------------- ### Initialize Graph with NetworkDisk SQLite Helper Source: https://networkdisk.inria.fr/tutorials/introduction Initializes a NetworkDisk Graph using a NetworkDisk SQLite Helper object, which wraps a `sqlite3` connector. The graph also loses direct access to the DB file path. ```Python >>> M = nd.sqlite.Graph(db=L.helper) >>> sorted(M) ['bar', 'foo'] >>> M.helper.dbpath is None True ``` -------------------------------- ### Get Nodes with Data (NetworkX) Source: https://networkdisk.inria.fr/references/introduction Shows how to retrieve nodes along with their associated data attributes. This includes accessing the entire data dictionary or specific attributes, with options for default values. ```Python >>> G.add_node(1, time="5pm") >>> G.nodes[0]["foo"] = "bar" >>> list(G.nodes(data=True)) [(0, {'foo': 'bar'}), (1, {'time': '5pm'}), (2, {})] >>> list(G.nodes.data()) [(0, {'foo': 'bar'}), (1, {'time': '5pm'}), (2, {})] ``` -------------------------------- ### Get Graph Edges with Data Source: https://networkdisk.inria.fr/references/introduction Demonstrates how to retrieve edges from a NetworkX graph, including their associated data. It shows how to access edge attributes and provide default values when attributes are missing. ```Python >>> G = nx.path_graph(3) # or MultiGraph, etc >>> G.add_edge(2, 3, weight=5) >>> [e for e in G.edges] [(0, 1), (1, 2), (2, 3)] >>> G.edges.data() # default data is {} (empty dict) EdgeDataView([(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})]) >>> G.edges.data("weight", default=1) EdgeDataView([(0, 1, 1), (1, 2, 1), (2, 3, 5)]) >>> G.edges([0, 3]) # only edges from these nodes EdgeDataView([(0, 1), (3, 2)]) >>> G.edges(0) # only edges from node 0 EdgeDataView([(0, 1)]) ``` -------------------------------- ### Python: Constructing SELECT queries Source: https://networkdisk.inria.fr/references/querybuilder/index Demonstrates how to construct SELECT queries on a SQL schema using the networkdisk library. It shows basic selection, selecting specific columns, and adding WHERE clauses with various conditions. ```Python >>> fooTable.select_query() SelectQuery >>> fooTable.select_query(condition=ageC.eq(18)) SelectQuery ? AND age < ?> >>> JQ= fooTable.inner_join_query(barTable, (idC, fidC)) >>> JQ.select_query(columns=("name", "msg")), SelectQuery >>> list(helper.execute(fooTable.select_query(columns=("name",), condition=fooTable["age"].gt(42)))) [('Jane Doe',)] ``` -------------------------------- ### Get Node Degree Source: https://networkdisk.inria.fr/references/introduction Shows how to access the degree of nodes in a graph using the .degree property. It explains how to retrieve the degree for a single node or multiple nodes, and how to use edge weights. ```Python >>> G = nx.path_graph(4) >>> G.degree[0] 1 >>> list(G.degree([0, 1, 2])) [(0, 1), (1, 2), (2, 2)] ``` -------------------------------- ### Create Abstract Schema and Tables Source: https://networkdisk.inria.fr/_sources/references/querybuilder/index Demonstrates building an abstract relational schema, adding tables with columns, defining primary keys, SQL types, and constraints. It shows how to represent table signatures and generate CREATE TABLE queries. ```Python Schema = dialect.schema.Schema() fooTable = Schema.add_table("foo") idC = fooTable.add_column("id", primarykey=True, sqltype="INT") nameC = fooTable.add_column("name", sqltype="TEXT") ageC = fooTable.add_column("age", sqltype="INT") print(fooTable.create_query()) ``` -------------------------------- ### Get Node Degree in DiGraph Source: https://networkdisk.inria.fr/references/introduction Demonstrates how to retrieve the degree of nodes in a DiGraph. The degree is the number of edges connected to a node. This can be calculated for a single node or multiple nodes, with an option to consider edge weights. ```Python >>> G = nx.DiGraph() >>> nx.add_path(G, [0, 1, 2, 3]) >>> G.degree(0) 1 >>> list(G.degree([0, 1, 2])) [(0, 1), (1, 2), (2, 2)] ``` -------------------------------- ### Node Insertion with Data (Reiterable - Python) Source: https://networkdisk.inria.fr/tutorials/introduction Demonstrates inserting nodes with data using a reiterable object. This optimized approach allows for a single pass to insert both nodes and their data efficiently. ```Python >>> G.add_nodes_from(list((i, {"foo":"bar") for i in range(2))) ``` -------------------------------- ### SQL Trace for Adding a Node (SQL) Source: https://networkdisk.inria.fr/tutorials/introduction Illustrates the SQL operations performed when adding a single node to the NetworkDisk graph. It shows the queries for checking existence, deleting, and inserting the node. ```SQL BEGIN TRANSACTION SELECT COUNT(?) FROM nodes1 WHERE name = ? LIMIT 1 --- \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x ``` -------------------------------- ### Sequential Node Insertion Transactions (SQL) Source: https://networkdisk.inria.fr/tutorials/introduction Shows the SQL transactions generated by the sequential node insertion method. Each transaction includes a SELECT, DELETE, and INSERT statement for a single node, demonstrating the overhead. ```SQL BEGIN TRANSACTION SELECT COUNT(?) FROM nodes1 WHERE name = ? LIMIT 1 --- ↖ (1, '"new_node_0"') DELETE FROM nodes1 WHERE name = ? --- ↖ ('"new_node_0"',) … ('"new_node_0"',) INSERT INTO nodes1(name) VALUES (?) --- ↖ ('"new_node_0"',) COMMIT TRANSACTION BEGIN TRANSACTION SELECT COUNT(?) FROM nodes1 WHERE name = ? LIMIT 1 --- ↖ (1, '"new_node_1"') DELETE FROM nodes1 WHERE name = ? --- ↖ ('"new_node_1"',) … ('"new_node_1"',) INSERT INTO nodes1(name) VALUES (?) --- ↖ ('"new_node_1"',) COMMIT TRANSACTION BEGIN TRANSACTION SELECT COUNT(?) FROM nodes1 WHERE name = ? LIMIT 1 --- ↖ (1, '"new_node_2"') DELETE FROM nodes1 WHERE name = ? --- ↖ ('"new_node_2"',) … ('"new_node_2"',) INSERT INTO nodes1(name) VALUES (?) --- ↖ ('"new_node_2"',) COMMIT TRANSACTION ``` -------------------------------- ### Create and Populate Graph with NetworkDisk Source: https://networkdisk.inria.fr/tutorials/transforming Demonstrates how to create a new graph using NetworkDisk's SQLite backend and add nodes with properties and edges. This is a foundational step for subsequent graph manipulations. ```Python >>> G = nd.sqlite.Graph(db="/tmp/nd.db", name="nodes_ex") >>> G.add_nodes_from([(i, {"parity": i%2}) for i in range(100)]) >>> G.add_edges_from([(randint(0, 99), randint(0, 99)) for _ in range(1000)]) ``` -------------------------------- ### Get Out-Degree of Nodes in a DiGraph Source: https://networkdisk.inria.fr/references/introduction Demonstrates how to retrieve the out-degree for single or multiple nodes in a NetworkX DiGraph. The out-degree is the number of edges pointing out of a node. It supports weighted degrees using an optional 'weight' parameter. ```Python >>> G = nx.DiGraph() >>> nx.add_path(G, [0, 1, 2, 3]) >>> G.out_degree(0) # node 0 with degree 1 1 >>> list(G.out_degree([0, 1, 2])) [(0, 1), (1, 1), (2, 1)] ``` -------------------------------- ### Initialize Graph with SQLite DB Connector Source: https://networkdisk.inria.fr/tutorials/introduction Initializes a NetworkDisk Graph by directly providing an existing `sqlite3.connect` database object. The graph loses direct access to the DB file path. ```Python >>> import sqlite3 >>> db = sqlite3.connect("/tmp/mydb.db") >>> L = nd.sqlite.Graph(db=db) >>> sorted(L) ['bar', 'foo'] >>> L.helper.dbpath is None True ``` -------------------------------- ### Basic Column and Query Construction - Python Source: https://networkdisk.inria.fr/references/querybuilder/index Demonstrates the creation of a basic column value and an addition operation, followed by constructing a simple SELECT query using the SQL dialect. ```Python c = dialect.columns.ValueColumn(1) c2 = dialect.columns.AddColumn(c, c) print(dialect.queries.SelectQuery(columns=c2)) # Output: SelectQuery