Chr*_*ves 6 graph-traversal gremlin
在图遍历中,我只想考虑具有属性的边,该边等于遍历中前一步中访问的边之一的属性.
我找到了http://tinkerpop.apache.org/docs/current/recipes/#traversal-induced-values但这似乎只适用于单个对象,在我的情况下,我需要在遍历时更改值.例如,从具有出站边缘(E1,E2,E3 ......)的V1开始,我想要将E1遍历到V2,然后沿着V2的任何边缘遍历,其中edge.property(x)== E1.property(x ),并对V1(E2,E3,...)中的所有边做同样的事情
我找不到任何支持在Gremlin中执行此操作的文档,是否可能?
我们可以使用TinkerPop附带的现代玩具图:
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
Run Code Online (Sandbox Code Playgroud)
该曲线图中已经包含6层的边缘,其中两个具有weight的1.0:
gremlin> g.E().valueMap()
==>[weight:0.5]
==>[weight:1.0]
==>[weight:0.4]
==>[weight:1.0]
==>[weight:0.4]
==>[weight:0.2]
Run Code Online (Sandbox Code Playgroud)
我们用这两个边缘的一个带有weight的1.0获得与同其他边缘weight.通过遍历这两个边中的第一个,我们降落在一个有两个外边的顶点:
gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
==>e[10][4-created->5]
==>e[11][4-created->3]
gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
==>[weight:1.0]
==>[weight:0.4]
Run Code Online (Sandbox Code Playgroud)
其中一个边缘是另一个重量为1.0.所以,我们只需要根据第一条边的权重过滤这些边:
gremlin> g.V(1).outE().has('weight',1.0).
as('firstEdge'). // save the first edge
inV().outE().
where(eq('firstEdge')). // compare with the first edge
by('weight') // use only the 'weight' property for the equality check
==>e[10][4-created->5]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1771 次 |
| 最近记录: |