[英]How to check if all nodes in a graph are reachable from all other nodes?
[英]How to group all sibling nodes from different parents by common sibling in a graph using Gremlin
我很難描述。 我嘗試編寫的Gremlin查詢將一個節點作為輸入。 然后,我正在使用輸入類Group搜索所有節點。 然后,在每個組中只有一個Text類節點和許多Elem節點。 我想獲得所有具有同一個Text節點的Elem節點,即使它們來自不同的Group節點。 您會看到分組的不同顏色。
這是我的意思:
到目前為止,我有:
g = new OrientGraph("remote:localhost/graphdb")
v = g.v('#12:109')
v.bothE.has('@class','hasElem').outV.has('@class','Group').bothE.or(_().has('@class','hasText'), _().has('@class','hasElem').except([v])).inV().except([v])
這將所有綠色和藍色節點返回給我,但是我不知道如何進行分組。
任何幫助表示贊賞:)
謝謝!
花了5個小時,但我找到了執行此操作的查詢:
groupBy
映射基本上將Text節點{it}
作為鍵,並將text-> {it.inE.outV.outE.inV.hasNot('@class','Text').except([v])}
> sibling {it.inE.outV.outE.inV.hasNot('@class','Text').except([v])}
的葉子作為值{it.inE.outV.outE.inV.hasNot('@class','Text').except([v])}
屬於Text類,但Input除外。 最后一行m.sort{a,b -> b.value.size() <=> a.value.size()}
是按受歡迎程度降序對文本進行排序,換句話說,具有較長相關列表的文本兄弟姐妹是第一位。
g = new OrientGraph("remote:localhost/graphdb")
v = g.v('#12:109')
m = [:]
v.bothE.has('@class','hasElem').outV.has('@class','hasElem').dedup().bothE.has('@class','hasText').inV().groupBy(m){it}{it.inE.outV.outE.inV.hasNot('@class','Text').except([v])}
m.sort{a,b -> b.value.size() <=> a.value.size()}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.