格林姆林交叉口手术 [英] gremlin intersection operation

查看:100
本文介绍了格林姆林交叉口手术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gremlin控制台v3.3.1. 使用本教程中的现代"图: http://tinkerpop.apache.org/docs/current/tutorials/getting -started/

I'm using the gremlin console v3.3.1. Using the "Modern" graph from the tutorial: http://tinkerpop.apache.org/docs/current/tutorials/getting-started/

以此创建图形:

gremlin>graph = TinkerFactory.createModern()
gremlin>g = graph.traversal()

我可以找到所有这样的人:

I can find all the people that know "vadas" like this:

g.V().hasLabel('person').has('name', 'vadas').in('knows').hasLabel('person').valueMap()

我可以找到所有创建软件"lop"的人:

And I can find all the people that created the software "lop" with this:

g.V().hasLabel('software').has('name', 'lop').in('created').hasLabel('person').valueMap()

我可以找到所有知道"vadas"或通过联合操作创建"lop"的人:

I can find all the people that know "vadas" OR created "lop" with a union operation:

g.V().union(
g.V().hasLabel('person').has('name', 'vadas').in('knows').hasLabel('person'),
g.V().hasLabel('software').has('name','lop').in('created').hasLabel('person')
).dedup().valueMap()

但是我不知道如何找到所有认识"vadas"并创建"lop"的人.本质上,我想进行INTERSECT操作(我认为),但是我找不到这种东西.

But I can't figure out how to find all the people that know "vadas" AND created "lop". Essentially I want an INTERSECT operation (I think), but there is no such thing that I can find.

有帮助吗?

推荐答案

可能还有其他方法可以做到这一点,但是我想出了一些方法.首先使用match()步骤:

There are likely other ways to do this, but here's a few that I came up with. The first uses match() step:

gremlin> g.V().match(
......1>   __.as('a').out('created').has('software','name','lop'),
......2>   __.as('a').out('knows').has('person','name','josh')).
......3>   select('a')
==>v[1]

第二个仅使用and()步骤:

gremlin> g.V().and(
......1>   out('created').has('software','name','lop'),
......2>   out('knows').has('person','name','vadas'))
==>v[1]

两个都可能需要对所有顶点进行全面扫描(不确定哪个图形数据库会优化这些遍历以使用索引),所以我也尝试这样做:

both could potentially require full scans of of all vertices (not sure what graph databases would optimize those traversals to use indices), so I also tried this:

gremlin> g.V().has('person','name','vadas').in('knows').hasLabel('person').
......1>   V().has('software','name','lop').in('created').hasLabel('person').
......2>   path().
......3>   filter(union(range(local,1,2), 
......4>                range(local,3,4)).
......5>          fold().
......6>          dedup(local).
......7>          count(local).is(1)).
......8>   tail(local)
==>v[1]

基本上,它捕获了V()上前两个遍历的path(),然后对其进行分析以在路径位置之间寻找匹配项.看到遍历后,我意识到可以将其简化为:

It basically grabs the path() of the first two traversals over V() and then analyzes it to look for matches betweeen path positions. As soon as I saw that traversal, I realized it could all be simplified down to:

gremlin> g.V().has('person','name','vadas').in('knows').hasLabel('person').as('a').
......1>   V().has('software','name','lop').in('created').hasLabel('person').as('b').
......2>   select('a').
......3>   where('a',eq('b'))
==>v[1]

这篇关于格林姆林交叉口手术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆