英文:
How do I return in Gremlin only paths which ends with vertices that other paths didn't end with yet?
问题
假设我有以下图:
A->B, B->D
A->C, C->D
A->E
我想返回所有从A开始的路径,但不包括以相同顶点结尾的多条路径。因此,在这种情况下,结果将是:
A->B->D(或A->C->D)和A->E
由于图很大且可能有很多路径,如果引擎可以以高效的方式修剪路径而无需先收集所有路径,那将是可取的。
英文:
Let's assume I have the following graph:
A->B, B->D
A->C, C->D
A->E
I want to return all paths which start from A, but don't include multiple paths which end with the same vertex.
So in case, the result will be:
A->B->D (or A->C->D) and A->E
Since the graph is very big and there can be a lot of paths, if there is an efficient way the engine can prune the paths without collecting all of them first, it is preferable.
答案1
得分: 1
根据图中的数据循环程度,这可能是一个昂贵的查询。我假设每个最终目标都是叶节点。在这种情况下,基本查询可能会变成这样:
g.V('A').
repeat(out().simplePath()).
until(not(out())).
where(without('x')).store('x').
path()
英文:
Depending upon how cyclic the data in the graph is, this can be an expensive query. I am assuming each eventual target is a leaf node. In such cases, the basic query might end up something like this:
g.V('A').
repeat(out().simplePath()).
until(not(out())).
where(without('x')).store('x').
path()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论