help with evaluator

31 views
Skip to first unread message

Javad Karabi

unread,
Jan 24, 2014, 4:21:58 PM1/24/14
to ne...@googlegroups.com
How would i use the traversal description to do the following?

MATCH me-[:preferred_store]->(:Store)<-[:preferred_store]-(:Member)-[:ordered]->(p:Product)

I assumed that the following worked:
       .relationships( DynamicRelationshipType.withName("preferred_store"), Direction.OUTGOING )
       .relationships( DynamicRelationshipType.withName("preferred_store"), Direction.INCOMING )
       .relationships( DynamicRelationshipType.withName("ordered"), Direction.OUTGOING )
       .relationships( DynamicRelationshipType.withName("product"), Direction.OUTGOING )

However, I am seeing that the order in which relationships() is executed does not make a difference, it just adds the relationships to a global list of allowed relationships for the description... how would i ensure that the traversal only goes from preferred store, to ordered, to the product?

Michael Hunger

unread,
Jan 24, 2014, 8:21:37 PM1/24/14
to ne...@googlegroups.com
I think you have to create a custom RelationshipExpander, that takes a list of pairs of type and direction and checks at the current path length for the correct combo to look for.

I think from a quick look that org.neo4j.kernel.OrderedByTypeExpander already does this btw. Please check.

new OrderedByTypeExpander(asList(Pair.of(DynamicRelationshipType.withName("preferred_store"), Direction.OUTGOING),Pair.of( DynamicRelationshipType.withName("preferred_store"), Direction.INCOMING), ....)

Michael


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Javad Karabi

unread,
Jan 25, 2014, 1:15:42 AM1/25/14
to ne...@googlegroups.com
the asList can not seem to be found... where is that provided?

Stefan Armbruster

unread,
Jan 25, 2014, 7:59:20 AM1/25/14
to ne...@googlegroups.com
Arrays.asList from the JDK,
http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#asList(T...)

2014/1/25 Javad Karabi <karab...@gmail.com>:

Javad Karabi

unread,
Jan 25, 2014, 1:13:48 PM1/25/14
to ne...@googlegroups.com
it does not seem to work for me

error: cannot find symbol
        asList(
        ^
  symbol:   method asList(Pair<Rels,Direction>)

Javad Karabi

unread,
Jan 25, 2014, 1:22:23 PM1/25/14
to ne...@googlegroups.com
scratch that, i forgot to import it...


You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/9JfW_RBLJF4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Javad Karabi

unread,
Jan 25, 2014, 1:26:49 PM1/25/14
to ne...@googlegroups.com
but now, i am seeing that it does traverse ()-[:preferred_store]->()<-[:preferred_store]-()
but, i am seeing that it _again_ traverses out via preferred_store:
(0)--[preferred_store,10]-->(11)<--[preferred_store,3517594]--(90746)--[preferred_store,3517600]-->(19758)

even though my expander looks as such:
      PathExpander e = (new org.neo4j.kernel.OrderedByTypeExpander())
            .add( Rels.preferred_store, Direction.OUTGOING )
            .add( Rels.preferred_store, Direction.INCOMING )
            .add( Rels.ordered, Direction.OUTGOING )
            ;

should this not match only ()-[:preferred_store]->()<-[:preferred_store]-()-[:ordered]->()
?

Max De Marzi Jr.

unread,
Jan 25, 2014, 5:55:32 PM1/25/14
to ne...@googlegroups.com

Use your own Array Expander:

           RelationshipType[][] orderedRelTypes = {
                    { Relations.FRIENDS, Relations.ENEMIES },
                    { Relations.LIKES },
                    { Relations.HATES}
            };
            Direction[] directions = {Direction.OUTGOING, Direction.INCOMING, Direction.INCOMING}  ;

            Traverser traverser = Traversal.description()
                    .depthFirst()
                    .expand(new ArrayExpander(directions,orderedRelTypes))
                    .evaluator(Evaluators.atDepth(3))
                    .uniqueness(Uniqueness.NONE)
                    .traverse(person);


public class ArrayExpander implements PathExpander {

    private Direction[] directions;
    private RelationshipType[][] types;

    public ArrayExpander(Direction[] directions, RelationshipType[][] types )
    {
        this.types = types;
        this.directions = directions;
    }

    public Iterable<Relationship> expand(Path path, BranchState state){
        return path.endNode().getRelationships(directions[path.length()],
                types[path.length()]);
    }

    public ArrayExpander reverse()
    {
        return new ArrayExpander(directions, types);
    }
}

Michael Hunger

unread,
Jan 26, 2014, 12:34:57 AM1/26/14
to ne...@googlegroups.com
Good point Max,

you're right the OrderedType expander doesn't really do that. Did you have a blog posted about that?

Michael
Reply all
Reply to author
Forward
0 new messages