获取连接到所有当前顶点的顶点 [英] Getting vertices that are connected to ALL current vertices
问题描述
我可能会问一个明显的问题,但是对于图表和gremlin语言来说是新手,并且有些卡住了.
I might be asking an obvious question, but new to the graphs and gremlin language and got a bit stuck.
我有一个图形设置,可以找到特定类型的N个顶点. 假设我找到了2个X类型的顶点. 这些顶点的边缘为Y型的K个顶点.
I have a graph setup where I can find N vertices of a particular type. Let's say I find 2 vertices of type X. These vertices have edges to K vertices of type Y.
我想找到所有与我找到的X类型的3个顶点有关的Y类型的顶点.在这种情况下,Y类型的顶点可以与X类型的3个顶点之一相连,但是我只想得到普通的.
I want to find vertices of type Y that all have connection to the 3 vertices I found of the type X. In this situation, the vertices of type Y could be connected to either of the 3 vertices of type X, but I want to get only common ones.
用于创建示例数据的脚本``
Script to create sample data ```
g.addV("X1").property("name", "category1")
g.addV("X2").property("name", "category2")
g.addV("Y").property("name", "y1")
g.addV("Y").property("name", "y2")
g.addV("Y").property("name", "y3")
g.V().has("Y", "name", "y1").addE("isOf").to(g.V().has("X1", "name", "category1"))
g.V().has("Y", "name", "y1").addE("isOf").to(g.V().has("X2", "name", "category2"))
g.V().has("Y", "name", "y2").addE("isOf").to(g.V().has("X1", "name", "category1"))
g.V().has("Y", "name", "y2").addE("isOf").to(g.V().has("X2", "name", "category2"))
g.V().has("Y", "name", "y3").addE("isOf").to(g.V().has("X1", "name", "category1"))
```
我感兴趣的发现是具有isOf category1和category2以及可能更多类别的"Y"顶点.我需要消除仅连接到指定类别子集的顶点Y.
And what I am interested finding are the "Y" vertices that have isOf category1 and category2, and potentially more categories. I need to eliminate vertices Y that connected only to a subset of specified categories.
推荐答案
汇总名为x
的集合中的所有源顶点,然后遍历所有y
顶点并验证每个y
顶点是否具有n
编号导致顶点存储在x
(其中n
等于x
的大小)的边的数量.
Aggregate all source vertices in a collection named x
, then traverse to all y
vertices and verify that each y
vertex has n
number of edges leading to vertices stored in x
(where n
equals the size of x
).
gremlin> g.V().hasLabel("X1","X2").aggregate("x").
in("isOf").dedup().
filter(out("isOf").where(within("x")).count().
where(eq("x")).
by().
by(count(local))).
valueMap()
==>[name:[y1]]
==>[name:[y2]]
这篇关于获取连接到所有当前顶点的顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!