我很难通过节点 ID 获取完整的层次结构。 我想要直接和间接连接到特定节点的所有子节点和子子节点。
节点属性:(~id, 'entity_name', 'entity_type', ~label) 边属性:(~id, ~label, 'journey_id')
graph_result = g.V(entity_id).repeat(inE().outV().dedup()).emit().path().toList()
for path in graph_result:
for item in path:
if type(item) == Edge:
if (item.outV.id, item.inV.id) not in unique_ids:
unique_ids.add((item.outV.id, item.inV.id))
results.append({
"src_entity_id": item.outV.id,
"src_entity_name": item.outV.label,
"target_entity_id" : item.inV.id,
"target_entity_name" : item.inV.label,
"association": item.label
})
使用上面的代码我可以获得层次结构,因为我对节点顶点进行重复数据删除,所以我没有得到异常结果。我想基于(outV.id,inV.id,label)这三者的组合进行重复数据删除。
或者有更好的方法吗?
这听起来更像是您想要获取层次结构中的所有边,而不一定是顶点。 如果是这种情况,您可以执行以下操作:
g.V(entity_id).
repeat(
outE().
aggregate('edges').
inV().
dedup()
).
cap('edges').
unfold().
elementMap()
然后 elementMap 将包含所有边的 inV、outV 和标签。