【发布时间】:2019-08-09 09:29:02
【问题描述】:
我想过滤我的图以仅包含边数小于阈值(例如 50)的顶点,如下所示:
g.V().filter(bothE().limit(50).count().is(lt(50)))
这给了我想要保留的顶点列表。
如何创建仅包含这些顶点的traversal 对象?
背景
我需要计算图中每个顶点的 k-hop 邻域,以过滤掉具有大量边的顶点(例如
想到的第一种方法是首先过滤图,将结果存储为新的子图,然后遍历每个顶点以找到 k-hop 邻域。对于单个顶点v,k=5-hop 邻域码为:
g.V(v).repeat(__.bothE().bothV()).times(5).dedup().toList()
更好的方法可能是迭代原始未过滤图中的每个顶点并忽略连接到高边数顶点的边,但我不太确定如何执行此操作。
尝试 1:
filtered_edges = g.V().filter(bothE().limit(50).count().is_(lt(50))).outE().toList()
subgraph = g.E(filtered_edges).subgraph('subGraph').cap('subGraph').next()
不幸的是,在使用gremlinpython 时会引发错误 (StreamClosedError: Stream is closed)。在出现此错误之前和之后运行其他(可能成本更低)查询不会产生类似的错误,因此与 gremlin shell 的连接仍然存在。该代码也适用于 gremlin shell(将 is_ 替换为 is)。
我猜这是因为我在 gremlin 服务器和 Python 之间发送了太多数据,但不确定为什么会出现问题。
尝试 2:
使用 gremlin 客户端。我尝试用名称l 覆盖另一个遍历对象。但是覆盖操作失败 (l = subgraph.traversal();)。
gremlin_client = client.Client('ws://{}:{}/gremlin'.format('localhost', 8192), 'g', message_serializer=serializer.GraphSONSerializersV3d0())
command = "filtered_edges = g.V().filter(bothE().limit(50).count().is(lt(50))).outE().toList(); subgraph = g.E(filtered_edges).subgraph('subGraph').cap('subGraph').next(); l = subgraph.traversal();"
gremlin_client.submit(command).all().result()
【问题讨论】:
标签: gremlin janusgraph gremlin-server