繁体   English   中英

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

[英]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.

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