Raphael
Raphael

Reputation: 1919

Graphs, edges and contextual information

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

Answers (2)

Bohdan Ivanov
Bohdan Ivanov

Reputation: 816

Two approaches came to my mind:

  1. Combine people pairs and so on into particular entities; so actually you will have relations Bob <- John and Bob <- John + Mary. But with a big amount of data, I guess it may look ugly.
  2. Create state machine: you will be able to track different states for different situations. So for example, state "John came alone" will have a transition to "Sit near John" while "John came with Mary" will not.

Upvotes: 1

DomTomCat
DomTomCat

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

Related Questions