Hi Ryan,

It's nice to see that interest in using Neo4j with Python is picking up :)

Traversers in Neo4j return the (returnable) nodes they visit as they
traverse the graph. It sounds to me that you are more interested in the
relationships. I'm working on changing the traversal subsystem, that will
make it more convenient to extract the relationships.

What the traversers do is traverse the graph from a start node, to arbitrary
depth, using the relationship types you specify. In your case they will
traverse 'follows' relationships from the start node, and then onwards from
each of those nodes. The returnable evaluation you've defined will return
all nodes except the start node (since you are checking for the same
relationship type as the only type you are traversing).

If what you are interested in is traversing to depth one, then just
iterating through the relationships would be easier:

for rel in node.follows:
   print rel

Finally, iterating over neo.nodes will give you ALL nodes in the entire
database. That is why you are seing millions of nodes.

Cheers,
/Tobias

On Tue, Mar 16, 2010 at 8:15 PM, Ryan Rosario <uclamath...@gmail.com> wrote:

> Hi,
>
> I have a large graph and I am trying to extract the list of edges that
> correspond to some relationship "foo", node A -> node B.
> I cannot figure out how to do this. I have tried using a traversal
> class, but I am not having any luck.
>
> neo = NeoService("the path")
>
> class Follow(neo4j.Traversal):
>    types = [
>        neo4j.Outgoing.follows
>    ]
>    order = neo4j.DEPTH_FIRST
>    stop = neo4j.STOP_AT_END_OF_GRAPH
>    def isReturnable(self, position):
>        return (not position.is_start
>                and position.last_relationship.type == 'follows')
>
>
> for friend_node in Friends(node):
>     ...
>
> but this seems to only get the other end of the relationship, not both
> ends. If I wrap this in a for loop "for node in neo.node" I get a huge
> number of nodes, way more than are in the graph.
>
> Even if I write an isStopNode function to mimick STOP_AT_DEPTH_ONE,
> the script keeps going and I end up with millions of nodes in the
> edgelist, when there are only 1000.
>
> TIA,
> Ryan
> _______________________________________________
> Neo mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <tobias.ivars...@neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857
_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to