Search in sources :

Example 26 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project graphdb by neo4j-attic.

the class SmallestGraphEverTest method testTraverseRelationshipsWithStartNodeNotIncluded.

@Test
@SuppressWarnings("deprecation")
public void testTraverseRelationshipsWithStartNodeNotIncluded() throws Exception {
    TraversalDescription traversal = Traversal.description().filter(Traversal.returnAllButStartNode());
    int count = 0;
    for (Relationship rel : traversal.traverse(referenceNode()).relationships()) {
        count++;
    }
    assertEquals(1, count);
}
Also used : Relationship(org.neo4j.graphdb.Relationship) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 27 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription 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)

Example 28 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.

the class TestMultiPruneEvaluators method testMaxDepthAndCustomPruneEvaluatorCombined.

@Test
public void testMaxDepthAndCustomPruneEvaluatorCombined() {
    Evaluator lessThanThreeRels = new Evaluator() {

        public Evaluation evaluate(Path path) {
            return count(path.endNode().getRelationships(Direction.OUTGOING).iterator()) < 3 ? Evaluation.INCLUDE_AND_PRUNE : Evaluation.INCLUDE_AND_CONTINUE;
        }
    };
    TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.all()).evaluator(toDepth(1)).evaluator(lessThanThreeRels);
    Set<String> expectedNodes = new HashSet<String>(asList("a", "b", "c", "d", "e"));
    try (Transaction tx = beginTx()) {
        for (Path position : description.traverse(node("a"))) {
            String name = (String) position.endNode().getProperty("name");
            assertTrue(name + " shouldn't have been returned", expectedNodes.remove(name));
        }
        tx.success();
    }
    assertTrue(expectedNodes.isEmpty());
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Evaluator(org.neo4j.graphdb.traversal.Evaluator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.

the class SmallestGraphEverTest method testTraverseRelationshipsWithStartNodeNotIncluded.

@Test
public void testTraverseRelationshipsWithStartNodeNotIncluded() throws Exception {
    try (Transaction transaction = beginTx()) {
        TraversalDescription traversal = getGraphDb().traversalDescription().evaluator(excludeStartPosition());
        assertEquals(1, Iterables.count(traversal.traverse(node("1")).relationships()));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 30 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.

the class SpecificDepthTraversalTest method shouldGetCorrectNodeAtDepthOne.

@Test
public void shouldGetCorrectNodeAtDepthOne() {
    TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.atDepth(1));
    expectNodes(description.traverse(getNodeWithName("6")), "5");
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Aggregations

TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)37 Test (org.junit.Test)20 Node (org.neo4j.graphdb.Node)12 Path (org.neo4j.graphdb.Path)12 Transaction (org.neo4j.graphdb.Transaction)7 Evaluator (org.neo4j.graphdb.traversal.Evaluator)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 HashMap (java.util.HashMap)3 WeightedPath (org.neo4j.graphalgo.WeightedPath)3 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)3 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)3 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)3 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Direction (org.neo4j.graphdb.Direction)2 PathExpander (org.neo4j.graphdb.PathExpander)2 Relationship (org.neo4j.graphdb.Relationship)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2