Gremlin 如何从tinkerpop中的重复步骤访问存储的变量
我和小精灵只呆了两天。我有一组顶点和彩色边。我想找到从S2到D2的路径。如果我通过绿色边G1-B1进入黑色顶点,那么我只能通过绿色边B2-G2出来。我不应该从红边出来 下面的查询工作,但我不能硬编码颜色有'颜色',绿色在第三行Gremlin 如何从tinkerpop中的重复步骤访问存储的变量,gremlin,tinkerpop3,Gremlin,Tinkerpop3,我和小精灵只呆了两天。我有一组顶点和彩色边。我想找到从S2到D2的路径。如果我通过绿色边G1-B1进入黑色顶点,那么我只能通过绿色边B2-G2出来。我不应该从红边出来 下面的查询工作,但我不能硬编码颜色有'颜色',绿色在第三行 g.V().hasLabel("S2").repeat(outE("tx").choose(values("type")). option("multiplex",aggregate(local,"colors").by("color").inV()).
g.V().hasLabel("S2").repeat(outE("tx").choose(values("type")).
option("multiplex",aggregate(local,"colors").by("color").inV()).
option("demultiplex",has('color',within("green")).inV()).
option(none,__.inV()).
simplePath()).until(hasLabel("D2")).path().by(label())
所以我试着在下面查询它没有给出任何路径。如果我的边有标签“multiplex”,那么我存储颜色。如果我的边缘有标签“解复用”,那么我会从商店中读取颜色
g.V().hasLabel("S2").repeat(outE("tx").choose(values("type")).
option("multiplex",aggregate("colors").by("color").inV()).
option("demultiplex",has("color",within(select("colors").unfold())).inV()).
option(none,__.inV()).
simplePath()).until(hasLabel("D2")).path().by(label())
下面的代码填充图形
你很接近。这种语法总是很诱人:
has("color",within(select("colors").unfold())
但它并不像你发现的那样有效。P语法不会以这种方式进行遍历。您需要使用where的形式来表示何时需要引用副作用,即颜色
gremlin> g.V().hasLabel("S2").
......1> repeat(outE("tx").
......2> choose(values("type")).
......3> option("multiplex",aggregate(local,"colors").by("color").inV()).
......4> option("demultiplex", filter(values('color').as('c').
......5> where('c',eq('colors')).
......6> by().
......7> by(unfold().tail())).inV()).
......8> option(none,__.inV()).
......9> simplePath()).
.....10> until(hasLabel("D2")).
.....11> path().by(label)
==>[S2,tx,G1,tx,B1,tx,B2,tx,G2,tx,G3,tx,B3,tx,B4,tx,G4,tx,D2]
gremlin> g.V().hasLabel("S2").
......1> repeat(outE("tx").
......2> choose(values("type")).
......3> option("multiplex",aggregate(local,"colors").by("color").inV()).
......4> option("demultiplex", filter(values('color').as('c').
......5> where('c',eq('colors')).
......6> by().
......7> by(unfold().tail())).inV()).
......8> option(none,__.inV()).
......9> simplePath()).
.....10> until(hasLabel("D2")).
.....11> path().by(label)
==>[S2,tx,G1,tx,B1,tx,B2,tx,G2,tx,G3,tx,B3,tx,B4,tx,G4,tx,D2]