我们可以将一个属性与相同顶点的其他属性相关联吗 [英] can we relate a property with other property of same vertex

查看:91
本文介绍了我们可以将一个属性与相同顶点的其他属性相关联吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例顶点

g.addV('a').property('vehicle','v1').property('time',1000).property(list,'vehicle','v2').property(list,'time',830)

我们如何将车辆"属性中的值映射到时间"属性中. 我累了下面的代码

how can we map the values in property 'vehicle' to the values in property 'time'. I tired the following code

g.V(1).hasKey('vehicle').map(hasKey('time'))

要找到路径,我讨厌遵循以下代码

To find path I tired following code

g.V().hasLabel('a').repeat(out().simplePath()).until(hasLabel('h')).path().by(union(label(),values('vehicle','time')).fold())

你能帮我吗

推荐答案

更改数据模型使这些查询更易于编写.如果您使用顶点和边来建模车辆和时间,而不是使用存储为属性的列表来建模,则可以执行以下操作.

Changing the data model makes these kinds of queries easier to write. If you use vertices and edges to model the vehicles and times instead of lists stored as properties then you can do something like this.

g.addV('A').as('a').
  addV('B').as('b').
  addV('C').as('c').
  addV('vehicle').as('v1').property('time',10).property('name','V1').
  addV('vehicle').as('v2').property('time',8).property('name','V2').
  addV('vehicle').as('v3').property('time',5).property('name','V3').
  addV('vehicle').as('v4').property('time',6).property('name','V4').
  addV('vehicle').as('v5').property('time',5).property('name','V5').
  addV('vehicle').as('v6').property('time',6).property('name','V6').
  addE('route').from('a').to('b').
  addE('route').from('b').to('c').
  addE('vehicle_info').from('a').to('v1').
  addE('vehicle_info').from('a').to('v2').
  addE('vehicle_info').from('b').to('v3').
  addE('vehicle_info').from('b').to('v4').
  addE('vehicle_info').from('c').to('v5').
  addE('vehicle_info').from('c').to('v6').
  iterate()

gremlin> g.V().hasLabel('A').
......1>   repeat(out('route').simplePath()).
......2>     until(hasLabel('C')).
......3>   path().
......4>     by(union(label(),out('vehicle_info').values('name','time').fold()).fold())

==>[[A,[V1,10,V2,8]],[B,[V3,5,V4,6]],[C,[V5,5,V6,6]]]  

编辑添加:

您可以按时间进行过滤,如下所示:

You can filter by the time as follows:

gremlin> g.V().hasLabel('A').
......1>   repeat(out('route').simplePath()).
......2>     until(hasLabel('C')).
......3>   path().
......4>     by(union(label(),out('vehicle_info').has('time',between(5,10)).values('name','time').fold())
.fold()) 
==>[[A,[V2,8]],[B,[V3,5,V4,6]],[C,[V5,5,V6,6]]]  

这篇关于我们可以将一个属性与相同顶点的其他属性相关联吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆