Thanks Peter. That was very useful. I am trying to get the path A ->B->C->D-> E in the below graph, with the following inputs Start Node: A, Relationships: REL1, REL4, REL2 (that is, order is not known) Relationship Property: relProp= "abc" in REL3
I was not able to define an evaluator which takes the combination of relationship types(without regard to order) and relationship properties to return the desired path. Can it be achievable in the current traversal framework? REL1 REL2 REL8 A ---------> X ---------> Y -----------> Z REL1 REL2 REL3 REL4 A ---------> B ---------> C -----------> D ---------> E REL1 REL3 REL9 REL10 A ---------> P ---------> Q -----------> R ---------> E As always, appreciate your guidance. ======================================================= John, if the order of the relationships doesn't matter, you could do something like this with the Traversal API (holding an ordered Path to test against in your Evaluator): public void testPath() { final ArrayList<RelationshipType> orderedPath = new ArrayList<RelationshipType>(); orderedPath.add( withName( "REL1" ) ); orderedPath.add( withName( "REL2" ) ); orderedPath.add( withName( "REL3" ) ); orderedPath.add( withName( "REL4" ) ); TraversalDescription td = Traversal.description().evaluator( new Evaluator() { public Evaluation evaluate( Path path ) { if ( path.length() == 0 ) { return Evaluation.EXCLUDE_AND_CONTINUE; } String currentName= path.lastRelationship().getType().name(); String relationshipType = orderedPath.get( path.length() - 1 ).name(); if ( path.length() == orderedPath.size() ) { if ( currentName.equals( relationshipType ) ) { return Evaluation.INCLUDE_AND_PRUNE; } else { return Evaluation.EXCLUDE_AND_PRUNE; } } else { if ( currentName.equals( relationshipType ) ) { return Evaluation.EXCLUDE_AND_CONTINUE; } else { return Evaluation.EXCLUDE_AND_PRUNE; } } } } ); Traverser t = td.traverse( getNodeWithName( "A" ) ); for ( Path path : t ) { System.out.println(path); } } I am attaching the classes for your reference, so you have full code. Also, you could try JRuby, Gremlin or other along the same lines. But this is a basic Java example in creating an ordered Path information and checking against it during the traversal. You can add in more stuff of course ... Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - Your high performance graph database. http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party. On Tue, Jan 25, 2011 at 10:59 PM, John Howard <johnyhowdy at gmail.com> wrote: > Hello, > > We are trying to use neo4j graph database in one of our applications. > I think we hit a roadblock with traversal framework. It could be due to our > limited knowledge of neo4j framework. > > Here is what we are trying to accomplish: > We need to get a path(from the graph below) from the nodes A to E through > relations REL1, REL2, REL3 & REL4. > All we know before the traversal is: Node A, REL1, REL2, REL3, > REL4..(sometime we even know the end node E) > So how can we get the path A to E? I can't seem to achieve it using > evaluator and/or relationships in TraversalDescription. It always returns me > nodes X, P,Q since they have one my relationships(REL1, REL3). > > > REL1 REL2 REL8 > A ---------> X ---------> Y -----------> Z > > REL1 REL2 REL3 REL4 > A ---------> B ---------> C -----------> D ---------> E > > REL1 REL3 REL9 REL10 > A ---------> P ---------> Q -----------> R ---------> E > > > Nodes: A, B, C, D,E,X,Y,Z,P,Q,R, > Relations: REL1....REL10 > > > Thank you for your help. > > John > _______________________________________________ > Neo4j mailing list > User at lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > -------------- next part -------------- A non-text attachment was scrubbed... Name: gist.zip Type: application/zip Size: 5718 bytes Desc: not available Url : http://lists.neo4j.org/pipermail/user/attachments/20110126/f2e3cac5/attachment-0001.zip _______________________________________________ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user