有没有办法在计算特征之前存储过滤后的边缘

Is there a way to store filtered edges before computing features

对于给定的顶点,我想计算多个聚合特征,这些特征彼此不明显,我可能会这样做。

g.V(81968)
    .project('P1', 'P2', 'P3')
    .by(__.bothE().has('dt_int', lt(999999999999)).values('orig_amt').mean())
    .by(__.bothE().has('dt_int', lt(999999999999)).values('currency').dedup().count())
    .by(__.bothE().has('dt_int', lt(999999999999)).values('weight').mean())

这个查询的明显问题是每次我想创建一个新的聚合特征时我都在计算 __.bothE().has('trxn_dt', lt(999999999999))(即 P1P2P3).当我尝试为具有大量边的顶点计算这组特征时,这一点变得很清楚。

有没有办法存储过滤后的边集,然后 select 以备后用?类似于这个伪查询:

g.V(81968)
    .hold(__.bothE().has('dt_int', lt(999999999999))).as('edges')
    .project('P1', 'P2', 'P3')
    .by(select('edges').values('orig_amt').mean())
    .by(select('edges').values('currency').dedup().count())
    .by(select('edges').values('weight').mean())

这个问题可以追溯到我之前问过的一个问题 (),但我正在寻找一种更通用的方法,并且正在努力使其适应一组通用的功能。

您建议 "hold()" 结果,而 Gremlin 有 aggregate()store() 用于此类事情,如果您需要 List,只需 fold() 您的结果,然后 project() 您需要的那个 List

g.V(81968).bothE().has('dt_int', lt(999999999999)).
  fold().
  project('P1', 'P2', 'P3').
    by(unfold().values('orig_amt').mean()).
    by(unfold().values('currency').dedup().count()).
    by(unfold().values('weight').mean())

通过这种方式,您不需要副作用或路径跟踪。