Help Matching Where Patterns Intersect

(Usuallycwdillon) #1

I have a graph with events on a timeline and participants in events. I want to do some queries for statistics about how regularly participants attend, given that the events are irregularly spaced along the timeline.

Simplified: (:Person)-[:ATTENDS]->(:Event) and (:Event)-[:OCCURS]->(:Week) along with a time-tree of weeks (:Week)-[:NEXT_WEEK]-(:Week).

How can I isolate the weeks when an event occurs so that I can count the weeks between events?

For example, if I query MATCH p=( (:Event)-[:OCCURS]->(w:Week) ) WITH p MATCH (w)-[nw:NEXT_WEEK*]->(ww:Week)-[:OCCURS]-(:Event) RETURN length(nw) ORDER BY w the browser spins interminably. ...actually, I don't even get a response when I prepend it with PROFILE.

(Usuallycwdillon) #2

I got a little closer with this query, but now it's giving me too every combination of distances between events.

MATCH (:Event)-[:OCCURS]->(w:Week) WITH DISTINCT w ORDER BY w.weekNumber WITH COLLECT(w.weekNumber) AS weeks
UNWIND weeks as wk
MATCH (p:Person)-[:ATTENDS]->(e:Event)-[:OCCURS]-(w:Week{weekNumber:wk})-[nw:NEXT_WEEK*]->(ww:Week)-[:OCCURS]-(ee:Event)-[:ATTENDS]-(pp:Person)
RETURN p, e, w, length(nw), ww, ee, pp

It looks like I'm getting the weeks between every combination of events instead of the number of weeks until the next event.

(Michael Hunger) #3

Not 100% sure what you want to do. Do you want to get the spacing between particualar events? Or all events ( Events^2 ) ?

I would use shortestPath() for your var-length path.

MATCH (p:Person {id:$personId)-[:ATTENDS]->(e1:Event)-[:OCCURS]->(w1:Week),
WHERE w1.week < w2.week
RETURN e1, e2, length(shortestPath( (w1)-[:NEXT*]->(w2) ) as distance