格林姆林:获取遍历的边 [英] Gremlin: Get Edges that were traversed

查看:100
本文介绍了格林姆林:获取遍历的边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样本数据:TinkerPop Modern

Sample data: TinkerPop Modern

所需的数据格式:

{'relation': '['created']', 'id': [10224, 10220], 'title': ['Marko', 'lop']}
{'relation': '['knows', 'created']', 'id': [10224, 10226, 10222], 'title': ['Marko', 'Josh', 'ripple']}
{'relation': '['knows', 'created']', 'id': [10225, 10224, 10220], 'title': ['Vadas', 'Marko', 'lop']}
{'relation': '['knows', 'knows', 'knows', 'created']', 'id': [10225, 10224, 10226, 10222], 'title': ['Vadas', 'Marko', 'Josh', 'ripple']}
{'relation': '['created']', 'id': [10226, 10220], 'title': ['Josh', 'lop']}
{'relation': '['created']', 'id': [10226, 10222], 'title': ['Josh', 'ripple']}
{'relation': '['created']', 'id': [10227, 10220], 'title': ['Peter', 'lop']}
{'relation': '['created', 'knows', 'created']', 'id': [10227, 10220, 10226, 10222], 'title': ['Peter', 'lop', 'Josh', 'ripple']}

查询:

g.V().hasLabel("Person").as("from")
.repeat(both().as("to").dedup("from", "to"))
.emit(hasLabel("Software"))
.hasLabel("Software")
.project("title", "relation", "id")
.by(path().by("name"))
.by(constant("r"))
.by(path().by(id()))

问题:

我找不到一种方法来获取遍历的Edge以获取结果Vertex.有什么办法吗?我尝试了bothE().bothV(),但不仅限于遍历

I cannot find a way to get the Edges that were traversed to get the result Vertex. any way out? I tried bothE().bothV() but that is not limited to the traversals

推荐答案

首先,您必须使用bothE().otherV()而不是仅使用both()来遍历边缘.但是,这也会改变路径,因此您必须在查询中调整一些其他内容:

First you have to traverse the edges by using bothE().otherV() instead of just both(). However, this will also change the path and thus you'll have to adjust a few more things in your query:

g.V().hasLabel("person").as("from","v").
  repeat(bothE().as("e").otherV().as("v").dedup("from", "v")).
    emit(hasLabel("software")).
  hasLabel("software").
  project("title", "relation", "id").
    by(select(all, "v").unfold().values("name").fold()).
    by(select(all, "e").unfold().label().fold()).
    by(select(all, "v").unfold().id().fold())

这篇关于格林姆林:获取遍历的边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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