[英]Gremlin Query: How to get all "internal" edges in the query so far?
So I'm trying to visualize the nodes so far in a gremlin query together with only the edges between these nodes;所以我试图在 gremlin 查询中可视化到目前为止的节点以及这些节点之间的边缘; the "internal" edges if you may.
如果可以的话,“内部”边缘。
For example, I have this gremlin query:例如,我有这个 gremlin 查询:
g.V().hasLabel("Person").out("Expert in")
which results in a set of nodes.这导致一组节点。 How do I, in a general matter, make a gremlin query to get all the edges between the nodes in this resultset?
在一般情况下,我如何进行 gremlin 查询以获取此结果集中节点之间的所有边?
Thanks for any help :)谢谢你的帮助 :)
The out()
step is a shorthand for outE().inV()
so the first step to getting the edges is to explicitly traverse the edges so that they become part of the path history. out()
步骤是outE().inV()
的简写,因此获取边缘的第一步是显式遍历边缘,使它们成为路径历史的一部分。 You could get the edges from that history in a variety of ways - how about the path() step?您可以通过多种方式从该历史记录中获取边缘 - path() 步骤如何?
g.V().hasLabel("Person").outE("Expert in").inV().path()
I figured it out!我想到了!
This gremlin query should do the trick:这个 gremlin 查询应该可以解决问题:
g.V().hasLabel('Person') // <-- Nodes chosen so far; can be any query resulting in nodes
.dedup()
.union(outE(), inE())
.groupCount()
.unfold()
.where(select(values).is(gt(1)))
.select(keys)
This takes the union of all outgoing and all ingoing edges, and then removes those edges that does not appear more than once.这需要所有出边和所有入边的联合,然后删除那些出现次数不超过一次的边。 The result is all the edges between the nodes in the query so far :)
结果是到目前为止查询中节点之间的所有边:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.