Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I've just gone through an exercise where I attempted to model a family tree using RedisGraph. I have just published this as my second RedisGraph article, Family Tree with RedisGraph.
As a result of this exercise, I have a few questions on things that I wasn't sure how to do.
First, is it possible to get a mixed tree (i.e. ancestors and descendants) in a single query as opposed to separate queries for ancestors and descendants?
Secondly, given two people, is it possible to identify their relationship (e.g. sibling, cousin, uncle, parent, etc) based on the path between then, or would one need to run separate queries for each relationship type?
Finally, what would be a good query to identify cousins? I'm not convinced with the one I'm using (below) as it should exclude the family where the person queried lies.
I was thinking of a solution along the lines of having another
I hope you'll find my answers below useful
RedisGraph will not avoid revisiting visited nodes.
Thanks for your kind words and for your answers. Let's go through them:
That's interesting, as I can see the relationship. However what I'd like is to be able to give it two individuals (e.g. Donald and Antoinette) and identify the family relationship (e.g. aunt). I'm not sure whether that's possible with a single query.
I fixed an indirected relation in the first
I got this:
Unfortunately this isn't quite right because although it does return the cousins (Bernard and Fiona), it also returns Donald (the person whose cousins we want) and his children (Anthony and George).
I'll see if I can play with this a little and get to a working solution.
Thanks very much!
Thanks for your answers!
The approach you took for No. 1 is interesting to say the least. I had no idea you could get paths like that. It's a shame that UNION is not supported, as it would have been a lot easier.
For No. 2, is there a way to get the shortest path between the two given nodes? Because I could identify the type of family relationship by analysing the relationships in the path. Which I guess is pretty much what I'd do in an actual Cypher query, except that like this I can run a single query instead of one for each type of family relationship.
For No. 3, that's pretty good! I modified it slightly to focus on a specific person, and it works perfectly:
Yes, I just clarified that in #753. A working query for the ancestors & descendants is thus: