【问题标题】:Tinkerpop: select vertex which do not have path to vertex having a propertyTinkerpop:选择没有路径到具有属性的顶点的顶点
【发布时间】:2020-08-21 07:51:16
【问题描述】:

在 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

【问题讨论】:

    标签: gremlin tinkerpop tinkerpop3 gremlin-server tinkergraph


    【解决方案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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-16
        • 2023-01-15
        • 1970-01-01
        • 2016-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-14
        相关资源
        最近更新 更多