【问题标题】:Gremlin.Net Get an edges Id, InV, OutV, and properties all in one traversalGremlin.Net 一次遍历获取边 Id、InV、OutV 和属性
【发布时间】:2019-01-23 16:06:08
【问题描述】:

目前,通过一次遍历,我可以做到:

Edge edge = g.E().Next();
var inv = edge.InV;
var outv = edge.OutV;
var id = edge.Id;

它允许我获取边的 id,以及边之间的顶点的 id。或者,我可以这样做:

IDictionary<object, object> dict = g.E().ValueMap<object, object>(true).Next();
var id = dict[T.id]
var edgeProp = dict["$edgePropertyName"];

它允许我获取属性和 id,但不能获取边缘的 id。有没有办法在一次遍历中同时获取顶点和属性?

【问题讨论】:

    标签: c# .net gremlin tinkerpop


    【解决方案1】:

    当然,只需使用project()

    gremlin> g.E().
    ......1>   project('id','properties','out','in').
    ......2>     by(id).
    ......3>     by(valueMap()).
    ......4>     by(outV().id()).
    ......5>     by(inV().id())
    ==>[id:7,properties:[weight:0.5],out:1,in:2]
    ==>[id:8,properties:[weight:1.0],out:1,in:4]
    ==>[id:9,properties:[weight:0.4],out:1,in:3]
    ==>[id:10,properties:[weight:1.0],out:4,in:5]
    ==>[id:11,properties:[weight:0.4],out:4,in:3]
    ==>[id:12,properties:[weight:0.2],out:6,in:3]
    

    【讨论】:

    • 就是这样-谢谢! (对于在 Gremlin.Net 中专门使用此解决方案,请使用 __ 类进行匿名遍历)
    【解决方案2】:

    将接受的答案翻译成 C#:

    var result = g.E()
        .Project<object>("id", "properties", "out", "in")
        .By(__.Id())
        .By(__.ValueMap<string, object>())
        .By(__.OutV().Id())
        .By(__.InV().Id())
        .Next();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 2013-07-05
      • 2012-09-07
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多