我很难描述。我试图写的Gremlin查询有一个节点作为输入。然后我用类Group输入搜索所有节点。然后在每个组中只有一个Text类节点和一些Elem节点。 我想让所有Elem节点作为兄弟节点具有相同的Text节点,即使它们来自不同的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])
这会将所有绿色和蓝色节点返回给我,但我不知道如何进行分组。
感谢任何帮助:)
谢谢!
答案 0 :(得分:1)
It took 5hours but I found the query that does it:
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. 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.
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()}