【问题标题】:I'd like to return all the vertex and all the path for the vertexes which we returned我想返回所有顶点和我们返回的顶点的所有路径
【发布时间】:2018-01-25 10:40:47
【问题描述】:

我的问题是我想返回所有的顶点。并获取所有返回的顶点之间的所有路径。

例如,我将获取所有的标签,即人。而且我还想得到顶点之间的所有路径。

顶点:g.V().has('tag','person') 我们如何获得网络路径?

【问题讨论】:

  • def graph=ConfiguredGraphFactory.open("POC"); def g=graph.traversal(); g.V().repeat(bothE().dedup().store('edges').bothV().dedup().store('vertices')).times(1).cap('vertices', 'edges' ') 这是显示 1 度净值。我说的对吗?

标签: graph-databases gremlin tinkerpop3 janusgraph


【解决方案1】:

g.V().has('tag', 'person') 不会返回任何路径,因为此查询仅返回顶点列表。

我会从您的评论中假设您想要所有此类顶点之间的所有路径,那么以下查询应该很有用:

g.V().has('tag', 'person').bothE().otherV().path()

在目标顶点上添加dedup() 步骤可能很有用,这样您就不会得到重复的路径:

g.V().has('tag', 'person').bothE().otherV().dedup().path()

要获得更复杂的 path() 输出,您可以使用 Gremlin 控制台和玩具图进行试验。以下对源顶点、遍历边和目标顶点(分别)应用不同的by() 调制器:

gremlin> graph = TinkerFactory.createModern()
gremlin> g = graph.traversal(standard())
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().bothE().otherV().dedup().path().by(id).by(label).by(id)
==>[1, created, 3]
==>[1, knows, 2]
==>[1, knows, 4]
==>[2, knows, 1]
==>[3, created, 6]
==>[4, created, 5]

参考:

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 2019-02-14
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    相关资源
    最近更新 更多