use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class SpecificDepthTraversalTest method shouldGetSecondNodeWhenFromToIsTwoBreadthFirst.
@Test
public void shouldGetSecondNodeWhenFromToIsTwoBreadthFirst() {
TraversalDescription description = getGraphDb().traversalDescription().breadthFirst().evaluator(Evaluators.fromDepth(2)).evaluator(Evaluators.toDepth(2));
expectNodes(description.traverse(getNodeWithName("5")), "2");
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TestBidirectionalTraversal method multipleStartAndEndNodes.
@Test
public void multipleStartAndEndNodes() throws Exception {
/*
* (a)--\ -->(f)
* v /
* (b)-->(d)<--(e)-->(g)
* ^
* (c)--/
*/
createGraph("a TO d", "b TO d", "c TO d", "e TO d", "e TO f", "e TO g");
PathExpander<Void> expander = PathExpanderBuilder.<Void>empty().add(to).build();
TraversalDescription side = getGraphDb().traversalDescription().uniqueness(NODE_PATH).expand(expander);
expectPaths(getGraphDb().bidirectionalTraversalDescription().mirroredSides(side).traverse(asList(getNodeWithName("a"), getNodeWithName("b"), getNodeWithName("c")), asList(getNodeWithName("f"), getNodeWithName("g"))), "a,d,e,f", "a,d,e,g", "b,d,e,f", "b,d,e,g", "c,d,e,f", "c,d,e,g");
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TestMultipleFilters method testNarrowingFilters.
@Test
public void testNarrowingFilters() {
Evaluator mustBeConnectedToK = new MustBeConnectedToNodeFilter(getNodeWithName("k"));
Evaluator mustNotHaveMoreThanTwoOutRels = path -> Evaluation.ofIncludes(Iterables.count(path.endNode().getRelationships(Direction.OUTGOING)) <= 2);
TraversalDescription description = getGraphDb().traversalDescription().evaluator(mustBeConnectedToK);
expectNodes(description.traverse(node("a")), "b", "c");
expectNodes(description.evaluator(mustNotHaveMoreThanTwoOutRels).traverse(node("a")), "c");
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TraversalAStar method findPaths.
private Iterable<WeightedPath> findPaths(Node start, Node end, boolean multiplePaths) {
PathInterest interest;
if (multiplePaths) {
interest = stopAfterLowestWeight ? PathInterestFactory.allShortest() : PathInterestFactory.all();
} else {
interest = PathInterestFactory.single();
}
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription traversalDescription = db.traversalDescription().uniqueness(Uniqueness.NONE).expand(expander, initialState);
lastTraverser = traversalDescription.order(new SelectorFactory(end, interest)).evaluator(includeWhereEndNodeIs(end)).traverse(start);
return new Iterable<WeightedPath>() {
@Override
public Iterator<WeightedPath> iterator() {
return new WeightedPathIterator(lastTraverser.iterator(), costEvaluator, stopAfterLowestWeight);
}
};
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TraversalShortestPath method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription sideBase = db.traversalDescription().breadthFirst().uniqueness(NODE_PATH);
return db.bidirectionalTraversalDescription().mirroredSides(sideBase.expand(expander)).sideSelector(LEVEL_STOP_DESCENT_ON_RESULT, maxDepth).collisionEvaluator(toDepth(maxDepth)).traverse(start, end);
}
Aggregations