TinkerPop:按不与边连接的边过滤

TinkerPop: Filter by Edge not connected with an Edge

示例数据库:TinkerPop Modern


Objective: 寻找没有开发过软件的人。

即。不直接连接到顶点类型 "Software"

的顶点类型 "Person"

连接到软件的人[作品]

g.V().hasLabel("Person").as("from")
.project("title", "node")
    .by(select("from").unfold().values("name").fold())
    .by(select("from").unfold().label().fold())

查找未连接到软件的人[不起作用]

g.V().hasLabel("Person").as("from")
.filter(both().not(hasLabel("Software")))
.project("title", "node")
    .by(select("from").unfold().values("name").fold())
    .by(select("from").unfold().label().fold())

我相信它会忽略不满足条件的边,但不会跳过顶点。

试图做一个循环,但没有找到它的例子。

Cypher Query equivalent(仅供参考):MATCH (n:People) WHERE NOT (n)--(:Software) RETURN n


示例数据库:

我认为您只需要更改您的筛选条件:

gremlin> g.V().hasLabel('person').
......1>   filter(__.not(outE('created'))).
......2>   project("title", "node").
......3>     by('name').
......4>     by(label)
==>[title:vadas,node:person]

如您所见,您也不需要 select 出于任何原因返回 as() 步骤 - 您已经将该顶点作为 project() 中的当前遍历器.