01. Overview

Firstly, to enhance the capacity of the existing MASS-based graph database (DB) system (GraphPlaces and VertexPlace) in terms of handling graph datasets with various property information about nodes and relationships, we have re-engineered the existing system in accordance with the property graph model.

Secondly, to make the MASS-based graph database system capable to support a query language for creating, manipulating, and retrieving graph data, we have implemented a completion process to integrate Cypher with the MASS-based graph DB system.

The code for the enhanced MASS-based graph DB system is in mass_java_appl/QueryGraphDB branch and mass_java_core/QueryGraphDB branch. For more information of the files and folders added and/or amended in this project, please refer to mass_java_app/QueryGraphDB branch/QueryGraphDB/README.me.

02. Overall Design

01.png

This is to illustrate the entire design and implementation of the whole project. It follows a three-tier architecture pattern, with presentation layer, logic layer and data access layer.

03. An example of main program

Screenshot 2024-05-24 at 11.01.45 AM.png

This is an example of a main program that interacts with the GraphManager class to manage a MASS-based graph database and execute Cypher queries. It follows the process as listed below:

  1. Initialize a GraphManager instance.

  2. Call GraphManager’s start() method to start MASS system.

  3. Call GraphManager’s buildGraph() methods to build a graph, either an empty one or from csv files.

  4. Users can call GraphManager’s printGraph() to visualize the graph DB built in MASS system.

  5. Users can query the system by calling GraphManager’s queryHandler() method.

  6. Users can quit the system by typing “Exit” in terminal.

04. GraphManager class

The GraphManager class is responsible for managing a property graph using the MASS components. It includes methods for initializing and shutting down the MASS library, building graphs from CSV files, and handling queries. Below is a detailed documentation of the class and its methods.

Private Members

Constructor

Public Methods

05. PropertyGraphPlaces class and PropertyVertexPlace class

To enhance the functionality of the existing system in accordance with the property graph model, a new PropertyGraphPlaces class and a new PropertyVertexPlace class are designed to manage graph DB system and store graph data with nodes and edges containing property information.

PropertyGraphPlaces extends from GraphPlaces and contains a list of PropertyVertexPlace, which further extends from VertexPlace.

02.png

PropertyGraphPlaces class

The PropertyGraphPlaces class serves as a crucial component for managing the property graph DB within the MASS Java framework. This class is designed to facilitate the creation, manipulation, and analysis of property graphs, composed of individual vertices represented by PropertyVertexPlace instances.

Key public methods

  1. int addPropertyVertex(Object itemID_Original, List labels, Map<String, String> properties)

    This method allows for the addition of new vertices to the graph. Upon invocation, addPropertyVertex() method creates a new PropertyVertexPlace instance with the specified attributes and adds it to the graph.

    Parameters:

    Returns int: An integer represents the MASS internal ID for the vertex.

  2. boolean setRelationEdge(Object fromItemID_Ori, Object toItemID_Ori, List relationTypes, Map<String, String> relationProperties)

    This method enables the creation of edges between two vertices, specifying the type of relationship and any associated properties.

    Parameters:

    Returns boolean: ‘true’ if the relationship edge is added to the graph database successfully, and ‘false’ otherwise.

  3. PropertyGraphModel getPropertyGraph()

    This method returns a representation of the entire property graph, including details about each vertex and its associated properties and relationships. This functionality enables users to inspect the graph’s structure and content, facilitating tasks such as debugging, validation, or visualization.

    Returns PropertyGraphModel: The model representing the entire property graph.

PropertyVertexPlace class

The PropertyVertexPlace class is designed to represent nodes or edges in a graph structure in accordance with the property graph model.

Below are the key attributes of the PropertyVertexPlace class: * ‘ItemID’: This attribute stores a unique ID for each node or vertex within the graph. * ‘labels’: Represented as a set, this attribute captures the descriptive tags for categorizing the node or vertex. * ‘nodeProperties’: A map structure utilized to store the properties associated with the node or vertex, facilitating the storage of key-value pairs denoting various attributes. * ‘toRelationship’ and ‘fromRelationship’: These maps are employed to record relationship information related to both outgoing and incoming connections of the node or vertex. They store relationship details including neighborID, and the types and properties of respective relationships. * ‘nextVertex’: This list contains the vertex IDs of nodes where an Agent is expected to spawn and subsequently migrate to.

05.png

06. Cypher Integration

Cypher compilation process

04.png

The Cypher compilation process begins with the input of a Cypher query text, which specifies the query clause with patterns to be performed on the graph data. Once the Cypher query is received, it undergoes parsing into a parse-tree, a hierarchical representation of its syntactic structure, and then being translated into an Abstract Syntax Tree (AST), which captures the essential semantic structure of the parse-tree. Upon the construction of AST, it is transformed into an execution plan, which is essentially a tree of execution steps required to fulfill the query efficiently. Once the execution plan is generated, it is executed against the agent-based property graph DB and the results of the query execution are retrieved.

Cypher clauses implemented

Currently, compilation of Cypher CREATE and MATCH clauses have been completed. To execute these two clauses, users need to call GraphManager’s queryHandler() method with query clause as input parameter.

  1. Cypher CREATE clause examples

  2. Cypher MATCH clause examples