Package org.neo4j.graphdb.traversal

Examples of org.neo4j.graphdb.traversal.TraversalDescription


    public FriendsMovieRecommendations(int ratingDistance) {
        this.ratingDistance = ratingDistance;
    }

    public Map<Movie, ?> getRecommendationsFor(User user) {
        TraversalDescription traversal = Traversal.description().breadthFirst()
                .uniqueness(Uniqueness.NODE_GLOBAL).relationships(withName(User.FRIEND))
                .evaluator(Evaluators.toDepth(ratingDistance)).evaluator(Evaluators.excludeStartPosition());

        Iterable result = user.findAllPathsByTraversal(traversal);
        Iterable<EntityPath<User,User>> friends = (Iterable<EntityPath<User,User>>)result;
View Full Code Here


    public void testTraverseFromGroupToPeople() {
        Person p = persistedPerson("Michael", 35);
        Group group = persist(new Group());
        group.setName("dev");
        group.addPerson(p);
        final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons")).evaluator(Evaluators.excludeStartPosition());
        Iterable<Person> people = neo4jTemplate.<Person>traverse(group, Person.class, traversalDescription);
        final HashSet<Person> found = new HashSet<Person>();
        for (Person person : people) {
            found.add(person);
        }
View Full Code Here

    public void testTraverseFromGroupToPeoplePaths() {
        Person p = persistedPerson("Michael", 35);
        Group group = persist(new Group());
        group.setName("dev");
        group.addPerson(p);
        final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons"), Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
        Iterable<EntityPath<Group,Person>> paths = (Iterable<EntityPath<Group, Person>>) neo4jTemplate.<EntityPath<Group,Person>>traverse(group, EntityPath.class, traversalDescription);
        for (EntityPath<Group, Person> path : paths) {
            assertEquals(group, path.startEntity());
            assertEquals(p, path.endEntity());
            assertEquals(1,path.length());
View Full Code Here

        final GraphRepository<Person> finder = neo4jTemplate.repositoryFor(Person.class);
        Person p = persistedPerson("Michael", 35);
        Group group = persist(new Group());
        group.setName("dev");
        group.addPerson(p);
        final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons")).evaluator(Evaluators.excludeStartPosition());
        Iterable<Person> people = finder.findAllByTraversal(group, traversalDescription);
        final HashSet<Person> found = new HashSet<Person>();
        for (Person person : people) {
            found.add(person);
        }
View Full Code Here

    @SuppressWarnings("deprecation")
    @Test
    public void testTraverse() throws Exception {
        //final TraversalDescription description = Traversal.description().relationships(KNOWS).prune(Traversal.pruneAfterDepth(1)).filter(Traversal.returnAllButStartNode());
        final TraversalDescription description = Traversal.description().relationships(KNOWS).evaluator(Evaluators.toDepth(1)).evaluator(Evaluators.excludeStartPosition());
        assertSingleResult("node1",template.traverse(node0, description).to(String.class,new PathNodeNameMapper()));
    }
View Full Code Here

        template.exec(new GraphCallback.WithoutResult() {
            @Override
            public void doWithGraphWithoutResult(GraphDatabase graph) throws Exception {
        final Set<String> resultSet = new HashSet<String>();
            final TraversalDescription description = Traversal.description().relationships(HAS).evaluator(Evaluators.excludeStartPosition()).evaluator(Evaluators.toDepth(1));

            final Result<Path> result = template.traverse(family, description);
            result.handle(new Handler<Path>() {
                @Override
                public void handle(Path value) {
View Full Code Here

    @SuppressWarnings("deprecation")
    @Test
    @Transactional
    public void testTraverse() throws Exception {
        //final TraversalDescription description = Traversal.description().relationships(KNOWS).prune(Traversal.pruneAfterDepth(1)).filter(Traversal.returnAllButStartNode());
        final TraversalDescription description = Traversal.description().relationships(KNOWS).evaluator(Evaluators.toDepth(1)).evaluator(Evaluators.excludeStartPosition());
        assertSingleResult("node1", neo4jTemplate.traverse(node0, description).to(String.class, new PathNodeNameMapper()));
    }
View Full Code Here

        return paths.hasNext() ? paths.next() : null;
    }

    private Iterator<Path> paths( final Node start, final Node end )
    {
        TraversalDescription base = Traversal.description().uniqueness(
                Uniqueness.RELATIONSHIP_PATH ).order(
                new BranchOrderingPolicy()
                {
                    public BranchSelector create( TraversalBranch startSource )
                    {
                        return new LiteDepthFirstSelector( startSource,
                                startThreshold );
                    }
                } );
        final int firstHalf = onDepth / 2;
        Traverser startTraverser = base.prune(
                Traversal.pruneAfterDepth( firstHalf ) ).expand(
                expander ).filter( new Predicate<Path>()
        {
            public boolean accept( Path item )
            {
                return item.length() == firstHalf;
            }
        } ).traverse( start );
        final int secondHalf = onDepth - firstHalf;
        Traverser endTraverser = base.prune(
                Traversal.pruneAfterDepth( secondHalf ) ).expand(
                expander.reversed() ).filter( new Predicate<Path>()
        {
            public boolean accept( Path item )
            {
View Full Code Here

    @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 );
    }
View Full Code Here

             || relationshipTypesAndDirections.length == 0 )
        {
            throw new IllegalArgumentException();
        }
        TraverserImpl result = new TraverserImpl();
        TraversalDescription description = traversal( result, traversalOrder,
                stopEvaluator, returnableEvaluator );
        description = description.expand( toExpander( relationshipTypesAndDirections ) );
        result.iter = description.traverse( node ).iterator();
        return result;
    }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.traversal.TraversalDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.