Gremlin - 用有意义的信息显示最短(成本最低)的路径
Gremlin - Showing the shortest (lowest cost) path in with meaningful information
我正在尝试让 Gremlin 向我显示包含有意义信息的最短路径(关于成本,而不是经过的顶点数)。 [Gremlin's Recipes]http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/recipes/#shortest-path 中有一个类似的例子,关于如何获取所有路径及其从一个顶点到另一个顶点的各自成本,但我找不到让 Gremlin 显示有意义的信息的方法,例如名称或顶点的年龄和边的权重。例如,从下面的结果中无法知道 v[1}
是谁。
gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
path().as('p').
map(unfold().coalesce(values('weight'),
constant(0.0)).sum()).as('cost').
select('cost','p') //(4)
==>[cost:3.00, p:[v[1], e[0][1-knows->2], v[2], e[1][2-knows->4], v[4], e[2][4-knows->5], v[5]]]
==>[cost:2.00, p:[v[1], e[0][1-knows->2], v[2], e[3][2-knows->3], v[3], e[4][3-knows->4], v[4], e[2][4-knows->5], v[5]]]
我知道 Gremlin 支持 by()-step 调制器来完成这里的任务:
gremlin> g.V().out().out().path().by('name').by('age')
==>[marko,32,ripple]
==>[marko,32,lop]
,但我不知道如何结合这两种解决方案。理想情况下,我正在寻找的结果应该是这样的:
==>[duration:2, path:[Chicago, supertrain, New York]]
有什么建议吗?非常感谢!
可以在path
步骤后加by
调节器,将values
改成select
:
g.V().hasLabel('A').repeat(outE().inV().
simplePath()).
until(hasLabel('C')).path().
by(valueMap().with(WithOptions.tokens)).as('p').
map(unfold().
coalesce(
select('distance'),
constant(0.0)
).sum()).
as('cost').
select('cost', 'p')
我正在尝试让 Gremlin 向我显示包含有意义信息的最短路径(关于成本,而不是经过的顶点数)。 [Gremlin's Recipes]http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/recipes/#shortest-path 中有一个类似的例子,关于如何获取所有路径及其从一个顶点到另一个顶点的各自成本,但我找不到让 Gremlin 显示有意义的信息的方法,例如名称或顶点的年龄和边的权重。例如,从下面的结果中无法知道 v[1}
是谁。
gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
path().as('p').
map(unfold().coalesce(values('weight'),
constant(0.0)).sum()).as('cost').
select('cost','p') //(4)
==>[cost:3.00, p:[v[1], e[0][1-knows->2], v[2], e[1][2-knows->4], v[4], e[2][4-knows->5], v[5]]]
==>[cost:2.00, p:[v[1], e[0][1-knows->2], v[2], e[3][2-knows->3], v[3], e[4][3-knows->4], v[4], e[2][4-knows->5], v[5]]]
我知道 Gremlin 支持 by()-step 调制器来完成这里的任务:
gremlin> g.V().out().out().path().by('name').by('age')
==>[marko,32,ripple]
==>[marko,32,lop]
,但我不知道如何结合这两种解决方案。理想情况下,我正在寻找的结果应该是这样的:
==>[duration:2, path:[Chicago, supertrain, New York]]
有什么建议吗?非常感谢!
可以在path
步骤后加by
调节器,将values
改成select
:
g.V().hasLabel('A').repeat(outE().inV().
simplePath()).
until(hasLabel('C')).path().
by(valueMap().with(WithOptions.tokens)).as('p').
map(unfold().
coalesce(
select('distance'),
constant(0.0)
).sum()).
as('cost').
select('cost', 'p')