use of org.neo4j.graphdb.impl.StandardExpander in project neo4j by neo4j.
the class TestShortestPath method withFilters.
@Test
void withFilters() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d");
graph.makeEdgeChain(transaction, "a,g,h,d");
final Node a = graph.getNode(transaction, "a");
final Node d = graph.getNode(transaction, "d");
final Node b = graph.getNode(transaction, "b");
b.setProperty("skip", true);
var context = new BasicEvaluationContext(transaction, graphDb);
final Predicate<Node> filter = item -> {
final boolean skip = (Boolean) item.getProperty("skip", false);
return !skip;
};
testShortestPathFinder(context, finder -> assertPaths(finder.findAllPaths(a, d), "a,g,h,d"), ((StandardExpander) allTypesAndDirections()).addNodeFilter(filter), 10);
transaction.commit();
}
}
use of org.neo4j.graphdb.impl.StandardExpander in project neo4j by neo4j.
the class TestShortestPath method filtersTouchesAllIntermediateNodes.
@Test
void filtersTouchesAllIntermediateNodes() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d");
final Node a = graph.getNode(transaction, "a");
final Node d = graph.getNode(transaction, "d");
Collection<Node> touchedByFilter = new HashSet<>();
final Predicate<Node> filter = item -> {
touchedByFilter.add(item);
return true;
};
final PathExpander expander = PathExpanderBuilder.empty().add(R1, OUTGOING).addNodeFilter(filter).build();
// final PathExpander expander = ((StandardExpander) PathExpanders.forTypeAndDirection(R1, OUTGOING)).addNodeFilter( filter );
var context = new BasicEvaluationContext(transaction, graphDb);
Path path = Iterables.single(shortestPath(context, expander, 10).findAllPaths(a, d));
assertEquals(3, path.length());
List<Node> nodes = Iterables.asList(path.nodes());
List<Node> intermediateNodes = nodes.subList(1, nodes.size() - 1);
assertTrue(touchedByFilter.containsAll(intermediateNodes), "touchedByFilter: " + touchedByFilter);
assertFalse(touchedByFilter.contains(a));
assertFalse(touchedByFilter.contains(d));
transaction.commit();
}
}
Aggregations