简体   繁体   English

Gremlin Cayley查询:如何进行多级查询

[英]Gremlin Cayley query: How to have a multi leveled query

New to cayley and have cannot figure out how to display a multi level query with unknown amount of levels. 新的cayley并且无法弄清楚如何显示具有未知数量级别的多级查询。

For example Lets say all predicates/relations between nodes are "likes". 例如,让我们说节点之间的所有谓词/关系都是“喜欢”。 If I have a graph shaped this way. 如果我有这样形状的图形。

A --> B

B --> C

C --> D

D --> E

... ...

I would like to follow the train and display the entire likes graph. 我想跟随火车并显示整个喜欢的图表。 What query would I use? 我会用什么查询? This is what I have tried. 这就是我尝试过的。

function getLikes(x) { 
    return g.V(x).As("source").Out("likes").As("target)
}

getLikes("A").ForEach( function(d) {
    g.Emit(getLikes(d))
})

This only returns 这只会返回

{ {

"result": [ “结果”:[

{ {

"All": {}, “全部”:{},

"And": {}, “和”:{},

"As": {}, “作为”:{},

"Back": {}, “背部”: {},

... And all other path options ......以及所有其他路径选择

I have also tried 我也试过了

return g.V(x).As("source").Out("likes").As("target).All()

Instead of the second line of code. 而不是第二行代码。 Just added the .All() at the end to finalize the query. 刚刚在末尾添加了.All()来完成查询。 This returns query results, but the visualization tool shows nothing. 这将返回查询结果,但可视化工具不显示任何内容。 Any guidance on how to show this like graph would be much appreciated! 任何有关如何显示此图形的指导将非常感谢!

I'm not sure if you still need this, but I'm going to write anyway as I had to learn the same thing from almost non-existent example based documentation on Cayley. 我不确定你是否仍然需要这个,但我还是要写,因为我必须从Cayley上几乎不存在的基于示例的文档中学到同样的东西。

To traverse a graph, Cayley has a .FollowRecursive() method defined in the API . 为了遍历图形,Cayley在API中定义了.FollowRecursive()方法。 The method .FollowRecursive uses something called a Morphism to figure out how to follow the path recursively. 方法.FollowRecursive使用一种称为态射的东西来弄清楚如何递归地遵循路径。 From my understanding, it seems like an abstract path object that encodes the recursive case (kind-of like your getLikes function (but not quite)). 根据我的理解,它似乎是一个抽象路径对象,它编码递归的情况(有点像你的getLikes函数(但不完全))。 Here's an example of Gizmo query that should work for complete graph/chain traversal. 以下是Gizmo查询的示例,该查询应该适用于完整的图形/链遍历。

var path = g.M().Out("edge_name_here");
var start_node = "begin";

//Path query
//Note that FollowRecursive expects a Morphism path
g.V(start_node).FollowRecursive(path).All() //That's all.

To visualize the entire traversal or to do some further querying on each vertex use the .ForEach() construct (see API) 要可视化整个遍历或对每个顶点进行进一步查询,请使用.ForEach()构造(请参阅API)

g.V(start_node).FollowRecursive(path).ForEach( function(v){
  //In here we can do further querying or more vaguely put "stuff"
  g.V(v.id).Out(chain_pred).ForEach( function(t){
    var node = { //This source, target formulation works for visualization for eg.
      source: v.id,
      target: t.id
    }

    g.Emit(node) //This throws the output into the final result bucket
  })
})

I hope someone in the universe finds it helpful 我希望宇宙中有人发现它有用

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

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