[英]Gremlin - Select vertices based on group keys
I have a graph with 2 different vertex classes with some identical properties.我有一个具有 2 个不同顶点类的图,它们具有一些相同的属性。
I need to:我需要:
g.addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "round").
property("price", 1.2).
addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "round").
property("price", .9).
addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "square").
property("price", 5).
addV("Product").
property("color", "green").
property("material", "wood").next();
What I've tried so far is this到目前为止我尝试过的是这个
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()));
I understand that at 2
the scope changes so select(Column.keys)
no longer refers to the group.我知道在
2
范围发生了变化,因此select(Column.keys)
不再指代该组。 However, I'm at a loss how to get the value of the c
(and m
) key into the traversal at 2
但是,我不知道如何将
c
(和m
)键的值放入2
的遍历中
So I tried to solve it with a slightly different approach.所以我试图用稍微不同的方法来解决它。
Each group will have all the items and the products for the color and material combo每组将拥有颜色和材料组合的所有项目和产品
that way most of the work will be done on your first group
step:这样,大部分工作将在您的第一个
group
步骤中完成:
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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.