Tinkerpop:选择不包含具有属性的顶点的路径的顶点

问题描述

在Tinkerpop中,我要选择不直接连接到属性foo等于bar的顶点的顶点

例如:

Vertex user1 = graph.addVertex("vid","one");
Vertex user2 = graph.addVertex("vid","two");
Vertex user3 = graph.addVertex("vid","three");

Vertex tag1 = graph.addVertex("tagKey","tagKey1");
Vertex tag2 = graph.addVertex("tagKey","tagKey2");
Vertex tag3 = graph.addVertex("tagKey","tagKey3");

user1.addEdge("user_tag",tag1);
user2.addEdge("user_tag",tag2);
user2.addEdge("user_tag",tag3);

在上述测试用例中,我想选择所有未连接到user且值为tagKey标签顶点的tagKey2顶点。输出应为2个顶点user3,user 1

解决方法

查询以获取未连接到标签的顶点。

g.V().hasLabel("Vertex").
    filter(
        not(outE().hasLabel('connected'))
        ).
    properties()

查询以添加顶点数据:

g.addV('Vertex').as('1').property(single,'name','One').
  addV('Vertex').as('2').property(single,'Two').
  addV('Vertex').as('3').property(single,'Three').
  addV('Vertex').as('4').property(single,'Four').
  addV('Tag').as('5').property(single,'Key1').
  addV('Tag').as('6').property(single,'Key2').
  addV('Tag').as('7').property(single,'Key3').
  addE('connected').from('1').to('5').
  addE('connected').from('2').to('6').
  addE('connected').from('4').to('7')

Gremlify链接:https://gremlify.com/f1muf12xhdv/2

,

您可以结合使用notwhere步骤来实现此目的:

g.V().hasLabel('User').
  not(where(out('user_tag').has('tagKey','tagKey2'))).
  valueMap().with(WithOptions.tokens)

示例:https://gremlify.com/jybeipj4zjg