1

foo在 Tinkerpop 中,我想选择不直接连接到属性等于的顶点的顶点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标记顶点的顶点。输出应该是 2 个顶点tagKeytagKey2user3 , user 1

4

2 回答 2

1

You can achieve this by using a combination of not and where steps:

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

example: https://gremlify.com/jybeipj4zjg

于 2020-08-21T08:58:29.963 回答
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, 'name', 'Two').
  addV('Vertex').as('3').property(single, 'name', 'Three').
  addV('Vertex').as('4').property(single, 'name', 'Four').
  addV('Tag').as('5').property(single, 'name', 'Key1').
  addV('Tag').as('6').property(single, 'name', 'Key2').
  addV('Tag').as('7').property(single, 'name', '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

于 2020-08-21T08:55:14.827 回答