Gremlin-基于组关键点选择顶点
我有一个图,有两个不同的顶点类,它们有一些相同的性质 我需要:Gremlin-基于组关键点选择顶点,gremlin,tinkerpop3,Gremlin,Tinkerpop3,我有一个图,有两个不同的顶点类,它们有一些相同的性质 我需要: 根据某些属性对类项的所有顶点进行分组 查找共享这些属性的类乘积的顶点 到目前为止我试过的是这个 g.V().has("Item", "price", P.inside(0, 10)). group(). by(project("c", "m"). by("color").by("material")). //\1 local(unfold(). project("color", "mate
g.V().has("Item", "price", P.inside(0, 10)).
group().
by(project("c", "m").
by("color").by("material")). //\1
local(unfold().
project("color", "material","price","product")
.by(select(Column.keys).select("c"))
.by(select(Column.keys).select("m"))
.by(select(Column.values).unfold().values("price").mean())
.by(
V().hasLabel("Product"). //\2
has("material",P.eq(select(Column.keys).select("c"))).fold()));
我知道在2
中,范围发生了变化,因此select(Column.keys)
不再指该组。
但是,我不知道如何将
c
(和m
)键的值输入到2
处的遍历中,所以我尝试用稍微不同的方法来解决它
每组将拥有颜色和材质组合的所有项目和产品
这样,大部分工作将在您的第一个组中完成
步骤:
g.V().coalesce(
hasLabel("Item").has("price", P.inside(0, 10)),
hasLabel("Product").has("color").has("material")
).group()
.by(project("c", "m").by("color").by("material"))
.unfold()
.where(select(values).unfold().hasLabel("Item"))
.project("color", "material","price","product")
.by(select(keys).select("c"))
.by(select(keys).select("m"))
.by(select(values).unfold().hasLabel("Item").values("price").mean())
.by(select(values).unfold().hasLabel("Product").fold())
谢谢你,这很有效。你能澄清一下原因吗?从文档合并-返回第一次遍历的结果,以发出至少一个元素。为什么产品甚至在集团中?我将此理解为“如果第一次遍历有元素,则不做其他元素”不要紧,组接受遍历器的所有元素,因此它首先“耗尽”项遍历,然后是产品。我感到困惑,因为到目前为止,我所看到的最常用的合并是添加一个顶点,如果它不存在,但使用
next
g.V().coalesce(
hasLabel("Item").has("price", P.inside(0, 10)),
hasLabel("Product").has("color").has("material")
).group()
.by(project("c", "m").by("color").by("material"))
.unfold()
.where(select(values).unfold().hasLabel("Item"))
.project("color", "material","price","product")
.by(select(keys).select("c"))
.by(select(keys).select("m"))
.by(select(values).unfold().hasLabel("Item").values("price").mean())
.by(select(values).unfold().hasLabel("Product").fold())