Graph 查询以查找只有一个公共顶点的节点

Graph 查询以查找只有一个公共顶点的节点,graph,gremlin,graph-databases,janusgraph,tinkerpop3,Graph,Gremlin,Graph Databases,Janusgraph,Tinkerpop3,我有以下顶点- Person1 -> Device1 <- Person2 ^ | | v Email1 <- Person3 Person1->Device1 以下遍历将为您提供通过一个或多个“设备”顶点连接到“Person1”且未通过任何其他类型顶点连接的人员顶点。请在此处输入代码 g.V().has('person', 'name', 'Person1

我有以下顶点-

  Person1 -> Device1 <- Person2 
                  ^
     |            |
     v            
    Email1  <-  Person3
Person1->Device1
以下遍历将为您提供通过一个或多个“设备”顶点连接到“Person1”且未通过任何其他类型顶点连接的人员顶点。请在此处输入代码

g.V().has('person', 'name', 'Person1').as('p1').
  out().as('connector').
  in().where(neq('p1')).
  group().
    by().
    by(select('connector').label().fold()).
  unfold().
  where(
    select(values).
    unfold().dedup().fold().  // just in case the persons are connected by multiple devices
    is(eq(['device']))
  ).
  select(keys)

由于Gremlin用户的电子邮件列表中已经回答了这个问题,因此,如果其他人遇到这个问题,可以将答案复制到这里。当然,开尔文劳伦斯
g.V().has('person', 'name', 'Person1').as('p1').
  out().as('connector').
  in().where(neq('p1')).
  group().
    by().
    by(select('connector').label().fold()).
  unfold().
  where(
    select(values).
    unfold().dedup().fold().  // just in case the persons are connected by multiple devices
    is(eq(['device']))
  ).
  select(keys)