Gremlin Python:返回列表中的顶点 ID 和边属性

Gremlin Python: Returning vertex IDs and edge properties in a list

我很难return找到我正在寻找的确切信息。本质上,我想 return 某种类型的所有边缘(在任一方向)。我想在列表中获取顶点 ID 和边参数。理想情况下,我的输出格式如下所示:

{
    "from": "vertex_id_1",
    "to": "vertex_id_2",
    "similarity": 0.45
}

我一直在使用 g.both().vertexMap().toList() 来获取相似点,但我无法通过这种方式获取顶点 ID。

以玩具图为例,您最好使用 project():

gremlin> g.V().bothE('knows').
......1>   project('from','to','weight').
......2>     by(outV().id()).
......3>     by(inV().id()).
......4>     by('weight')
==>[from:1,to:2,weight:0.5]
==>[from:1,to:4,weight:1.0]
==>[from:1,to:2,weight:0.5]
==>[from:1,to:4,weight:1.0]