【问题标题】:Gremlin: Get Edges that were traversedGremlin:获取已遍历的边
【发布时间】:2018-03-27 10:26:28
【问题描述】:

示例数据: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()))

问题:

我找不到方法来获取遍历的边以获取结果顶点。有什么出路吗?我尝试了 bothE().bothV() 但这不限于遍历

【问题讨论】:

  • 我也面临同样的问题

标签: gremlin


【解决方案1】:

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

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())

【讨论】:

  • 感谢您的帮助,现在可以修改一些东西并玩 gremlin
  • 如果我使用 .as("from") 而不是 .as("from", "to") 缺少 to结果,这与范围在 gremlin 中的工作方式有关吗? IE。 otherV().as("to") 在重复步骤中是本地的吗?
  • 如果你没有用v标记第一个顶点,那么它就不会出现在select(all, "v")中,不知道有什么不清楚的地方。
【解决方案2】:

PipeFunction "enablePath()" 应该为您执行此操作。请参阅文档。

【讨论】:

  • 试图搜索该函数但找不到它,你能给我一个文档链接吗?
猜你喜欢
  • 1970-01-01
  • 2021-12-21
  • 2019-03-22
  • 1970-01-01
  • 1970-01-01
  • 2013-05-06
  • 1970-01-01
  • 1970-01-01
  • 2020-07-07
相关资源
最近更新 更多