Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-18 Thread Jim Webber
Hi Peter,

> Jim: I don't suppose you know if/when the REST API will support these
> complex traversals (or END_OF_GRAPH queries)? This unfortunately makes Neo4j
> a no-go for our project until then.

The REST API does support some complex traversals, but it's not totally 
equivalent to the either of the Java traverser APIs.

I think Peter Neubauer could be right here - if you don't want to write Java, 
then writing Gremlin or Cypher is a good way to go.

Jim
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-18 Thread Peter Neubauer
Peter,
there is no concept of END_OF_GRAPH in Neo4j or Gremlin. It is merely
the concept of not including a depth-related component into the stop
condition of a traversal. So, your query could maybe be something like

g.v(%d).out('JOURNEY').loop(1){it.object.getProperty('stop_id') !=
'%d'}.out('HOP').paths

Note the shorter notation of steps that simply filter by direction and
label of the edges. Does this work? Also, you might need to take into
account that the stop_id might not be present on some nodes in your
closure?


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://startupbootcamp.org/    - Öresund - Innovation happens HERE.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.



On Thu, Aug 18, 2011 at 4:17 PM, picklepete  wrote:
> Hey Peter,
>
> Thanks for the quick reply. I actually started work on my migration using
> Gremlin, my original query looks like this:
>
> g.v(%d).outE{it.label=='JOURNEY'}.inV.loop(3){it.loops < 5 &
> it.object.getProperty('stop_id') != '%d'}.outE{it.label=='HOP'}.inV.paths
>
> I would be querying on one of the black (selected) nodes here:
> http://cl.ly/9O22. Basically going from one node and looping until I reach a
> node with a property called 'stop_id' and its value matching my criteria.
> Unfortunately I couldn't figure out how to make the query loop until it
> matched the node, I had to specify a 'it.loops'.
>
> Is there an equivalent END_OF_GRAPH filter in Gremlin?
>
> Cheers,
> - Peter
>
> --
> View this message in context: 
> http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3265011.html
> Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-18 Thread picklepete
Hey Peter,

Thanks for the quick reply. I actually started work on my migration using
Gremlin, my original query looks like this:

g.v(%d).outE{it.label=='JOURNEY'}.inV.loop(3){it.loops < 5 &
it.object.getProperty('stop_id') != '%d'}.outE{it.label=='HOP'}.inV.paths

I would be querying on one of the black (selected) nodes here:
http://cl.ly/9O22. Basically going from one node and looping until I reach a
node with a property called 'stop_id' and its value matching my criteria.
Unfortunately I couldn't figure out how to make the query loop until it
matched the node, I had to specify a 'it.loops'.

Is there an equivalent END_OF_GRAPH filter in Gremlin?

Cheers,
- Peter

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3265011.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-18 Thread Peter Neubauer
Hi Peter,
using Gremlin or Cypher, you can do more complicated traversals even
with the Neo4j Server, see
http://docs.neo4j.org/chunked/snapshot/cypher-plugin.html and
http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html . While
Cypher support for variable length pathes is coming, in Gremlin, using
Groovy as the underlying scripting engine, you can loop:

g.v(1).out('RELATES_TO').loop(1){true}

where TRUE is the condition for the loop pipe going back to the out
step always is TRUE. See even
https://github.com/tinkerpop/gremlin/wiki/Gremlin-Steps for more
goodies.


Have not tried this with an example graph, let me know if this works.

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://startupbootcamp.org/    - Öresund - Innovation happens HERE.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.



On Thu, Aug 18, 2011 at 3:52 PM, picklepete  wrote:
> Hey Paddy,
>
> Thanks for the inspiration, I had a scour through the source and website,
> the speed in which you can traverse the graph is incredible!
>
> Jim: I don't suppose you know if/when the REST API will support these
> complex traversals (or END_OF_GRAPH queries)? This unfortunately makes Neo4j
> a no-go for our project until then.
>
> Cheers,
> - Peter
>
> --
> View this message in context: 
> http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3264937.html
> Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-18 Thread picklepete
Hey Paddy,

Thanks for the inspiration, I had a scour through the source and website,
the speed in which you can traverse the graph is incredible!

Jim: I don't suppose you know if/when the REST API will support these
complex traversals (or END_OF_GRAPH queries)? This unfortunately makes Neo4j
a no-go for our project until then.

Cheers,
- Peter

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3264937.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread Patrick Fitzgerald
Hi Peter,
You might find my journey planner project on github helpful, it uses Neo4j &
Google Maps: http://www.github.com/whichway/transportdublin
 It's coded in Java but
hopefully you could get some ideas from it.

Cheers
Paddy



On Wed, Aug 17, 2011 at 11:30 AM, picklepete wrote:

> Hey Jim,
>
> I am unfortunately unable to code in Java (Python/PHP dev), would the best
> alternative be to use the 'old' traversal core via the REST API to reach
> the
> END_OF_GRAPH, and perhaps cherry-pick my results afterwards (instead of
> your
> prune/exclude evaluators)?
>
> In most of my queries I am going to need to traverse using a relationship
> called 'JOURNEY' and filter only the journeys with a certain value of
> property 'route' (individual bus routes). Is it possible to tell a
> traversal
> to follow 'JOURNEY' and those with a certain property?
>
> This schema made the most sense when it came to designing my domain as I
> would need (journeys * routes) relationships otherwise. This way I only
> have
> relationships for journeys and each tracks its own route, there are about 1
> million of them at present.
>
> Currently cloning your (rather large!) neo4j-tutorial on Github.
>
> Cheers,
> - Peter
>
> --
> View this message in context:
> http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3262514.html
> Sent from the Neo4j Community Discussions mailing list archive at
> Nabble.com.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread picklepete
Hey Jim,

I am unfortunately unable to code in Java (Python/PHP dev), would the best
alternative be to use the 'old' traversal core via the REST API to reach the
END_OF_GRAPH, and perhaps cherry-pick my results afterwards (instead of your
prune/exclude evaluators)? 

In most of my queries I am going to need to traverse using a relationship
called 'JOURNEY' and filter only the journeys with a certain value of
property 'route' (individual bus routes). Is it possible to tell a traversal
to follow 'JOURNEY' and those with a certain property?

This schema made the most sense when it came to designing my domain as I
would need (journeys * routes) relationships otherwise. This way I only have
relationships for journeys and each tracks its own route, there are about 1
million of them at present.

Currently cloning your (rather large!) neo4j-tutorial on Github.

Cheers,
- Peter

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3262514.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread Jim Webber
Hi Peter,

It's a bit confusing, but we have (at least) two traverser frameworks, both of 
which have been around since 1.x.

The core traverser API: in the org.neo4j.graphdb package
The "new" traverser API: in the org.neo4j.graphdb.traversal package

Have a look at the slideware in the neo4j tutorial here for examples: 
https://github.com/jimwebber/neo4j-tutorial

The REST API doesn't provide such rich access. If you're going to do 
super-badass traversals, then I'd write them in Java and expose them through 
the REST API as extensions (a bit like stored procs I guess):

Unmanaged (JAX-RS) extensions: 
http://docs.neo4j.org/chunked/snapshot/server-unmanaged-extensions.html
Server plugins: http://docs.neo4j.org/chunked/snapshot/server-plugins.html

Jim

PS - Please upgrade to 1.4.1. It's completely jar-compatible with 1.4 but 
better.


___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread picklepete
Hey Jim,

No problem on the forum link, it had me confused for a bit ;)

Thanks for the example, when you refer to the new Neo4j traverser, is this
in 1.4.1? I'm currently running 1.4 and some documentation code examples 
http://docs.neo4j.org/chunked/1.4/tutorials-java-embedded-traversal.html
still use END_OF_GRAPH .

Also, is this new evaluator accessible via the REST API? I'm using @jadell's
awesome  https://github.com/jadell/Neo4jPHP Neo4jPHP library  for this
project.

Cheers,
- Peter

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3262114.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread Jim Webber
Hi Peter,

[I'm sure the Greliministas will provide an answer too, but here's the native 
Neo4j APIs' take]

In the Neo4j simple traverser framework, you can set max depth to end of graph. 
But you constrain the types of relationships you allow the traverser to 
traverse. That way your traversals tend to end at nodes where there are no more 
relationships (that you've declared the traverser can traverse) to follow.


Edited from the Doctor Who Koans (https://github.com/jimwebber/neo4j-tutorial), 
E.g.

Traverser t = theDoctor.traverse(Order.DEPTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL_BUT_START_NODE,
DoctorWhoUniverseGenerator.COMPANION_OF,
Direction.INCOMING);

The new Neo4j traverser framework takes a different approach. It allows the 
writer to embed some logic which determines at each hop of a traversal whether 
the current node is to be included in the results, and whether or not to 
continue searching down the current subgraph, e.g.

Traverser traverser = Traversal.description()
  .relationships(DoctorWhoUniverseGenerator.PLAYED, Direction.INCOMING)
  .breadthFirst()
  .evaluator(new Evaluator() {
public Evaluation evaluate(Path path) {
  if 
(path.endNode().hasRelationship(DoctorWhoUniverseGenerator.REGENERATED_TO, 
Direction.BOTH)) {
return Evaluation.INCLUDE_AND_CONTINUE;
  } else {
return Evaluation.EXCLUDE_AND_PRUNE;
  }
  }
}).traverse(theDoctor);

You can see how you could adapt this to address your domain:

public Evaluation evaluate(Path path) {
  if (path.endNode().hasRelationship(RELATES_TO, Direction.BOTH)) {
return Evaluation.EXCLUDE_AND_CONTINUE;
  } else if (path.endNode().hasRelationship(RELATES_TO, Direction.INCOMING)) {
return Evaluation.EXCLUDE_AND_CONTINUE;
  } else {
return Evaluation.INCLUDE_AND_PRUNE;
  }
}

Hope that helps a bit, and thanks for the tweet about the forums (Anders 
registered a redirect).

Jim

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Depth and traversals in journey planner migration.

2011-08-17 Thread picklepete
Hello,

I am currently researching a migration from MySQL to Neo4j for a journey
planner my agency has built for a local bus operator. Due to scaling and
performance issues we are looking to migrate to a NoSQL (preferably
graph-based) solution.

Two of my tests so far, in Gremlin and using traversals have been
successful, but I'm running into some problems when it comes to performing
searches across many relationships. As far as I understand it, the 'depth'
parameter relates to how many nodes the traverser or path finder passes
before halting and returning the stops, relationships or both.

How would I go about querying a graph which contains the following data...

Start [A] -> RELATES_TO -> [B] -> RELATES_TO -> [C] -> RELATES_TO -> [D] End

... without specifying a depth? At the moment I am having to pass the exact
depth value (A -> B = 1, A->C = 2, etc) to actually get to my destination.

Any ideas on how this could be accomplished?

Thanks,
- Peter

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Depth-and-traversals-in-journey-planner-migration-tp3261892p3261892.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user