Hi Marko,

While I am not claiming that a traverser in Scala would be as powerful as 
Gremlin, the combination of for comprehensions and traversals allows for a 
concise formulation of working with graphs in Neo4J.

In my previous post I already mentioned the use of for comprehensions which 
allows constructs like:

val startNode = //some means to obtain the startnode
for(
  rel1 <- startNode.getRelationships(OUTGOING)
  if(rel1.getProperty("bla0") == "bla1");
  node1 <- rel.getOtherNode(startNode)
  if(node1.getProperty("bla2") == "bla3");
  rel2 <- node1.getRelationships(OUTGOING)
  if(rel2.getProperty("bla4") == "bla5");
  node2 <- rel.getOtherNode(node1)

  if(node2.getProperty("bla6") == "bla7");

){
//do things with rel1, node1, rel2, node2
}

This is nothing more than a concise way of writing 4 nested loops, so not a 
genuine traversal, although a traversal can be part of a for comprehension. 
Being an Iterable, a traversal is a monadic operation and can be used in the 
composition of a for comprehension.

The traverer I am working on at the moment, has the following signature:

class Traverser(startNode: Node // startnode
                   , relationshipTypes: Set[(RelationshipType, Direction)] 
//Set of relationshiptype, direction pairs
                   , relationshipFilters: Set[Relationship => Boolean] // Set 
of functions from relationship to boolean 
                   , nodeFilters: Set[Node => Boolean]  //Set of functions from 
node to boolean
                   , depthExpression: Int => Boolean //Expression of traversal 
depth to boolean
                   , options: TraversalOption // ReturnStopnode(n) or ReturnAll 
or ReturnAllExceptStartNode
                   , mode: DepthFirst or BreadthFirst
)

Am thinking about adding subtraversals, but need to further work out the 
details on that. Another thing I am considering is a traverser using the 
metamodel. This doesn't necessarily increase the expressiveness of the 
traversal, but could make writing fine grained traversals easier. Anything  a 
metamodel based traverser can do, can be expressed in relationshipfilters and 
nodefilters, but allows for nicer organization of the code.

Kind regards,
Niels Hoogeveen

> From: okramma...@gmail.com
> To: user@lists.neo4j.org
> Date: Wed, 17 Mar 2010 21:59:27 -0600
> Subject: Re: [Neo] basic questions
> 
> Hi,
> 
> > The example I provided is in effect nothing but a couple of nested  
> > iterations, so nothing like a real traversal, but certainly  
> > comparable to the the java pipes or the Gremlin path expressions.
> >
> > I am working on a Scala based traverser, having higher order  
> > functions makes it possible to supply filter expressions to the  
> > traverser. The result of a traversal can then be used in a for  
> > comprehension to further navigate the results or to compose  
> > different traversals.
> 
> Can you talk about what the Scala-based traverser can express beyond  
> Gremlin? I ask this cause Gremlin provides Turing completeness in  
> function and path definitions. Thus it allows you to move through a  
> graph in an arbitrary manner----explicit adjacency, probability  
> distribution control, teleportations, path/function composition, etc.?  
> --- though Gremlin lacks i/o manipulations of a traverser (e.g. data  
> from a socket connection altering the traversal, file data, keyboard,  
> etc).
> 
> See http://markorodriguez.com/Lectures_files/cnls-gremlin-2010.pdf
> 
> Thanks,
> Marko.
> 
> _______________________________________________
> Neo mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
                                          
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to