Finding the unique paths through a Neo4j graph
Posted
by
Larry
on Stack Overflow
See other posts from Stack Overflow
or by Larry
Published on 2013-10-21T15:52:31Z
Indexed on
2013/10/21
15:53 UTC
Read the original article
Hit count: 163
neo4j
I have a Neo4j graph with 12 inputs and 4 outputs, and am trying to write a query with the Java Traverser that will return the 14 unique paths from an input to an output node. All the queries I have tried return only a subset of the 14 paths. For example, the code below returns 4 paths, but the other 10 all stop 1 node short of the output.
RelationshipType relType = RelationshipTypes.EDGE;
TraversalDescription td = new TraversalDescriptionImpl()
.depthFirst()
.relationships(relType, Direction.OUTGOING);
for (Node node : inputs){
Traverser tv = td.traverse(node);
Iterator<Path> iter = tv.iterator();
// ... print path
}
I've tried uniqueness and depth settings as well, with no effect.
The query below returns all 14 paths using the web interface, but when I use the ExecutionEngine class, I only get 13 paths back.
START s=node(*)
MATCH (s)-[p:EDGE*]->(c)
WHERE s.type! = "INPUT" AND c.type! = "OUTPUT"
RETURN p
How do I get all the unique paths using the Java API?
© Stack Overflow or respective owner