2017-12-14 9 views

答えて

1

create (:Node)-[:LINK]->(:Node)-[:LINK]->(:Node)-[:LINK]->(:Node)-[:LINK]->(:Node)-[:LINK]->(:Node)-[:LINK]->(:Node) 

その後、私は、このサイファーを使用:

// Get the path between the start and end nodes, including both 
MATCH p = (start:Node)-[:LINK*]->(end:Node) 
WHERE NOT (end)-[:LINK]->() AND NOT()-[:LINK]->(start) 
// extract the nodes of p and calc an array of indexes to 
// access each node in the array of nodes called `nodes`. 
WITH nodes(p) as nodes, range(0, size(nodes(p))) AS indexes 
// unwind indexes as index... 
UNWIND indexes AS index 
// set the value of `DtaID` property of each nodes to the index value. 
// That is: the node 0 will have `DtaID` equal to 0. 
// I'm assuming that you need an increment by one. If you need a 
// different increment you can do calculations here. For example: 
// SET (nodes[index]).DtaID = index * 10 to increment by 10. 
SET (nodes[index]).DtaID = index 

結果:

╒═══════════╕ 
│"n"  │ 
╞═══════════╡ 
│{"DtaID":0}│ 
├───────────┤ 
│{"DtaID":1}│ 
├───────────┤ 
│{"DtaID":2}│ 
├───────────┤ 
│{"DtaID":3}│ 
├───────────┤ 
│{"DtaID":4}│ 
├───────────┤ 
│{"DtaID":5}│ 
├───────────┤ 
│{"DtaID":6}│ 
└───────────┘ 

あなたが必要な場合最初のノードのDtaIDの値をベース値として使用するには、最初のノードをに渡すことができます句と計算に使用します。

MATCH p = (start:Node)-[:LINK*]->(end:Node) 
WHERE NOT (end)-[:LINK]->() AND NOT()-[:LINK]->(start) 
WITH start, nodes(p) as nodes, range(0, size(nodes(p))) AS indexes 
UNWIND indexes AS index 
SET (nodes[index]).DtaID = start.DtaID + index 
+0

は私にとって完璧です。どうもありがとう、Andreas –

+0

@AndreasKuczeraこんにちは!どういたしまして!この回答があなたの質問を解決した場合は、[同意する](https://meta.stackexchange.com/q/5234/179419)のチェックマークをクリックしてください。これは、あなたが解決策を見つけ出し、回答者とあなた自身の両方に評判を与えていることを広範なコミュニティに示します。これを行う義務はありません。 –

+0

アドバイスをいただき、ありがとうございました。 よろしくお願いします。 Andreas –

関連する問題