InfiniteGraph
InfiniteGraph Documentation

. Core API Manual
. Developer Wiki (install, getting started and examples)


Quick Start Example
A graph database consists of vertices (nodes) and edges (relationships). With these tools, InfiniteGraph can create a complex graph database. The navigation capability of InfiniteGraph can find the relationship between multiple nodes. In this example, we use the sample included with the InfiniteGraph installation to demonstrate how the API may be used to create a graph database.

 
The Person class extends BaseVertex. In addition to the placement of the common methods and attributes the Base Vertex is identified as a persistent capable class inside Infinite Graph.
class Person extends BaseVertex { ... };
The same is done for Edges by extending BaseEdge.
class MetWith extends BaseEdge { ... };
A GraphFactory provides a factory for creating new databases and subsequently retrieving them.
GraphFactory.create("SampleGraph", ".\\propertyFile\\SampleGraphProperties.properties"); myGraphDB = GraphFactory.open("SampleGraph", ".\\propertyFile\\SampleGraphProperties.properties");
In order to access the database for reading and or writing a transaction class is required:
tx = myGraphDB.beginTransaction(AccessMode.READ_WRITE);
Adding Vertices and Edges to the Graph Database is done with the following example:
Person suspect1 = new Person("Chopper Reid"); Person unknown1 = new Person("Nancy Smith"); MetWith meeting1 = new MetWith("Kings Cross"); myGraphDB.addVertex(suspect1); suspect1.addEdge(meeting1, unknown1, EdgeKind.BIDIRECTIONAL);
The direct retrieval of a Vertex from the database can be accomplished by using an index interface which is one of the many indexing techniques provided:
myGraphDB.nameVertex("suspect1", suspect1); Person retrievedSuspect1 = (Person)myGraphDB.getNamedVertex("suspect1");
The navigate engine is used to find a Vertex within a infinite amount of Vertexes and Edge possibilities by using customizable qualifiers on the path and on the result:
Navigator suspect1Navigator = suspect1.navigate(guide, pathQualifier, resultQualifier, navigationResultHandler);
This result qualifier will only filter out the path only if the end of the path is Bellatrix Lestrange.
class meetingWithBellatrix implements Qualifier { public boolean qualify(Path currentPath) { //this is a qualifying path if the last vertex of this path is Bellatrix Lestrange if ("Bellatrix Lestrange" == ((Person)(currentPath.getFinalHop().getVertex())).getName()) return true; else return false; } };
The pathQualifier sends resulting paths to resultQualifier; The resultQualifier sends resulting paths to the ResultHandler.
class PrintPathResultsHandler implements NavigationResultHandler { public void handleResultPath(Path result, Navigator navigator) { System.out.print("Found matching path : "); System.out.print(result.get(0).getVertex().toString()); // For h in p for(Hop h : result) { if(h.hasEdge()) { System.out.print("<->" + h.getVertex().toString()); } } } };
The instantiation of the result qualifier and the result handler is done as:
PrintPathResultsHandler resultPrinter = new PrintPathResultsHandler(); meetingWithBellatrix meetingWithBellatrix1 = new meetingWithBellatrix();
They are then passed into navigate() as part of the initialization of the navigator:
// Start a breadth first navigation from Chopper looking for this meeting Navigator suspect1Navigator = suspect1.navigate(Guide.SIMPLE_BREADTH_FIRST, Qualifier.ANY, meetingWithBellatrix1, resultPrinter);
To start the navigator, the method navigator.start() is used:
suspect1Navigator.start();
At the end of the sample, it deletes the database from the system. If you want to take a look of the database struct with Assist, comment out this line. At a later time you can delete the database by running oodeletefd SampleGraph.boot in the Sample directory.
//Delete the Database from the System GraphFactory.delete("SampleGraph", ".\\propertyFile\\SampleGraphProperties.properties");
Execute runSample.bat in the sample directory. It will compile and run the sample.
Result:
SM: adding new class to schema named Person as Person SM: adding new class to schema named MetWith as MetWith Found Tom Riddle Found matching path : Tom Riddle<->Nancy Smith<->Bellatrix Lestrange Sample Database removed