Reputation: 1919
I'm new to graph and try to understand how contextual relations can be mapped into them.
I've looked at examples which systematically introduce simple demos (1), for instance:
# I want to organize the seating arrangement for my party
# Bob does not like John, so I can say
----------- ------------
| Bob | <--- excludes --- | John |
----------- ------------
But what if I want to say that Bob actually likes John, but does not like being around him when he is accompanied by his girlfriend Mary (you know, they kiss all the time and you cannot talk to them anymore). I've thought about two solutions:
# solution 1: create an intermediary node.
# now, the problem is that, if I want to know who John excludes,
# I have to look at the node John + every other node he might be the child of.
| John |
----------- ------------- -----------
| Bob | <--- excludes --- | Couple | <
----------- ------------- ------------
| Mary |
------------
# solution 2: target the edges, and make them cumulative
# here if I want to know who John excludes,
# I just have to target the node John and then check for
# additional logic (in this case, check if Mary is present too).
----------- ------------
| Bob | <--- excludes --- | John |
----------- ^ ------------
^ |
| |
excludes <---- requires (some logic here)
|
----------
| Mary |
----------
Note that I did not find any example like this and am even wondering if handling this kind of problem directly in the graph is the right solution. Any thought? Thanks.
(1) eg about neo4j, http://www.slideshare.net/thobe/django-and-neo4j-domain-modeling-that-kicks-ass/25-The_Neo4j_Graph_data_model
Upvotes: 2
Views: 54
Reputation: 816
Two approaches came to my mind:
Upvotes: 1
Reputation: 8569
If you don't restrict yourself to the set of people their relations, but to the Power Set of all people, you can also model relations between differently numbered groups - e.g. again by using a graph. The solution is clean in the sense of all nodes being part of a defined set. You'll have to inspect all nodes which a person is in, as you've mentioned already.
Upvotes: 0