【问题标题】:return both a 'graphml' subgraph and a collection from 1 traversal in Gremlin从 Gremlin 的 1 次遍历中返回一个“graphml”子图和一个集合
【发布时间】:2018-02-12 22:30:00
【问题描述】:

我有一个 Gremlin 遍历,如下所示:

g.V().hasLabel("Firma").has("cui","2816464") 
..........subgraph('sub') ......otherV() ...?????....

如果我想获取顶点属性的集合,我将结束遍历:

 "values('prop')"

如果我想以“graphml”格式保存子图,我将结束遍历:

 cap('sub').next().io(IoCore.graphml()).writeGraph('/tmp/a2.xml')

如何在一次遍历中同时实现这两个目标并获取顶点属性的集合,同时将子图保存为 Graphml 格式?

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    我假设您想要返回 GraphML 而不是将其存储在服务器上,因此我已相应地编写了此答案。如果您使用的是 Java,您可以这样做:

    gremlin> g.V().hasLabel('person').
    ......1>   outE().
    ......2>   subgraph('sub').
    ......3>   inV().
    ......4>   values('name').as('props').
    ......5>   union(cap('sub'),select('props').fold())
    ==>tinkergraph[vertices:6 edges:6]
    ==>[lop,lop,lop,vadas,josh,ripple]
    

    然后在客户端生成 GraphML。如果您不使用 Java,我认为您将无法提交这样的脚本:

    t = g.V().hasLabel('person').
      outE().
      subgraph('sub').
      inV().
      values('name').store('props').
      cap('sub')
    result = []
    result << t.next()..... // write graph to GraphML string to place in result
    result << t.getSideEffects().get('props')
    

    【讨论】:

    • 我喜欢你给我的第二个选项。我通过 HTTP 从 PHP 脚本向 Gremlin 服务器发送 Gremlin 脚本。需要返回 GraphML 以在浏览器客户端中使用(Cytoscape.js 有一个扩展程序允许我直接加载 GraphML)并将其他一些节点属性返回到同一个浏览器客户端。非常感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 2021-11-27
    • 2012-06-16
    • 2021-04-23
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2012-06-09
    • 2013-12-04
    相关资源
    最近更新 更多