简体   繁体   English

Gremlin的边共享相同的顶点

[英]Gremlin get edges sharing the same vertex

My application has filters in English and I need to translate these filters into Gremlin query. 我的应用程序具有英文过滤器,我需要将这些过滤器转换为Gremlin查询。 Each filter consists of three parts: 每个过滤器包括三个部分:

  1. Type of vertex 顶点类型
  2. Label of outgoing edge from vertex in #1 #1中顶点的出线边缘标签
  3. Name of incoming vertex from edge in #2 来自#2中的边的传入顶点的名称

Any of the part can take the string "any", which signifies any type, label or name can be included in the result. 任何部分都可以采用字符串“ any”,表示结果中可以包含任何类型,标签或名称。 Using the Modern toy graph as example, I have the following two filters: 以现代玩具图为例,我有以下两个过滤器:

  1. person -> created -> any 人->创建->任何
  2. person -> knows -> vadas 人->知道-> vadas

The result of the evaluation of the above two filters should be: 以上两个过滤器的评估结果应为:

  1. marko -> created -> lop marko->创建-> lop
  2. marko -> knows -> vadas marko->知道-> vadas

While the following two filters: 而以下两个过滤器:

  1. person -> any -> josh 人->任何->乔什
  2. person -> created -> lop 人->创建->折叠

Should evaluate to the following edges: 应该评估以下方面:

  1. marko -> knows -> josh marko->知道-> josh
  2. marko -> created -> lop marko->创建-> lop

The query I come up with the closest result to the desired results above is: 我想出的最接近上面期望结果的查询是:

g.E().and(outV().outE().has(label, "created"), outV().outE().has(label, "knows").inV().has("name", "vadas"), outV().has(label, "person"))

The problem with the above query is that it returns all three edges going out from marko, not just two desired edges. 上面查询的问题是,它返回从marko出来的所有三个边缘,而不仅仅是两个期望的边缘。 How can I improve my query to return only the two edges as described above? 如何改善查询以仅返回如上所述的两个边?

This solution takes the approach of separating the filters from the traversals that return the results. 该解决方案采用了将过滤器与返回结果的遍历分离的方法。

gremlin> Gremlin.version()
==>3.3.3
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().
......1>     and(
......2>         outE('created'),
......3>         out('knows').has('name', 'vadas')
......4>     ).
......5>     union(
......6>         outE('created').inV(),
......7>         outE('knows').inV().has('name', 'vadas')
......8>     ).
......9>     path().by('name').by(label)
==>[marko,created,lop]
==>[marko,knows,vadas]
gremlin> g.V().
......1>     and(
......2>         out().has('name', 'josh'),
......3>         out('created').has('name', 'lop')
......4>     ).
......5>     union(
......6>         outE().inV().has('name', 'josh'),
......7>         outE('created').inV().has('name', 'lop')
......8>     ).
......9>     path().by('name').by(label)
==>[marko,knows,josh]
==>[marko,created,lop]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM