python - Gremlin Python:在列表中返回顶点 ID 和边属性
问题描述
我很难返回我正在寻找的确切信息。本质上,我想返回某种类型的所有边(在任一方向)。我想在列表中获取顶点 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]
推荐阅读
- flutter - 没有任何问题,但我仍然收到错误消息
- java - 如何只打开一次 JavaFX 窗口
- angular - 如何在 ng2 智能表中选择多个列?
- arrays - 初始化一个数组 - MIPS
- mysql - SQL 日期返回 -1 天
- r - 在大矩阵中计算欧几里得距离的最有效方法
- r - 在 R 中:使用 stargazer 组合具有汇总统计信息的多个数据集
- python - 如何用pygame画一条虚曲线?
- python-3.x - 迁移问题,django.core.exceptions.FieldDoesNotExist:lightspeed.inventoryimagehistory 没有名为“imageID”的字段
- swift - 使应用程序处于非活动状态。苹果系统