13

Neo4j グラフ データベースとして次のグラフがあります。

                           activates
                            (80 °F)
          (A)------------------------------------->(D)
           | \__                                _/->^
           |    \__  activates               __/    |
           |       \__(50 °F)             __/       |
           |          \__              __/          |             
           |             \__        __/             | 
activates  |                \__  __/                |
 (50 °F)   |                   \/                   | activates
           |                 __/\__                 | (50 °F)
           |    activates __/      \__              |
           |    (60 °F)__/            \__           |
           |        __/                  \__        |
           |     __/                        \__     |
           |  __/                              \_   |
           v /                                   \->|
          (B)------------------------------------->(C)
                           activates                          
                            (50 °F)

各関係には、「アクティブ化」アクションに必要な温度を示すプロパティがあります。

パスに沿って温度が 50 °Fである(A) と (D) の間の使用可能なすべてのパスを取得する必要があります。

出力には次が含まれている必要があります。

A -[:activates{temperature:'50'}]-> B -[:activates{temperature:'50'}]-> C -[:activates{temperature:'50'}]-> D

A -[:activates{temperature:'50'}]-> C -[:activates{temperature:'50'}]-> D

だがしかし

A -[:activates{temperature:'80'}]-> D

A -[:activates{temperature:'50'}]-> B -[:activates{temperature:'60'}]-> D

必要な Cypher クエリを作成するにはどうすればよいですか?

前もって感謝します。

編集 1:より明確にするために、別の対角関係 (B -[:activates{temperature:'80'}]-> D) を追加しました。

編集 2: (A) と (D) の間で使用可能なすべてのパスを取得する必要があります。パスに沿って温度が同じ場合、つまり、A -> B -> C -> D、A -> C -> D、 A -> D.

4

1 に答える 1

17
START a=node({A}), d=node({D})
MATCH p=a-[r:ACTIVATES*..]-d
WHERE has(r.temperature) and r.temperature='50'
RETURN p;

曲線括弧(A、D)の値をノードIDに置き換えます

更新: 関数allを使用

START a=node(1), d=node(4) 
MATCH p=a-[r:ACTIVATES*..]-d 
WITH head(relationships(p))as r1,p //since the pointer r is a collection of rels we must declare a single relationship pointer
WHERE all(r2 in relationships(p) 
          where r2.temperature=r1.temperature) 
return p;
于 2013-01-03T08:42:51.620 に答える