【问题标题】:Groovy script fails to add edges to a Gremlin graphGroovy 脚本无法将边添加到 Gremlin 图中
【发布时间】:2016-12-05 01:25:45
【问题描述】:

我正在尝试使此脚本工作以检索文件中存在的所有边缘,以及从用户到电影的评分。

new File('ratings.dat').eachLine{
    line ->

    components = line.split('::');

    userId = components[0].toInteger();
    movieId = components[1].toInteger();

    g.V().has('userId', userId).as('o').V().has('movieId', movieId).addE('rated').to('o');
}

如果我在这个闭包中添加一些调试打印,我可以看到所有信息都正确加载到我的变量中,但是在执行结束时,我计算了我图中的边数,它只增加了1、什么时候应该是多个。一些调查表明,被有效添加到图中的边是最后被读取的。可能出了什么问题?

【问题讨论】:

    标签: groovy graph closures gremlin tinkerpop


    【解决方案1】:

    你永远不会执行你的遍历。您的代码应如下所示:

    new File('ratings.dat').eachLine { def line ->
        def (userId, movieId) = line.split('::')*.toInteger()
        g.V().has('userId', userId).as('o').
          V().has('movieId', movieId).
          addE('rated').to('o').iterate()
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 2021-04-27
      • 2019-07-26
      • 2017-03-31
      相关资源
      最近更新 更多