2016-06-09 89 views
2

我是新來圖並試圖瞭解上下文關係如何映射到它們中。圖形,邊緣和上下文信息

我看實例系統介紹簡單的演示(1),例如:

# I want to organize the seating arrangement for my party 
# Bob does not like John, so I can say 

-----------      ------------ 
| Bob | <--- excludes --- | John | 
-----------      ------------ 

但如果我想說的是,鮑勃竟然喜歡約翰,但不喜歡被他身邊的時候他由他的女朋友瑪麗陪同(你知道,他們總是親吻,你不能再跟他們說話)。我想過兩種解決方案:

# 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 | 
---------- 

請注意,我沒有找到任何像這樣的例子,甚至不知道是否在圖形處理直接這類問題是正確的解決方案。任何想法?謝謝。

(1)如約Neo4j的,http://www.slideshare.net/thobe/django-and-neo4j-domain-modeling-that-kicks-ass/25-The_Neo4j_Graph_data_model

回答

0

如果你不限制自己的一組人的關係,而是全體人民的Power Set,你可以編號不同羣體之間還模型關係 - 例如再次通過使用圖表。 解決方案在所有節點都是定義集的一部分的意義上是乾淨的。正如你已經提到的,你必須檢查一個人所在的所有節點。

1

兩種方法來到我的腦海:

  1. 結合人們對等成特定的實體;所以實際上你會有關係鮑勃< - 約翰和鮑勃< - 約翰+瑪麗。但有了大量的數據,我想它可能看起來很醜。
  2. 創建狀態機:您將能夠跟蹤不同情況下的不同狀態。例如,「約翰獨自來到」這個州將會轉變爲「坐在約翰附近」,而「約翰與瑪麗一起來」不會。
+0

謝謝博丹!國家模式看起來很有希望。如果我理解的很好,那麼這個目標節點就是約翰的衛星。國家模式似乎解決了問題的一部分。例如:如果尋找約翰在瑪麗加入時排除的人,我會馬上得到鮑勃。然而,在尋找誰排斥鮑勃時,我可能必須通過許多不同的狀態遍歷許多對象。 – Raphael

+1

對不起,我想過更多。這看起來很合理:你只需鏈接John和Bob,然後檢查是否符合排除條件。謝謝! – Raphael