So you have:
n ----> n1
| \ ^
| \ |
| --->n2 ----> n3
v /
n4 <--/
And want to find paths of depth two (outgoing relationships), which are:
n --> n2 --> n3
n --> n2 --> n4
And for each of those paths see if there are any shorter path(s) (in this
case only depth 1) between start and end node and in that case ignore the
two-length path? I would do something like (just spent a couple of minutes
trying it out):
Node n = ...
final Set<Node> directlyConnectedNodes = new HashSet<Node>();
for ( Relationship relationship : n.getRelationships(
Direction.OUTGOING ) )
{
directlyConnectedNodes.add( relationship.getEndNode() );
}
Evaluator evaluator = new Evaluator()
{
@Override
public Evaluation evaluate( Path path )
{
return path.length() < 2 ?
Evaluation.EXCLUDE_AND_CONTINUE :
Evaluation.of( !directlyConnectedNodes.contains(
path.endNode() ), false );
}
};
for ( Path foundPath : Traversal.description().relationships( TYPE,
Direction.OUTGOING )
.uniqueness( Uniqueness.NODE_PATH ).evaluator( evaluator
).traverse( n ) )
{
System.out.println( foundPath );
}
And the code creating your graph:
Node n = ...
Transaction tx = db.beginTx();
try
{
Node n1 = db.createNode();
n.createRelationshipTo( n1, TYPE );
Node n2 = db.createNode();
n.createRelationshipTo( n2, TYPE );
Node n3 = db.createNode();
Node n4 = db.createNode();
n.createRelationshipTo( n4, TYPE );
n2.createRelationshipTo( n1, TYPE );
n2.createRelationshipTo( n4, TYPE );
n2.createRelationshipTo( n3, TYPE );
tx.success();
}
finally
{
tx.finish();
}
And it returned the correct results.
2011/3/30 jisenhart <[email protected]>
>
> Suppose I have the following node/paths
>
> n -> n1
> n -> n2
> n -> n4
>
> n2 -> n1
> n2 -> n3
> n2 -> n4
>
> I want to find all paths of depth two (for example):
>
> n -> n2 -> n3
> n -> n2 -> n4
>
> and filter out those paths where a shorter path exists to a given node
> (n) leaving just
>
> n -> n2 -> n3
>
> since n -> n4 is "shallower" than n -> n2 -> n4
>
>
> Is this possible? I see GraphAlgoFactory.pathsWithLength(expander,
> length). But unclear on how to proceed beyond that.
>
> Jeff
>
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>
--
Mattias Persson, [[email protected]]
Hacker, Neo Technology
www.neotechnology.com
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user