Graph databases 小精灵:确定另一个顶点的所有连接中的顶点
我正在使用TinkerPop3 Gremlin Console 3.3.1分析图形数据库。我想确定哪些顶点的连接与同一标签的其他顶点的所有相似连接重叠。例如,为了清晰起见,使用TinkerFactory Modern graph以及附加的“软件”顶点和两条“创建”边:Graph databases 小精灵:确定另一个顶点的所有连接中的顶点,graph-databases,gremlin,tinkerpop,tinkerpop3,Graph Databases,Gremlin,Tinkerpop,Tinkerpop3,我正在使用TinkerPop3 Gremlin Console 3.3.1分析图形数据库。我想确定哪些顶点的连接与同一标签的其他顶点的所有相似连接重叠。例如,为了清晰起见,使用TinkerFactory Modern graph以及附加的“软件”顶点和两条“创建”边: graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] g = graph.traversal() ==>graphtraver
graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
graph.addVertex(T.label, "software", T.id, 13, "name", “sw")
==>v[13]
g.V("4").addE("created").to(V("13"))
==>e[14][4-created->13]
g.V("6").addE("created").to(V("5"))
==>e[15][6-created->5]
请参见我修改的现代图表的下图。我把我感兴趣的箭放在橙色上
通过这个例子,我想确定哪些人创建了包含其他人创建的所有软件的软件。不必知道是哪种软件。所以这个例子的结果是:
- Josh(第(4)节)共同创建了Marko(第(1)节)创建的所有软件
- 乔希(第(4)节)共同创造了彼得(第(6)节)创造的所有软件
- Peter(第(6)节)共同创建了Marko(第(1)节)创建的所有软件
gremlin>
g.V().has(label,"person").as("a").
both().has(label,"software").aggregate("swA").
both().has(label,"person").where(neq("a")).dedup().
where(both().has(label,"software").
where(within("swA")).count().
where(is(eq(select("swA").unfold().count())
)
)
).as("b").select("a","b").by(“name”)
非常感谢您的帮助 首先查找至少共同创建一个产品的所有成对人员
g.V().hasLabel('person').as('p1').
out('created').in('created').
where(neq('p1')).as('p2').
dedup('p1','p2').
select('p1','p2').
by('name')
从那里,您可以添加一点模式匹配,以验证personp1
创建的产品数量是否与这些产品到personp2
的连接数量相匹配
g.V().hasLabel('person').as('p1').
out('created').in('created').
where(neq('p1')).as('p2').
dedup('p1','p2').
match(__.as('p1').out('created').fold().as('x'),
__.as('x').count(local).as('c'),
__.as('x').unfold().in('created').where(eq('p2')).count().as('c')).
select('p1','p2').
by('name')
结果:
gremlin> g.V().hasLabel('person').as('p1').
......1> out('created').in('created').
......2> where(neq('p1')).as('p2').
......3> dedup('p1','p2').
......4> match(__.as('p1').out('created').fold().as('x'),
......5> __.as('x').count(local).as('c'),
......6> __.as('x').unfold().in('created').where(eq('p2')).count().as('c')).
......7> select('p1','p2').
......8> by('name')
==>[p1:marko,p2:josh]
==>[p1:marko,p2:peter]
==>[p1:peter,p2:josh]