【问题标题】:TinkerPop: Filter by Edge countTinkerPop:按边缘计数过滤
【发布时间】:2018-04-30 10:14:31
【问题描述】:

样本数据:TinkerPop Modern

总结:我想找到创建了 2 个软件的人。

我从基础开始,并正确计数

g.V().hasLabel("Person").as("from" ,"to1" )
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.emit(filter(hasLabel("Software"))).hasLabel("Software")
.group().by(select("from").by("name")).by(count()).as("c")

结果:

>> {'Marko': 1, 'Peter': 1, 'Josh': 2}

所以我尝试应用过滤器但它不起作用(即结果不正确),我尝试了什么:

g.V().hasLabel("Person").as("from")
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.filter(bothE().otherV().hasLabel("Software").count(local).is(eq(1)))
.dedup()
.values("name")

知道我做错了什么吗?


样本数据:

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    如果您只需要按边数计算“人”顶点,我真的不明白为什么您需要所有 repeat() 基础设施。只是:

    gremlin> g.V().hasLabel('person').
    ......1>   filter(outE('created').limit(2).count().is(2))
    ==>v[4]
    

    您只需要计算出边,因为架构是这样的,“创建”标签仅连接到“软件”,因此您无需检查 “软件”顶点标签。您limit(2) 尽快退出边缘迭代,但不是在您尝试计算 2 条边缘之前。

    【讨论】:

    • repeat 用于类似 people->server->OS 的用例,并像使用超过 2 个 OS 的人一样搜索
    • 您的查询有效,试图使其适合多跳搜索的情况
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2019-03-22
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多