比较 Gremlin 中的顶点属性 Groovy

Comparing vertex properties in Gremlin Groovy

我问的问题与您看到的 here 几乎相同,但必须使用 groovy 而不是 java 语法。理想情况下,答案将非常简洁。

我有一个简单的人顶点图。每个人都有一个 "age" 属性 列出该人的年龄(以年为单位)。还有 "worksFor" 个标记的边连接成对的人物顶点。我想看到边缘两端的人年龄相同的所有边缘属性。

然后我想要一个类似的查询,其中两个年龄相差不到 3 年。

如前所述,这应该是 groovy,而不是 Java 语法。首选 Gremlin 3,但可以接受 Gremlin 2 的答案。

如果我们知道与所有其他顶点进行比较的目标顶点,则以下可能有效:

t=g.V().has('id', 'target_node_id').values('age').next()

g.V().has('age').filter{it.get().value('age')-t<=3 && it.get().value('age')-t>=-3}

我不知道如何在一个查询中完成。我也不知道有没有function/step求绝对值

这只能部分满足您的需求,但这可能是一个开始。

all edges where the people at both ends of the edge have the same age property

g.V().as("a").outE("worksFor").as("e").inV().as("b").select("a","b").by("age").
      where("a", eq("b")).select("e")

where the two ages differ by less than 3 years

g.V().as("a").outE("worksFor").as("e").inV().as("b").select("a","b").by("age").
      filter {Math.abs(it.get().get("a") - it.get().get("b")) < 3}.select("e")

使用 math 步骤比较两个日期属性:

g.V().hasLabel('EnterExitDate').limit(10000).as('enter','exit')
    .where("enter",lt("exit")).by('enter').by('exit')
    .where(math('(exit - enter) / (3600*1000) ')
        .by(values('exit').map({ it.get().time }))
        .by(values('enter').map({ it.get().time }))
        .is(lt(1)))
    .valueMap()

该查询将查找员工在1小时内发生的所有进出记录对。

输入退出日期class:

public class EnterExitDate {
    private Date enter;
    private Date exit;
    // getters and setters...
}