use of org.neo4j.graphdb.traversal.Evaluator in project neo4j by neo4j.
the class TraversalDescriptionBuilder method describePruneEvaluator.
@SuppressWarnings("unchecked")
private TraversalDescription describePruneEvaluator(TraversalDescription result, Map<String, Object> description) {
Object pruneDescription = description.get("prune_evaluator");
if (pruneDescription != null) {
Evaluator pruner = evaluatorFactory.pruneEvaluator((Map) pruneDescription);
if (pruner != null) {
result = result.evaluator(pruner);
}
}
Object maxDepth = description.get("max_depth");
maxDepth = maxDepth != null || pruneDescription != null ? maxDepth : 1;
if (maxDepth != null) {
result = result.evaluator(Evaluators.toDepth(((Number) maxDepth).intValue()));
}
return result;
}
use of org.neo4j.graphdb.traversal.Evaluator in project graphdb by neo4j-attic.
the class MultiEvaluator method evaluate.
public Evaluation evaluate(Path position) {
boolean includes = true;
boolean continues = true;
for (Evaluator evaluator : this.evaluators) {
Evaluation bla = evaluator.evaluate(position);
if (!bla.includes()) {
includes = false;
}
if (!bla.continues()) {
continues = false;
}
if (!continues && !includes) {
return Evaluation.EXCLUDE_AND_PRUNE;
}
}
return Evaluation.of(includes, continues);
}
use of org.neo4j.graphdb.traversal.Evaluator in project neo4j by neo4j.
the class StandardBranchCollisionDetectorTest method testFilteredPathEvaluation.
@Test
public void testFilteredPathEvaluation() {
final PropertyContainer endNode = mock(Node.class);
final PropertyContainer alternativeEndNode = mock(Node.class);
final Node startNode = mock(Node.class);
Evaluator evaluator = mock(Evaluator.class);
TraversalBranch branch = mock(TraversalBranch.class);
TraversalBranch alternativeBranch = mock(TraversalBranch.class);
when(branch.iterator()).thenAnswer(new IteratorAnswer(endNode));
when(alternativeBranch.iterator()).thenAnswer(new IteratorAnswer(alternativeEndNode));
when(alternativeBranch.startNode()).thenReturn(startNode);
when(evaluator.evaluate(Mockito.any(Path.class))).thenReturn(Evaluation.INCLUDE_AND_CONTINUE);
StandardBranchCollisionDetector collisionDetector = new StandardBranchCollisionDetector(evaluator, path -> alternativeEndNode.equals(path.endNode()) && startNode.equals(path.startNode()));
Collection<Path> incoming = collisionDetector.evaluate(branch, Direction.INCOMING);
Collection<Path> outgoing = collisionDetector.evaluate(branch, Direction.OUTGOING);
Collection<Path> alternativeIncoming = collisionDetector.evaluate(alternativeBranch, Direction.INCOMING);
Collection<Path> alternativeOutgoing = collisionDetector.evaluate(alternativeBranch, Direction.OUTGOING);
assertNull(incoming);
assertNull(outgoing);
assertNull(alternativeIncoming);
assertEquals(1, alternativeOutgoing.size());
}
use of org.neo4j.graphdb.traversal.Evaluator in project neo4j-mobile-android by neo4j-contrib.
the class MultiEvaluator method evaluate.
public Evaluation evaluate(Path position) {
boolean includes = true;
boolean continues = true;
for (Evaluator evaluator : this.evaluators) {
Evaluation bla = evaluator.evaluate(position);
if (!bla.includes()) {
includes = false;
}
if (!bla.continues()) {
continues = false;
}
if (!continues && !includes) {
return Evaluation.EXCLUDE_AND_PRUNE;
}
}
return Evaluation.of(includes, continues);
}
use of org.neo4j.graphdb.traversal.Evaluator in project graphdb by neo4j-attic.
the class TestMultipleFilters method testNarrowingFilters.
@Test
public void testNarrowingFilters() {
Evaluator mustBeConnectedToK = new MustBeConnectedToNodeFilter(getNodeWithName("k"));
Evaluator mustNotHaveMoreThanTwoOutRels = new Evaluator() {
public Evaluation evaluate(Path path) {
return Evaluation.ofIncludes(IteratorUtil.count(path.endNode().getRelationships(Direction.OUTGOING)) <= 2);
}
};
TraversalDescription description = Traversal.description().evaluator(mustBeConnectedToK);
expectNodes(description.traverse(referenceNode()), "b", "c");
expectNodes(description.evaluator(mustNotHaveMoreThanTwoOutRels).traverse(referenceNode()), "c");
}
Aggregations