简体   繁体   English

如何在 Gremlin 中使用 Edge Label 执行遍历

[英]How to perform traversal in Gremlin With Edge Label

I have a somewhat a simple question but I am still trying to grasp the gremlin language and graphing databases in general.我有一个简单的问题,但我仍在努力掌握 gremlin 语言和图形数据库。 I have the following items in the graph.我在图中有以下项目。 This is just a single path but I want to find the nodes attached to the edges with property "ABC".这只是一条路径,但我想找到附加到具有属性“ABC”的边缘的节点。

This is my graph for example:例如,这是我的图表:

a = g.addV("building").property("name", "A").next()
b = g.addV("building").property("name", "B").next()
c = g.addV("building").property("name", "C").next()
d = g.addV("building").property("name", "D").next()
e = g.addV("building").property("name", "E").next()

g.addE("path").from(a).to(b).property("ident", "ABC")
g.addE("path").from(b).to(c).property("ident", "ABC")
g.addE("path").from(c).to(d).property("ident", "ABC")
g.addE("path").from(d).to(e).property("ident", "ABC")

g.addE("path").from(a).to(b).property("ident", "XYZ")
g.addE("path").from(b).to(c).property("ident", "XYZ")
g.addE("path").from(c).to(d).property("ident", "XYZ")
g.addE("path").from(d).to(e).property("ident", "XYZ")

What I am trying to do is find the edges with .has("path", "ident", "ABC") .我想做的是用.has("path", "ident", "ABC")找到边缘。 I can do this, but I am trying to figure out how to take that and end up showing the graph.我可以做到这一点,但我试图弄清楚如何接受并最终显示图表。 I am trying to figure out how to get:我试图弄清楚如何获得:

A->path->B->path->C->path->D->path->E

Again thanks in advance and you don't have to solve but help just point me in the right direction.再次提前感谢您,您不必解决问题,只需帮助我指出正确的方向。

This can be accomplished using a combination of repeat() steps with filtering on the edge property ident using the has() step like this:这可以通过将repeat()步骤与使用has()步骤对边缘属性ident进行过滤相结合来完成,如下所示:

gV().has('building', 'name', 'A').repeat(outE('path').has('ident', 'ABC').inV()).until(outE('path').count().is(0)).path()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM