/Sqlite3_QueryGraph

This is a Simple graph database in SQLite.

Primary LanguageJupyter Notebook

Sqlite3_QueryGraph

Task:

Given an image create a Directed Graph and Query it in a graph database.

image

On this try to query for :

A. All vertices you can reach in one step from A, D, E

B. All vertices you can reach in two steps from I

Dependencies:

  • SQLite3
  • Python3.7
  • Graphviz

Installation

Basic Functions

The database script provides convenience functions for atomic transactions to add, delete, connect, and search for nodes.

Any single node or path of nodes can also be depicted graphically by using the visualize function within the database script to generate dot files, which in turn can be converted to images with Graphviz.

Approach:

This is the Python implementation.

  1. Created a database object and initialized it by method initialize defined in database.py

Initialized object

  1. Created all the nodes given in an image.png i.e. A, B, C, D, E, F, G, H, I.

Node_Creation

  1. Connect all the created node as per the image.png

Node_Connections

  1. After connections, graph looks like this

Graph

  1. Created a function named as 'get_one_step_nodes' which uses 'get_connections_one_way' method from database.py to find all the connections of single node. 'get_one_step_nodes' takes any number of nodes as an argument and results one step connections from all the given nodes

Result for one step

  1. Created a function named as 'get_n_step_nodes' which uses 'get_one_step_nodes' method to find all the connections of single node recursively. 'get_n_step_nodes' takes two arguments 'a node' and 'number of steps to reach'

Result for n step

For full solution refer to notebook

source: https://github.com/dpapathanasiou/simple-graph