【问题标题】:tinkerpop3: use gremlin to count number of edges beetween all pairs of nodestinkerpop3:使用 gremlin 计算所有节点对之间的边数
【发布时间】:2015-11-24 15:45:41
【问题描述】:

我有一个多重图,我有兴趣计算连接每对节点的边数; 此外,我需要为每对节点获取某个属性的最大值。

不幸的是,在我看来,我们只能将.group().by(...) 与一个属性一起使用,而我需要按inVoutV 进行分组。 在 Cypher 我会写类似

MATCH (e0: Employee)-[fb: R]-> (e1: Employee)
WITH e0, e1, count(*) AS frequency, min(fb.value) AS min_val
RETURN e0, e1, frequency, min_val

有人可以帮忙吗?

干杯!

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    在 Gremlin 用户邮件列表上回答,但为了关闭圈子,这里又是遍历:

    gremlin> g.V().as("e0").outE("e").as("e").inV().as("e1").select("e0","e","e1").
    gremlin>       group().by(select("e0","e1").by("name")).
    gremlin>               by(fold().match(__.as("x").count(local).as("freq"),
    gremlin>                               __.as("x").unfold().select("e").by("value").max().as("max")).select("freq","max")
    gremlin>               ).next()
    ==>{e0=c, e1=d}={freq=1, max=9}
    ==>{e0=b, e1=d}={freq=1, max=9}
    ==>{e0=f, e1=h}={freq=1, max=9}
    ==>{e0=e, e1=h}={freq=1, max=9}
    ==>{e0=a, e1=b}={freq=2, max=10000}
    ==>{e0=b, e1=c}={freq=4, max=4}
    ==>{e0=e, e1=f}={freq=1, max=9}
    ==>{e0=f, e1=g}={freq=1, max=9}
    ==>{e0=a, e1=c}={freq=1, max=9}
    

    【讨论】:

    • 我刚刚意识到这是connected components query 的脚本,你能复制粘贴你在帖子中发布的其他解决方案吗?
    • 嗨@Daniel Kuppitz,我终于找到了一些时间来检查遍历:在我的情况下,输出与你的不同:我得到==>{e0=c, e1=d}={{freq=1, max=9}=1} ==>{e0=b, e1=d}={{freq=1, max=9}=1} ==>{e0=f, e1=h}={{freq=1, max=9}=1} ==>{e0=e, e1=h}={{freq=1, max=9}=1} ==>{e0=a, e1=b}={{freq=1, max=10}=1, {freq=1, max=10000}=1} ==>{e0=b, e1=c}={{freq=1, max=0}=1, {freq=1, max=2}=1, {freq=1, max=3}=1, {freq=1, max=4}=1} ==>{e0=e, e1=f}={{freq=1, max=9}=1} ==>{e0=f, e1=g}={{freq=1, max=9}=1} ==>{e0=a, e1=c}={{freq=1, max=9}=1} 看起来缺少一些聚合...
    • 我正在检查有什么问题。您是否偶然复制粘贴了之前版本的遍历?
    • 看来我用的是 3.1.x 版本,而你用的是 3.0.x。您可以增加您的 TP 版本或添加第三个by().by(limit(1)).by {it.head()} 之类的东西应该可以工作。
    • 我已经更改了我的 gremlin 版本。现在可以了 :) 谢谢!
    猜你喜欢
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 2016-07-04
    • 2023-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多