Cayley 0.7.0 depth function issue


#42

@Jorgen depth means up & down ie; in both directions whatever u have mentioned.

But as per your query only down part is showing.


#43

So you want this:
(probably not most efficient with a query in the foreach, so better to separate that.

var path = g.M().Tag('hop').Out(null, "relation");
var pathIn = g.M().Tag('hop').In(null, 'relation');
var depth =  3;
g.V("Test 2").Tag("source").FollowRecursive(path,depth).Tag("target").ForEach(function(v){
  g.V(v.source).Tag('source').FollowRecursive(pathIn, depth).Tag('target').ForEach(function(y){
    var node = {
  source: y.hop,
  start: y.source,
  relation : y.relation,
  target: y.target
  }
  g.Emit(node)

  })
  
  var node = {
  source: v.hop,
  start: v.source,
  relation : v.relation,
  target: v.target
  }
  g.Emit(node)

})

Graph

Query result


#44

Yes Correct @Jorgen

Graph is perfectly fine but as per your query I am getting below response which is not correct :

{
“result”: [
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test2”,
“target”: “Test1”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test2”,
“target”: “Test3”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test2”,
“target”: “Test1”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“start”: “Test2”,
“target”: “Test4”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test2”,
“target”: “Test1”
},
{
“relation”: “DependsOn”,
“source”: “Test4”,
“start”: “Test2”,
“target”: “Test5”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test2”,
“target”: “Test1”
},
{
“relation”: “ConnectedTo”,
“source”: “Test4”,
“start”: “Test2”,
“target”: “Test8”
}
]
}

So, need to fine tune the query part, If we are able to correct the query , will get the graph according to the same. It should show as below only -

{
“result”: [
{
“relation”: “RunsOn”,
“source”: “Test1”,
“target”: “Test2”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“target”: “Test3”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“target”: “Test4”
},
{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test5”
},
{
“relation”: “ConnectedTo”,
“source”: “Test4”,
“target”: “Test8”
}
]
}


#45

@Chaitanya (please not target/source a reversed in the first subquery because it goes in the other direction. You can change it to give the correct names while tagging

var path = g.M().Tag('hop').Out(null, "relation");
var pathIn = g.M().Tag('hop').In(null, 'relation');
var depth =  3;

var done = false;
  
g.V("Test 2").Tag("source").FollowRecursive(path,depth).Tag("target").ForEach(function(v){
  if (!done){
    done=true;
  g.V(v.source).Tag('source').FollowRecursive(pathIn, depth).Tag('target').ForEach(function(y){
    var node = {
  source: y.target,
  relation : y.relation,
  target: y.source
  }
  g.Emit(node)

  })
  }
  var node = {
  source: v.hop,
  start: v.source,
  relation : v.relation,
  target: v.target
  }
  g.Emit(node)

})

#46

Ohh you beauty !! Superb @Jorgen

Thanks u so much …!! Its working exactly what I am looking for.


#47

@Jorgen

While testing i got the that there is some mismatch for Test5 and depth=2 . It should show 6 related nodes but instead I am getting 5 nodes that too with one wrong relation.

Response :

{
“result”: [
{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test5”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“target”: “Test5”
},
{
“relation”: “BelongsTo”,
“source”: “Test5”,
“target”: “Test6”
},
{
“relation”: “ConnectedTo”,
“source”: “Test5”,
“target”: “Test9”
},
{
“relation”: “Contains”,
“source”: “Test6”,
“target”: “Test7”
}
]
}

Note : There is no direct relationship between Test3 & Test5.


#48

Copy and paste issue I think.

I believe this should do it:

var path = g.M().Tag('hop').Out(null, "relation");
var pathIn = g.M().Tag('hop').In(null, 'relation');
var depth =  2;

var done = false;
  
g.V("Test 5").Tag("source").FollowRecursive(path,depth).Tag("target").ForEach(function(v){
  if (!done){
    done=true;
  g.V(v.source).Tag('source').FollowRecursive(pathIn, depth).Tag('target').ForEach(function(y){
    var node = {
  source: y.hop,
  relation : y.relation,
  target: y.target
  }
  g.Emit(node)

  })
  }
  var node = {
  source: v.hop,
  start: v.source,
  relation : v.relation,
  target: v.target
  }
  g.Emit(node)

})

#49

Nops @Jorgen

It is showing wrong graph and the json result is also wrong.

Query Response :

{
“result”: [
{
“relation”: “DependsOn”,
“source”: “Test5”,
“target”: “Test4”
},
{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test3”
},
{
“relation”: “BelongsTo”,
“source”: “Test5”,
“start”: “Test5”,
“target”: “Test6”
},
{
“relation”: “ConnectedTo”,
“source”: “Test5”,
“start”: “Test5”,
“target”: “Test9”
},
{
“relation”: “Contains”,
“source”: “Test6”,
“start”: “Test5”,
“target”: “Test7”
}
]
}

Note : Test8 is missing in the graph as well as in the query response as its comes to level 2 for Test5 and the query response for the upper part of the Test5 is completely wrong.

{
“result”: [
{
“relation”: “DependsOn”,
“source”: “Test5”,
“target”: “Test4”
},
{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test3”
},
{
“relation”: “BelongsTo”,
“source”: “Test5”,
“start”: “Test5”,
“target”: “Test6”
},
{
“relation”: “ConnectedTo”,
“source”: “Test5”,
“start”: “Test5”,
“target”: “Test9”
},
{
“relation”: “Contains”,
“source”: “Test6”,
“start”: “Test5”,
“target”: “Test7”
}
]
}

Instead of the bold part, it should show below response :

{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test5”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“target”: “Test4”
},

and should include the Test8 json part as well as below :

{
“relation”: “ConnectedTo”,
“source”: “Test4”,
“target”: “Test8”
},

Note : I have corrected the upper part of the json response by slightly modifying the query but not able to understand how to include the Test8 node.


#50

As for the In part it’s probably something with variable names incorrect/switched. No time to check that now.
For the test 8 part: the reason is because that is an Out and doesn’t work with the follow recursive on In. The problem is that you mix in and outs, but if you do both you get more than you want. So I guess you’d need to rewrite the query in In recursive, out recursive and combine that result. But I’m doing this out of my head, not sure how that would work. Maybe both works with except the start node. When I’ve time tomorrow I can check it again.


#51

I believe this gives you more of what you want. But here you’ll miss out on node 8 because it is an Out on 4 and only following In nodes. Up. I guess this is correct, but if not, you seriously should consider asking yourself what it is you really want. Because you get mixed questions in one. If that is the case you better program exactly what you want. I can not help more than this.

var path = g.M().Tag('hop').Out(null, "relation");
var pathIn = g.M().Tag('hop').In(null, 'relation');
var depth =  3;


g.V("Test 5").Tag("source").Tag('target').ForEach(function(s){

g.V(s.source).Tag("source").FollowRecursive(pathIn, depth).Tag('target').ForEach(function(v){
  var node = {
  source: v.target,
  start: v.source,
  relation : v.relation,
  target: v.hop
  }
  g.Emit(node)

})
g.V(s.source).Tag("source").FollowRecursive(path, depth).Tag('target').ForEach(function(v){
  var node = {
  source: v.hop,
  start: v.source,
  relation : v.relation,
  target: v.target
  }
  g.Emit(node)

})


})