Search in sources :

Example 6 with Evaluator

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;
}
Also used : Evaluator(org.neo4j.graphdb.traversal.Evaluator)

Example 7 with Evaluator

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);
}
Also used : Evaluation(org.neo4j.graphdb.traversal.Evaluation) Evaluator(org.neo4j.graphdb.traversal.Evaluator)

Example 8 with Evaluator

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());
}
Also used : Path(org.neo4j.graphdb.Path) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Node(org.neo4j.graphdb.Node) Evaluator(org.neo4j.graphdb.traversal.Evaluator) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) Test(org.junit.Test)

Example 9 with Evaluator

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);
}
Also used : Evaluation(org.neo4j.graphdb.traversal.Evaluation) Evaluator(org.neo4j.graphdb.traversal.Evaluator)

Example 10 with Evaluator

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");
}
Also used : Path(org.neo4j.graphdb.Path) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Evaluator(org.neo4j.graphdb.traversal.Evaluator) Test(org.junit.Test)

Aggregations

Evaluator (org.neo4j.graphdb.traversal.Evaluator)12 Path (org.neo4j.graphdb.Path)9 Test (org.junit.Test)8 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)6 Node (org.neo4j.graphdb.Node)4 Transaction (org.neo4j.graphdb.Transaction)4 Evaluation (org.neo4j.graphdb.traversal.Evaluation)4 HashSet (java.util.HashSet)2 Predicate (java.util.function.Predicate)2 Before (org.junit.Before)2 Direction (org.neo4j.graphdb.Direction)2 Relationship (org.neo4j.graphdb.Relationship)2 BranchCollisionPolicy (org.neo4j.graphdb.traversal.BranchCollisionPolicy)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2 Iterator (java.util.Iterator)1 MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 CostEvaluator (org.neo4j.graphalgo.CostEvaluator)1