I've made an "dirty" hack how a traversal (query) DSL could look like in Scala. I pushed the code to here<https://github.com/FaKod/neo4j-scala/blob/ScalaTraverserHack/examples/eu/fakod/examples/TheMatrixTraversalHack.scala> .
The "query" uses a collections of nodes (nodeMap is a HashMap mapping Strings to Node instances): val startNodes = nodeMap("Neo") :: nodeMap("Morpheus") :: nodeMap("Trinity") :: Nil The Traverser can be started by calling method start on this list of nodes: startNodes.start[Matrix](_.name.length > 3)(--("CODED_BY") -- ("KNOWS") -->) - start takes type parameters. In This case its the case class Matrix(defined by case class Matrix(name: String, profession: String)) used while creating the nodes (a neo4j-scala feature). - The Term (_.name.length > 3) is basically the returnable evaluator, which dereferences the name parameter of the Matrix instance and checks its length. - The Term (--("CODED_BY") -- ("KNOWS") -->) evaluates to the relationship type and direction array (as parameterlist to call method traverse) The return of the call is a List of Matrix instances. Its possible to use Scala collection API to apply operations on this. Like sorting: startNodes.start[Matrix](_.name.length > 3)(--("CODED_BY") -- ("KNOWS") -->) sortWith (_.name < _.name) The length of all names: startNodes.start[Matrix](_.name.length > 3)(--("KNOWS") -->).map(_.name).foldLeft(0)(_ + _.length) Append all names: startNodes.start[Matrix](_.name.length > 3)(--("CODED_BY") -- ("KNOWS") -->).map(_.name).foldLeft("")(_ + _) The Output of the Github examples here<https://github.com/FaKod/neo4j-scala/blob/ScalaTraverserHack/examples/eu/fakod/examples/TheMatrixTraversalHack.scala>is: Relations CODED_BY and KNOWS, sorted by name: List(Matrix(Agent Smith,Program), Matrix(Cypher,Hacker), Matrix(Morpheus,Hacker), Matrix(The Architect,Whatever), Matrix(Trinity,Hacker)) Relations KNOWS, length of all names: 32 Relations CODED_BY and KNOWS, all names appended: TrinityMorpheusCypherAgent SmithThe Architect This is really a hack. It should be possible to get rid most of the relation parentheses and to run the traverser multithreaded automatically for every node. I hope this is helpful :-) Christopher On Fri, Nov 18, 2011 at 3:16 PM, Christopher Schmidt < fakod...@googlemail.com> wrote: > Hi Andres, > > worries is the wrong term. I think a query language has its use case and > its absolutely necessary for Neo4j. It maps common use cases to a powerful > language. > > But using it programmatically is something different. Thats what I mean > with abstraction (in the sense of software development). It is a different > language, with a different semantic used in a compiled language (Java or > Scala); and this is not a natural fit. > > Do I have something in mind: No - no concrete examples. > But obviously the traverser api with return and stop evaluators is too > generic (together with the lack of common result list operations, like > sort, filter etc). > > In case of Scala it should be possible (using the powerful collection api) > to create a DSL for complex queries and aggregation of results (that is > able to support multi core processing as well, which is a important feature > imho). > > I will try to invest some time. Maybe I can get to an example... > > > > On Thu, Nov 17, 2011 at 2:44 PM, Andres Taylor < > andres.tay...@neotechnology.com> wrote: > >> On Thu, Nov 17, 2011 at 1:21 PM, Christopher Schmidt < >> fakod...@googlemail.com> wrote: >> >> > Cypher has some >> > similarities to SQL as a special query language. And to be honest, I >> think >> > using it programmatically will cause the same symtoms as SQL with >> respect >> > to runtime errors, type safety, abstraction etc. >> > >> >> I understand your worries about runtime errors and type safety. I'd love >> to >> know what you mean by "abstraction etc". Do you have any concrete examples >> in mind? >> >> Andrés >> _______________________________________________ >> Neo4j mailing list >> User@lists.neo4j.org >> https://lists.neo4j.org/mailman/listinfo/user >> > > > > -- > Christopher > twitter: @fakod > blog: http://blog.fakod.eu > > -- Christopher twitter: @fakod blog: http://blog.fakod.eu _______________________________________________ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user