Database Reference
In-Depth Information
public static void main(..) : This main method is the entry point of
the traversals and defines the flow of code
private Node getStartNode() : This executes the Cypher query and
gets the node which is used as a starting point for our traversals
private void startTraversing() : This is the core part of the code that
defines the Traversals, rules, and iterates over the paths
Let's deep dive and understand the logic of the startTraversing() method.
TraversalDescription trvDesc =
graphDb.traversalDescription();
The preceding line of code fetches an instance of TraversalDescription from an
instance of the graph database with all its default values. TraversalDescription
defines the behavior of traversals and provides various methods for defining rules that are
further used while traversing graphs. There are two types of traversals: TraversalDe-
scription and BidirectionalTraversalDescription . Both traversals can
be retrieved from the object of graphDb .
trvDesc = trvDesc.depthFirst();
trvDesc =
trvDesc.evaluator(Evaluators.excludeStartPosition());
trvDesc = trvDesc.evaluator(Evaluators.toDepth(3));
The preceding statements define the three most common rules that are followed while do-
ing the traversals:
depthFirst : This is rule 1, where the traversals should be evaluating the depth
of the tree. You can also define breadthFirst for evaluating the breadth of
the tree.
excludeStartPosition : This is rule 2 that excludes the starting node and
does not evaluate any paths that are originating and ending from the starting point
itself.
toDepth(3) : This is rule 3, which defines the number of paths it should evalu-
ate from the starting node. If nothing is specified, then it will evaluate all paths
from the start node, that is, it will evaluate the complete graph.
Search WWH ::




Custom Search