简体   繁体   English

如何通过使用Gremlin在图中通过公共同级对不同父级的所有同级节点进行分组

[英]How to group all sibling nodes from different parents by common sibling in a graph using Gremlin

It is difficult for me to describe. 我很难描述。 The Gremlin query I am trying to write has one node as an input. 我尝试编写的Gremlin查询将一个节点作为输入。 Then I am searching all the nodes with class Group of input. 然后,我正在使用输入类Group搜索所有节点。 Then in each group there is only one Text class node and a number of Elem nodes. 然后,在每个组中只有一个Text类节点和许多Elem节点。 I would like to get all the Elem nodes that have as a sibling the same Text node even if they are from different Group nodes. 我想获得所有具有同一个Text节点的Elem节点,即使它们来自不同的Group节点。 You see the different color of groupings. 您会看到分组的不同颜色。

Here is what I mean: 这是我的意思:

在此处输入图片说明

What I have so far: 到目前为止,我有:

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])

This returns to me all the green and blue nodes together, but I don't know how to do the grouping. 这将所有绿色和蓝色节点返回给我,但是我不知道如何进行分组。

Any help is appreciated :) 任何帮助表示赞赏:)

Thanks! 谢谢!

It took 5hours but I found the query that does it: 花了5个小时,但我找到了执行此操作的查询:

The groupBy mapping basically takes as a key the Text node {it} and as a value the leaf from text->parent->sibling {it.inE.outV.outE.inV.hasNot('@class','Text').except([v])} that is not of class Text except for the Input. 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除外。 The last line m.sort{a,b -> b.value.size() <=> a.value.size()} is sorting Texts in descending popularity, or in other words the ones that have the longer list of related siblings are coming first. 最后一行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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM