graph - Gremlin 查询 : Another way to write this in a loop

标签 graph neo4j graph-databases gremlin

g.v(1).out('__SYSTEM_HAS_CHILD').filter{it.name == 'Journal'}.out('__SYSTEM_HAS_CHILD').filter{it.name == 'travel'}.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Alaskan-Natives'}.map

也许存储一个包含项目的数组,然后遍历每个项目并执行 out 并将其附加到 it.name;并迭代(计数)以确保我们不会超出数组的长度。

最佳答案

您可以像这样重新格式化管道:

pipe = g.v(1)
pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Journal'}
pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'travel'}
pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Alaskan-Natives'}
pipe.map

然后您可以使用 Groovy 结构将其变成一个循环:

names = ["Journal", "travel", "Alaskan-Natives"]
pipe = g.v(1)
names.each() { name -> 
  pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == name} 
}
pipe.map

注意:为什么要将管道作为 map 返回?要迭代管道,您可以使用以下任一方法:

pipe.iterate()
pipe.toList()

参见 https://github.com/tinkerpop/gremlin/wiki/Gremlin-Methods

关于graph - Gremlin 查询 : Another way to write this in a loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12188805/

相关文章:

c++ - 使用 boost 图创建结构

c++ - boost::property_map在boost中是怎么实现的,怎么改

java - 直接邻居关系密码查询性能

neo4j - 使用 resultDataContents=graph 通过 REST API 返回集合时,为什么排序顺序会丢失

docker - 让 Neo4J 在 OpenShift 上运行

sparql - Amazon Neptune 中默认使用匿名身份验证吗?

python - 您可以将 BulbFlow(灯泡)Python ORM 与 OrientDB 的图形模式约束一起使用吗?

javascript - 查找图中具有最小值的节点

c++ - 通过 boost::read_graphviz() 读取 boost 动态属性时出现异常

java - 按父顶点过滤 Gremlin 搜索