Alan
Robertson / CTO
Al...@AssimilationSystems.com / +1 303.947.7999
Assimilation Systems
Limited
http://AssimilationSystems.com
If I understand it correctly, this returns a single tuple with two elements:.... match path = shortestPath( (n)-[*]->(m) ) unwind nodes(path) as n with collect(distinct n) as nodes unwind rels(path) as r return collect(distinct r), nodes
I'll have to try this out!
I kind of wonder how this gets mapped into py2neo - what type are the tuple elements -- list(Relationship) and list(Node) or something like that...
Nigel?
I know my code won't currently handle this - but I can fix that
;-)
-- Alan
Hi,
Is there a way to specify a query which returns an intact subgraph?
For example:
starting from node "X" (by some specification), return the subgraph reachable through a collection of relationship types {T}, through some maximum distance (d), return a JSON representation of this subgraph - possibly with some WHERE specifications, but possibly not. In our nodes we include a nodetype in every node, we might want to say "WHERE node.nodetype IN {N}" as our where clause.
Result should be in some JSON graph format, perhaps like JSON Graph Format (JGF) http://jsongraphformat.info/ or https://github.com/bruth/json-graph-spec.
This is exactly what's needed for visualization of a subgraph from a Javascript program. Since Neo4j graphs are often huge, even monstrous, having a query that does this would be incredibly handy...
Otherwise you have to go through and put this graph together a piece at a time (or so it seems to me).
I think I can write a query which returns all the paths through this subgraph, but then I have to do the duplication elimination and so on myself. A single node might be returned many times in the possible paths result. Not an ideal situation...
This seems like a very common thing to want to do...
--
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/d/optout.
match path = shortestPath( (n)-[*]->(m) )
return collect(distinct unwind(nodes(path))), collect(distinct unwind(rels(path)))
Hi,
Michael Hunger separately provided me this query - which is a prototype query which looks like it will do what I want. It includes features of Cypher I was not familiar with (particularly unwind):
If I understand it correctly, this returns a single tuple with two elements:.... match path = shortestPath( (n)-[*]->(m) ) unwind nodes(path) as n with collect(distinct n) as nodes unwind rels(path) as r return collect(distinct r), nodes
- List of all individual relationships (no duplicates)
- List of all individual nodes (no duplicates)
I'll have to try this out!
I kind of wonder how this gets mapped into py2neo - what type are the tuple elements -- list(Relationship) and list(Node) or something like that...
Nigel?
I know my code won't currently handle this - but I can fix that ;-)
-- Alan
The query below should work on any database with at least
one relationship in it. It should return one row with these
fields:
1. nodes: list-of-Nodes
2. relationships: list-of-Relationships
MATCH start
MATCH p = shortestPath( (start)-[*]-(m) )
UNWIND nodes(p) as n
UNWIND rels(p) as r
RETURN collect(distinct n) as nodes, collect(distinct r) as relationships
But when I look at what py2neo is giving me, it returns
1. nodes: list-of-Nodes
2. relationships: list-of-Paths
This is with Neo4j 3.0.0, and Py2neo 2.0.8. It possible it's not your problem, but a Neo4j problem, or even a bug/deficiency in the REST API. But from reading your code, it looked like you weren't expecting this kind of result.
"neo4j::all":"3.0.0",
"py2neo": "2.0.8",
--
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/d/optout.
What do you think?match path = shortestPath( (n)-[*]->(m) ) return collect(distinct unwind(nodes(path))), collect(distinct unwind(rels(path)))
// Active match (but not complete) sub-tree
MATCH (y:Year)-->(m:Month)-->(d:Day)<--(p:Page)<-[r:PARENT_OF*]-(parent:Page)<-[:CONTAINS]-(s:Space)<--(server:Server)
where y.year=2015 // and m.month=1 // and s.key='DIRX'
return p,r,parent,s,server,y,m,d
The query isn't quite right. It has an error in it (variable n already used) and something about the order of operations causes it to return more than one row - with duplicates ;-)
But this one seems to do the trick:
match path = shortestPath( (n)-[*]->(m) ) return collect(distinct unwind(nodes(path))), collect(distinct unwind(rels(path)))
As noted in the original email thread below, the problems I ran
into are:
match path = shortestPath( (n)-[*]->(m) ) return collect(distinct unwind(nodes(path))), collect(distinct unwind(rels(path)))
For your other query, the initial lookup of those nodes will be slow (it has to scan the full graph) b/c you don't have a label (using an index) on them.
You probably also want to add a direction (if it makes sense)